@@ -85,7 +85,7 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) {
85
85
// TODO: @emyrk this currently happens outside the database tx used to create
86
86
// the user. Maybe I add this ability to grant roles in the createUser api
87
87
// and add some rbac bypass when calling api functions this way??
88
- // Add the admin role to this first user
88
+ // Add the admin role to this first user.
89
89
_ , err = api .Database .UpdateUserRoles (r .Context (), database.UpdateUserRolesParams {
90
90
GrantedRoles : []string {rbac .RoleAdmin (), rbac .RoleMember ()},
91
91
ID : user .ID ,
@@ -109,7 +109,7 @@ func (api *API) users(rw http.ResponseWriter, r *http.Request) {
109
109
statusFilter = r .URL .Query ().Get ("status" )
110
110
)
111
111
112
- // Reading all users across the site
112
+ // Reading all users across the site.
113
113
if ! api .Authorize (rw , r , rbac .ActionRead , rbac .ResourceUser ) {
114
114
return
115
115
}
@@ -162,7 +162,7 @@ func (api *API) users(rw http.ResponseWriter, r *http.Request) {
162
162
163
163
// Creates a new user.
164
164
func (api * API ) postUser (rw http.ResponseWriter , r * http.Request ) {
165
- // Create the user on the site
165
+ // Create the user on the site.
166
166
if ! api .Authorize (rw , r , rbac .ActionCreate , rbac .ResourceUser ) {
167
167
return
168
168
}
@@ -408,11 +408,11 @@ func (api *API) userRoles(rw http.ResponseWriter, r *http.Request) {
408
408
return
409
409
}
410
410
411
- // Only include ones we can read from RBAC
411
+ // Only include ones we can read from RBAC.
412
412
memberships = AuthorizeFilter (api , r , rbac .ActionRead , memberships )
413
413
414
414
for _ , mem := range memberships {
415
- // If we can read the org member, include the roles
415
+ // If we can read the org member, include the roles.
416
416
if err == nil {
417
417
resp .OrganizationRoles [mem .OrganizationID ] = mem .Roles
418
418
}
@@ -422,7 +422,7 @@ func (api *API) userRoles(rw http.ResponseWriter, r *http.Request) {
422
422
}
423
423
424
424
func (api * API ) putUserRoles (rw http.ResponseWriter , r * http.Request ) {
425
- // User is the user to modify
425
+ // User is the user to modify.
426
426
user := httpmw .UserParam (r )
427
427
roles := httpmw .UserRoles (r )
428
428
@@ -470,7 +470,7 @@ func (api *API) putUserRoles(rw http.ResponseWriter, r *http.Request) {
470
470
// updateSiteUserRoles will ensure only site wide roles are passed in as arguments.
471
471
// If an organization role is included, an error is returned.
472
472
func (api * API ) updateSiteUserRoles (ctx context.Context , args database.UpdateUserRolesParams ) (database.User , error ) {
473
- // Enforce only site wide roles
473
+ // Enforce only site wide roles.
474
474
for _ , r := range args .GrantedRoles {
475
475
if _ , ok := rbac .IsOrgRole (r ); ok {
476
476
return database.User {}, xerrors .Errorf ("must only update site wide roles" )
@@ -504,7 +504,7 @@ func (api *API) organizationsByUser(rw http.ResponseWriter, r *http.Request) {
504
504
return
505
505
}
506
506
507
- // Only return orgs the user can read
507
+ // Only return orgs the user can read.
508
508
organizations = AuthorizeFilter (api , r , rbac .ActionRead , organizations )
509
509
510
510
publicOrganizations := make ([]codersdk.Organization , 0 , len (organizations ))
@@ -584,7 +584,7 @@ func (api *API) postOrganizationsByUser(rw http.ResponseWriter, r *http.Request)
584
584
CreatedAt : database .Now (),
585
585
UpdatedAt : database .Now (),
586
586
Roles : []string {
587
- // Also assign member role incase they get demoted from admin
587
+ // Also assign member role incase they get demoted from admin.
588
588
rbac .RoleOrgMember (organization .ID ),
589
589
rbac .RoleOrgAdmin (organization .ID ),
590
590
},
@@ -650,7 +650,7 @@ func (api *API) postLogin(rw http.ResponseWriter, r *http.Request) {
650
650
})
651
651
}
652
652
653
- // Creates a new session key, used for logging in via the CLI
653
+ // Creates a new session key, used for logging in via the CLI.
654
654
func (api * API ) postAPIKey (rw http.ResponseWriter , r * http.Request ) {
655
655
user := httpmw .UserParam (r )
656
656
@@ -669,9 +669,19 @@ func (api *API) postAPIKey(rw http.ResponseWriter, r *http.Request) {
669
669
httpapi .Write (rw , http .StatusCreated , codersdk.GenerateAPIKeyResponse {Key : sessionToken })
670
670
}
671
671
672
- // Clear the user's session cookie
672
+ // Clear the user's session cookie.
673
673
func (api * API ) postLogout (rw http.ResponseWriter , r * http.Request ) {
674
- // Delete the session token from database
674
+ // Get a blank token cookie.
675
+ cookie := & http.Cookie {
676
+ // MaxAge < 0 means to delete the cookie now.
677
+ MaxAge : - 1 ,
678
+ Name : httpmw .SessionTokenKey ,
679
+ Path : "/" ,
680
+ }
681
+
682
+ http .SetCookie (rw , cookie )
683
+
684
+ // Delete the session token from database.
675
685
apiKey := httpmw .APIKey (r )
676
686
err := api .Database .DeleteAPIKeyByID (r .Context (), apiKey .ID )
677
687
if err != nil {
@@ -681,15 +691,6 @@ func (api *API) postLogout(rw http.ResponseWriter, r *http.Request) {
681
691
return
682
692
}
683
693
684
- // Get a blank token cookie
685
- cookie := & http.Cookie {
686
- // MaxAge < 0 means to delete the cookie now
687
- MaxAge : - 1 ,
688
- Name : httpmw .SessionTokenKey ,
689
- Path : "/" ,
690
- }
691
-
692
- http .SetCookie (rw , cookie )
693
694
httpapi .Write (rw , http .StatusOK , httpapi.Response {
694
695
Message : "Logged out!" ,
695
696
})
@@ -771,7 +772,7 @@ func (api *API) createUser(ctx context.Context, req codersdk.CreateUserRequest)
771
772
req .OrganizationID = organization .ID
772
773
orgRoles = append (orgRoles , rbac .RoleOrgAdmin (req .OrganizationID ))
773
774
}
774
- // Always also be a member
775
+ // Always also be a member.
775
776
orgRoles = append (orgRoles , rbac .RoleOrgMember (req .OrganizationID ))
776
777
777
778
params := database.InsertUserParams {
@@ -817,7 +818,7 @@ func (api *API) createUser(ctx context.Context, req codersdk.CreateUserRequest)
817
818
UserID : user .ID ,
818
819
CreatedAt : database .Now (),
819
820
UpdatedAt : database .Now (),
820
- // By default give them membership to the organization
821
+ // By default give them membership to the organization.
821
822
Roles : orgRoles ,
822
823
})
823
824
if err != nil {
0 commit comments