@@ -515,18 +515,6 @@ func createWorkspace(
515
515
return
516
516
}
517
517
518
- // The user also needs permission to use the template. At this point they have
519
- // read perms, but not necessarily "use"
520
- if ! api .Authorize (r , policy .ActionUse , template ) {
521
- httpapi .Write (ctx , rw , http .StatusForbidden , codersdk.Response {
522
- Message : fmt .Sprintf ("Unauthorized access to use the template %q." , template .Name ),
523
- Detail : "Although you are able to view the template, you are unable to create a workspace using it. " +
524
- "Please contact an administrator about your permissions if you feel this is an error." ,
525
- Validations : nil ,
526
- })
527
- return
528
- }
529
-
530
518
// Update audit log's organization
531
519
auditReq .UpdateOrganizationID (template .OrganizationID )
532
520
@@ -537,6 +525,18 @@ func createWorkspace(
537
525
httpapi .ResourceNotFound (rw )
538
526
return
539
527
}
528
+ // The user also needs permission to use the template. At this point they have
529
+ // read perms, but not necessarily "use". This is also checked in `db.InsertWorkspace`.
530
+ // Doing this up front can save some work below if the user doesn't have permission.
531
+ if ! api .Authorize (r , policy .ActionUse , template ) {
532
+ httpapi .Write (ctx , rw , http .StatusForbidden , codersdk.Response {
533
+ Message : fmt .Sprintf ("Unauthorized access to use the template %q." , template .Name ),
534
+ Detail : "Although you are able to view the template, you are unable to create a workspace using it. " +
535
+ "Please contact an administrator about your permissions if you feel this is an error." ,
536
+ Validations : nil ,
537
+ })
538
+ return
539
+ }
540
540
541
541
templateAccessControl := (* (api .AccessControlStore .Load ())).GetTemplateAccessControl (template )
542
542
if templateAccessControl .IsDeprecated () {
0 commit comments