AdminController
struct AdminController : APIRouteCollection
The collection of /api/v3/admin route endpoints and handler functions related to admin tasks.
All routes in this group should be restricted to users with administrator priviliges. This controller returns data of a privledged nature, and has control endpoints for setting overall server state.
-
Required. Registers routes to the incoming router.
Declaration
Swift
func registerRoutes(_ app: Application) throws -
addDailyThemeHandler(_:Asynchronous) POST /api/v3/admin/dailytheme/createCreates a new daily theme for a day of the cruise (or some other day). The ‘day’ field is unique, so attempts to create a new record with the same day as an existing record will fail–instead, you probably want to edit the existing DailyTheme for that day.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func addDailyThemeHandler(_ req: Request) async throws -> HTTPStatusParameters
requestBodyReturn Value
HTTP 201 Createdif the theme was added successfully. -
editDailyThemeHandler(_:Asynchronous) POST /api/v3/admin/dailytheme/ID/editEdits an existing daily theme. Passing nil for the image will remove an existing image. Although you can change the cruise day for a DailyTheme, you can’t set the day to equal a day that already has a theme record. This means it’ll take extra steps if you want to swap days for 2 themes.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func editDailyThemeHandler(_ req: Request) async throws -> HTTPStatusParameters
dailyThemeIDin URL path
requestBodyReturn Value
HTTP 201 Createdif the theme was added successfully. -
deleteDailyThemeHandler(_:Asynchronous) POST /api/v3/admin/dailytheme/ID/deleteDELETE /api/v3/admin/dailytheme/ID/Deletes a daily theme.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func deleteDailyThemeHandler(_ req: Request) async throws -> HTTPStatusParameters
dailyThemeIDin URL path
Return Value
HTTP 204 noContentif the theme was deleted successfully. -
GET /api/v3/admin/serversettingsReturns the current state of the server’s Settings structure.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func settingsHandler(_ req: Request) throws -> SettingsAdminDataReturn Value
-
settingsUpdateHandler(_:Asynchronous) POST /api/v3/admin/serversettings/updateUpdates a bunch of settings in the Settings.shared object.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func settingsUpdateHandler(_ req: Request) async throws -> HTTPStatusParameters
requestBodyReturn Value
HTTP 200 OKif the settings were updated. -
timeZoneChangeHandler(_:Asynchronous) GET /api/v3/admin/timezonechangesReturns information about the declared time zone changes happening during the cruise.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func timeZoneChangeHandler(_ req: Request) async throws -> TimeZoneChangeDataReturn Value
-
reloadTimeZoneChangeData(_:Asynchronous) POST /api/v3/admin/serversettings/reloadtzdataReloads the time zone change data from the seed file. Removes all previous entries.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func reloadTimeZoneChangeData(_ req: Request) async throws -> HTTPStatusReturn Value
HTTP 200 OKif the settings were updated. -
serverRollupCounts(_:Asynchronous) GET /api/v3/admin/rollupReturns a bunch of summary data about how many rows of certain database objects we’ve created. Useful when we want to check whether a certain row-creating operation is working, whether any operation is creating way more rows than we expect, or just to guage the popularity of various server features.
More sophisticated servers run an operation like this on a cronjob and analyze the results each time to check that recent db activity matches expectations. Mostly this is just a quick way for us to check usage.
Declaration
Swift
func serverRollupCounts(_ req: Request) async throws -> ServerRollupData
-
regCodeStatsHandler(_:Asynchronous) GET /api/v3/admin/regcodes/statsReturns basic info about how many regcodes have been used to create accounts, and how many there are in total. In the future, we may add a capability for admins to create and issue replacement codes to users (or pull codes from a pre-allocated ‘replacement’ list, or something). This returns stats on those theoretical codes too, but the numbers are all 0.
Declaration
Swift
func regCodeStatsHandler(_ req: Request) async throws -> RegistrationCodeStatsDataReturn Value
-
userForRegCodeHandler(_:Asynchronous) GET /api/v3/admin/regcodes/find/:search_stringChecks whether a user has been associated with a registration code. Can also be used to check whether a reg code is valid. Throws when the reg code is not found primarily to help differentiate between “No reg code found” “No User Found” and “User Found” cases.
Throws
400 Bad Request if the reg code isn’t found in the db or if it’s malformed. We don’t check too thoroughly whether it’s well-formed.Declaration
Swift
func userForRegCodeHandler(_ req: Request) async throws -> [UserHeader]Return Value
[] if no user has created an account using this reg code yet. If they have, returns an array containing the UserHeaders of all users associated with the registration code. The first item in the array will be the primary account.
-
regCodeForUserHandler(_:Asynchronous) GET /api/v3/admin/regcodes/findbyuser/:userIDReturns the primary user, all alt users, and registration code for the given user. The input userID can be for the primary user or any of their alts. If called with a userID that has no associated regcode (e.g. ‘admin’ or ‘moderator’), regCode will be “”.
Throws
400 Bad Request if the userID isn’t found in the db or if it’s malformed.Declaration
Swift
func regCodeForUserHandler(_ req: Request) async throws -> RegistrationCodeUserDataReturn Value
[] if no user has created an account using this reg code yet. If they have, returns a one-item array containing the UserHeader of that user.
-
assignDiscordRegCode(_:Asynchronous) POST /api/v3/admin/regcodes/discord/allocate/:usernameFinds an unallocated regcode that was reserved for Discord users, allocates it and assigns it to the given Discord user. This method allows TwitarrTeam members to hand out reg codes to be used on the preproduction Twitarr server for account creation, tying those reg codes to a Discord username.
This method is for Pre-Production only, as the boat server should not have any regcodes reserved for Discord users in its database.
Declaration
Swift
func assignDiscordRegCode(_ req: Request) async throws -> RegistrationCodeUserData
-
getModeratorsHandler(_:Asynchronous) GET /api/v3/admin/moderatorsReturns a list of all site moderators. Only THO and above may call this method.
Declaration
Swift
func getModeratorsHandler(_ req: Request) async throws -> [UserHeader]Return Value
Array of
UserHeader. -
makeModeratorHandler(_:Asynchronous) POST /api/v3/admin/moderator/promote/:user_idMakes the target user a moderator. Only admins may call this method. The user must have an access level of
.verifiedand not be temp-quarantined. Unlike the Moderator method that sets access levels, mod promotion only affects the requested account, not other sub-accounts held by the same user.Throws
badRequest if the target user isn’t verified, or if they’re temp quarantined.Declaration
Swift
func makeModeratorHandler(_ req: Request) async throws -> HTTPStatusReturn Value
200 OK if the user was made a mod.
-
demoteToVerifiedHandler(_:Asynchronous) POST /api/v3/admin/user/demote/:user_idSets the target user’s accessLevel to
.verifiedif it was.moderator,.twitarrteam, or.tho. Must be THO or higher to call any of these; must be admin to demote THO users.Throws
badRequest if the target user isn’t a mod.Declaration
Swift
func demoteToVerifiedHandler(_ req: Request) async throws -> HTTPStatusReturn Value
200 OK if the user was demoted successfully.
-
getTwitarrTeamHandler(_:Asynchronous) GET /api/v3/admin/twitarrteamReturns a list of all TwitarrTeam members. Only THO and above may call this method.
Declaration
Swift
func getTwitarrTeamHandler(_ req: Request) async throws -> [UserHeader]Return Value
Array of
UserHeader. -
makeTwitarrTeamHandler(_:Asynchronous) POST /api/v3/admin/twitarrteam/promote/:user_idMakes the target user a member of TwitarrTeam. Only admins may call this method. The user must have an access level of
.verifiedand not be temp-quarantined.Throws
badRequest if the target user isn’t verified, or if they’re temp quarantined.Declaration
Swift
func makeTwitarrTeamHandler(_ req: Request) async throws -> HTTPStatusReturn Value
200 OK if the user was made a mod.
-
getTHOHandler(_:Asynchronous) GET /api/v3/admin/thoReturns a list of all users with THO access level. Only THO and Admin may call this method.
THO access level lets users promote other users to Modaerator and TwitarrTeam access, and demote to Banned status. THO users can also post notifications and set daily themes.
Declaration
Swift
func getTHOHandler(_ req: Request) async throws -> [UserHeader]Return Value
Array of
UserHeader. -
makeTHOHandler(_:Asynchronous) POST /api/v3/admin/tho/promote/:user_idMakes the target user a member of THO (The Home Office). Only admins may call this method. The user must have an access level of
.verifiedand not be temp-quarantined.Throws
badRequest if the target user isn’t verified, or if they’re temp quarantined.Declaration
Swift
func makeTHOHandler(_ req: Request) async throws -> HTTPStatusReturn Value
200 OK if the user was made a mod.
-
getUsersWithRole(_:Asynchronous) GET /api/v3/admin/userroles/:user_roleReturns a list of all users that have the given role.
Declaration
Swift
func getUsersWithRole(_ req: Request) async throws -> [UserHeader]Return Value
Array of
UserHeader. -
addRoleForUser(_:Asynchronous) POST /api/v3/admin/userroles/:user_id/addrole/:user_roleAdds the given role to the given user’s role list. Only THO and above may call this method.
Throws
badRequest if the target user already has the role.Declaration
Swift
func addRoleForUser(_ req: Request) async throws -> HTTPStatusReturn Value
200 OK if the user now has the given role.
-
removeRoleForUser(_:Asynchronous) POST /api/v3/admin/userroles/:user_id/removerole/:user_roleRemoves the given role from the target user’s role list. Only THO and above may call this method.
Throws
badRequest if the target user isn’t a Karaoke Manager.Declaration
Swift
func removeRoleForUser(_ req: Request) async throws -> HTTPStatusReturn Value
200 OK if the user was demoted successfully.
-
scheduleUploadPostHandler(_:Asynchronous) POST /api/v3/admin/schedule/updateHandles the POST of a new schedule .ics file.
Warning
Updating the schedule isn’t thread-safe, especially if admin is logged in twice. Uploading a schedule file while another admin account was attempting to apply its contents will cause errors. Once uploaded, an events file should be safe to verify and apply multiple times in parallel.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func scheduleUploadPostHandler(_ req: Request) async throws -> HTTPStatusParameters
requestBodyEventsUpdateDatawhich is really one big String (the .ics file) wrapped in JSON.Return Value
HTTP 200 OK -
scheduleChangeVerificationHandler(_:Asynchronous) GET /api/v3/admin/schedule/verifyReturns a struct showing the differences between the current schedule and the (already uploaded and saved to a local file) new schedule.
Note
This is a separate GET call, instead of the response from POSTing the updated .ics file, so that verifying and applying a schedule update can be idempotent. Once an update is uploaded, you can call the validate and apply endpoints repeatedly if necessary.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func scheduleChangeVerificationHandler(_ req: Request) async throws -> EventUpdateDifferenceDataReturn Value
-
scheduleChangeApplyHandler(_:Asynchronous) POST /api/v3/admin/schedule/update/applyApplies schedule changes to the schedule. Reads in a previously uploaded schedule file from
/admin/uploadschedule.icsand creates, deletes, and updates Event objects as necessary. IfforumPostsistrue, creates posts in Event forums notifying users of the schedule change. WhetherforumPostsis true or not, forums are created for new Events, and forum titles and initial posts are updated to match the updated event info.URL Query Parameters:
?processDeletes=trueto delete existing events not in the update list. Only set this if the update file is a comprehensive list of all events.?forumPosts=trueto create posts in the Event Forum of each modified event, alerting readers of the event change. We may want to forego change posts if we update the schedule as soon as we board the ship. For events created by this update, we always try to create and associate a forum for the event.
Throws
A 5xx response should be reported as a likely bug, please and thank you.
Declaration
Swift
func scheduleChangeApplyHandler(_ req: Request) async throws -> HTTPStatusReturn Value
HTTP 200 OK -
scheduleChangeLogHandler(_:Asynchronous) GET /api/v3/admin/schedule/viewlogGets the last 100 entries in the schedule update log, showing what the automatic (and manual) updates to the schedule have been doing.
Declaration
Swift
func scheduleChangeLogHandler(_ req: Request) async throws -> [EventUpdateLogData]Return Value
[EventUpdateLogData]the most recent 100 log entries, in descending order of update time. -
scheduleGetLogEntryHandler(_:Asynchronous) GET /api/v3/admin/schedule/viewlog/:log_id** Parameters:**
:log_idthe ID of the schedule change log entry to return.
NOTE: Unless you’ve requested the most recent change, the returned data may not match the state of the schedule in the db.
Declaration
Swift
func scheduleGetLogEntryHandler(_ req: Request) async throws -> EventUpdateDifferenceDataReturn Value
EventUpdateDifferenceDatashowing what events were modified by this change to the schedule -
reloadScheduleHandler(_:Asynchronous) GET /api/v3/admin/schedule/reloadTrigger a reload of the Sched event schedule. Normally this happens automatically every hour.
Declaration
Swift
func reloadScheduleHandler(_ req: Request) async throws -> HTTPStatusReturn Value
HTTP 200 OK.
-
triggerConsistencyJobHandler(_:Asynchronous) POST /api/v3/admin/notifications/reloadTrigger an internal consistency check job for Redis data.
Declaration
Swift
func triggerConsistencyJobHandler(_ req: Request) async throws -> HTTPStatusReturn Value
HTTP 200 OK.
-
userfileDownloadHandler(_:Asynchronous) GET /api/v3/admin/bulkuserfile/downloadHandles the GET of a userfile. A userfile is a zip file continaing a bunch of user records, with profile data and avatars. Intended to be used to facilitate server-to-server transfer of users.
Warning: Uses blocking IO–the thing that isn’t great for multithreaded servers.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func userfileDownloadHandler(_ req: Request) async throws -> ResponseParameters
requestBodyEventsUpdateDatawhich is really one big String (the .ics file) wrapped in JSON.Return Value
HTTP 200 OK -
userfileUploadPostHandler(_:Asynchronous) POST /api/v3/admin/bulkuserfile/uploadHandles the POST of a new userfile.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func userfileUploadPostHandler(_ req: Request) async throws -> HTTPStatusParameters
requestBodyDataof the zip'ed userfile..Return Value
HTTP 200 OK -
userfileVerificationHandler(_:Asynchronous) GET /api/v3/admin/bulkuserfile/verifyReturns a struct showing the differences between the current schedule and the (already uploaded and saved to a local file) new schedule.
Note
This is a separate GET call, instead of the response from POSTing the updated .ics file, so that verifying and applying a schedule update can be idempotent. Once an update is uploaded, you can call the validate and apply endpoints repeatedly if necessary.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func userfileVerificationHandler(_ req: Request) async throws -> BulkUserUpdateVerificationDataReturn Value
-
userfileApplyHandler(_:Asynchronous) POST /api/v3/admin/bulkuserfile/update/applyThrows
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func userfileApplyHandler(_ req: Request) async throws -> BulkUserUpdateVerificationDataReturn Value
HTTP 200 OK
-
importUsersFromUploadedUserfile(_:AsynchronousverifyOnly: ) Declaration
Swift
func importUsersFromUploadedUserfile(_ req: Request, verifyOnly: Bool) async throws -> BulkUserUpdateVerificationData -
importUser(_:AsynchronoususerToImport: verifyOnly: verification: ) Declaration
Swift
func importUser(_ req: Request, userToImport: UserSaveRestoreData, verifyOnly: Bool, verification: inout BulkUserUpdateVerificationData) async -
Declaration
Swift
func importPerformer(_ req: Request, performerData: PerformerUploadData, verifyOnly: Bool, userID: UUID? = nil, verification: inout BulkUserUpdateVerificationData) async -
Declaration
Swift
func importNeedPhotographer_Event(_ req: Request, eventUID: String, verifyOnly: Bool, verification: inout BulkUserUpdateVerificationData) async -
copyImage(_:AsynchronousverifyOnly: on: ) Declaration
Swift
func copyImage(_ image: String, verifyOnly: Bool, on req: Request) async throws -> String -
Declaration
Swift
func uploadSchedulePath() throws -> URL -
Declaration
Swift
func uploadUserDirPath() throws -> URL -
Declaration
Swift
func uploadUserfilePath() throws -> URL -
Declaration
Swift
struct ImportError : LocalizedError
View on GitHub