Source
Learn how the Source abstraction is implemented in the plugin.
less than a minute
Concept
As explained here, the Source refers to the team or user that initiates a request. This abstraction allows compatibility with CTFd operating in either “users” or “teams” mode, making the plugin versatile and usable in both modes.
To enable sharing across all users, the sourceId is set to 0. The table below summarizes the different scenarios:
| user_mode | shared | sourceId |
|---|---|---|
| users | FALSE | current_user.id |
| teams | FALSE | current_user.team_id |
| users | TRUE | 0 |
| teams | TRUE | 0 |
Example workflow
Instance creation
Here an example of sourceId usage in the instance creation process:
flowchart LR
A[Launch] --> B{CTFd mode}
B -->|users| C[sourceId = user.id]
B -->|teams| D[sourceId = user.team_id]
D --> E{challenge.shared ?}
C --> E
E -->|True| F[sourceId = 0]
E -->|False| End1
F --> End1
End1(((1)))The rest of the workflows is detailed in mana section.