@@ -1155,64 +1155,74 @@ func New(options *Options) *API {
11551155 r .Get ("/" , api .AssignableSiteRoles )
11561156 })
11571157 r .Route ("/{user}" , func (r chi.Router ) {
1158- r .Use (httpmw .ExtractUserParam (options .Database ))
1159- r .Post ("/convert-login" , api .postConvertLoginType )
1160- r .Delete ("/" , api .deleteUser )
1161- r .Get ("/" , api .userByName )
1162- r .Get ("/autofill-parameters" , api .userAutofillParameters )
1163- r .Get ("/login-type" , api .userLoginType )
1164- r .Put ("/profile" , api .putUserProfile )
1165- r .Route ("/status" , func (r chi.Router ) {
1166- r .Put ("/suspend" , api .putSuspendUserAccount ())
1167- r .Put ("/activate" , api .putActivateUserAccount ())
1158+ r .Group (func (r chi.Router ) {
1159+ r .Use (httpmw .ExtractUserParamOptional (options .Database ))
1160+ // Creating workspaces does not require permissions on the user, only the
1161+ // organization member. This endpoint should match the authz story of
1162+ // postWorkspacesByOrganization
1163+ r .Post ("/workspaces" , api .postUserWorkspaces )
11681164 })
1169- r .Get ("/appearance" , api .userAppearanceSettings )
1170- r .Put ("/appearance" , api .putUserAppearanceSettings )
1171- r .Route ("/password" , func (r chi.Router ) {
1172- r .Use (httpmw .RateLimit (options .LoginRateLimit , time .Minute ))
1173- r .Put ("/" , api .putUserPassword )
1174- })
1175- // These roles apply to the site wide permissions.
1176- r .Put ("/roles" , api .putUserRoles )
1177- r .Get ("/roles" , api .userRoles )
1178-
1179- r .Route ("/keys" , func (r chi.Router ) {
1180- r .Post ("/" , api .postAPIKey )
1181- r .Route ("/tokens" , func (r chi.Router ) {
1182- r .Post ("/" , api .postToken )
1183- r .Get ("/" , api .tokens )
1184- r .Get ("/tokenconfig" , api .tokenConfig )
1185- r .Route ("/{keyname}" , func (r chi.Router ) {
1186- r .Get ("/" , api .apiKeyByName )
1187- })
1165+
1166+ r .Group (func (r chi.Router ) {
1167+ r .Use (httpmw .ExtractUserParam (options .Database ))
1168+
1169+ r .Post ("/convert-login" , api .postConvertLoginType )
1170+ r .Delete ("/" , api .deleteUser )
1171+ r .Get ("/" , api .userByName )
1172+ r .Get ("/autofill-parameters" , api .userAutofillParameters )
1173+ r .Get ("/login-type" , api .userLoginType )
1174+ r .Put ("/profile" , api .putUserProfile )
1175+ r .Route ("/status" , func (r chi.Router ) {
1176+ r .Put ("/suspend" , api .putSuspendUserAccount ())
1177+ r .Put ("/activate" , api .putActivateUserAccount ())
11881178 })
1189- r .Route ("/{keyid}" , func (r chi.Router ) {
1190- r .Get ("/" , api .apiKeyByID )
1191- r .Delete ("/" , api .deleteAPIKey )
1179+ r .Get ("/appearance" , api .userAppearanceSettings )
1180+ r .Put ("/appearance" , api .putUserAppearanceSettings )
1181+ r .Route ("/password" , func (r chi.Router ) {
1182+ r .Use (httpmw .RateLimit (options .LoginRateLimit , time .Minute ))
1183+ r .Put ("/" , api .putUserPassword )
1184+ })
1185+ // These roles apply to the site wide permissions.
1186+ r .Put ("/roles" , api .putUserRoles )
1187+ r .Get ("/roles" , api .userRoles )
1188+
1189+ r .Route ("/keys" , func (r chi.Router ) {
1190+ r .Post ("/" , api .postAPIKey )
1191+ r .Route ("/tokens" , func (r chi.Router ) {
1192+ r .Post ("/" , api .postToken )
1193+ r .Get ("/" , api .tokens )
1194+ r .Get ("/tokenconfig" , api .tokenConfig )
1195+ r .Route ("/{keyname}" , func (r chi.Router ) {
1196+ r .Get ("/" , api .apiKeyByName )
1197+ })
1198+ })
1199+ r .Route ("/{keyid}" , func (r chi.Router ) {
1200+ r .Get ("/" , api .apiKeyByID )
1201+ r .Delete ("/" , api .deleteAPIKey )
1202+ })
11921203 })
1193- })
11941204
1195- r .Route ("/organizations" , func (r chi.Router ) {
1196- r .Get ("/" , api .organizationsByUser )
1197- r .Get ("/{organizationname}" , api .organizationByUserAndName )
1198- })
1199- r .Post ("/workspaces" , api .postUserWorkspaces )
1200- r .Route ("/workspace/{workspacename}" , func (r chi.Router ) {
1201- r .Get ("/" , api .workspaceByOwnerAndName )
1202- r .Get ("/builds/{buildnumber}" , api .workspaceBuildByBuildNumber )
1203- })
1204- r .Get ("/gitsshkey" , api .gitSSHKey )
1205- r .Put ("/gitsshkey" , api .regenerateGitSSHKey )
1206- r .Route ("/notifications" , func (r chi.Router ) {
1207- r .Route ("/preferences" , func (r chi.Router ) {
1208- r .Get ("/" , api .userNotificationPreferences )
1209- r .Put ("/" , api .putUserNotificationPreferences )
1205+ r .Route ("/organizations" , func (r chi.Router ) {
1206+ r .Get ("/" , api .organizationsByUser )
1207+ r .Get ("/{organizationname}" , api .organizationByUserAndName )
1208+ })
1209+ r .Route ("/workspace/{workspacename}" , func (r chi.Router ) {
1210+ r .Get ("/" , api .workspaceByOwnerAndName )
1211+ r .Get ("/builds/{buildnumber}" , api .workspaceBuildByBuildNumber )
1212+ })
1213+ r .Get ("/gitsshkey" , api .gitSSHKey )
1214+ r .Put ("/gitsshkey" , api .regenerateGitSSHKey )
1215+ r .Route ("/notifications" , func (r chi.Router ) {
1216+ r .Route ("/preferences" , func (r chi.Router ) {
1217+ r .Get ("/" , api .userNotificationPreferences )
1218+ r .Put ("/" , api .putUserNotificationPreferences )
1219+ })
1220+ })
1221+ r .Route ("/webpush" , func (r chi.Router ) {
1222+ r .Post ("/subscription" , api .postUserWebpushSubscription )
1223+ r .Delete ("/subscription" , api .deleteUserWebpushSubscription )
1224+ r .Post ("/test" , api .postUserPushNotificationTest )
12101225 })
1211- })
1212- r .Route ("/webpush" , func (r chi.Router ) {
1213- r .Post ("/subscription" , api .postUserWebpushSubscription )
1214- r .Delete ("/subscription" , api .deleteUserWebpushSubscription )
1215- r .Post ("/test" , api .postUserPushNotificationTest )
12161226 })
12171227 })
12181228 })
0 commit comments