@@ -109,36 +109,12 @@ func ExtractWorkspaceAgentAndLatestBuild(opts ExtractWorkspaceAgentAndLatestBuil
109
109
return
110
110
}
111
111
112
- //nolint:gocritic // System needs to be able to get owner roles.
113
- roles , err := opts .DB .GetAuthorizationUserRoles (dbauthz .AsSystemRestricted (ctx ), row .WorkspaceTable .OwnerID )
114
- if err != nil {
115
- httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
116
- Message : "Internal error checking workspace agent authorization." ,
117
- Detail : err .Error (),
118
- })
119
- return
120
- }
121
-
122
- roleNames , err := roles .RoleNames ()
123
- if err != nil {
124
- httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
125
- Message : "Internal server error" ,
126
- Detail : err .Error (),
127
- })
128
- return
129
- }
130
-
131
- subject := rbac.Subject {
132
- ID : row .WorkspaceTable .OwnerID .String (),
133
- Roles : rbac .RoleIdentifiers (roleNames ),
134
- Groups : roles .Groups ,
135
- Scope : rbac .WorkspaceAgentScope (rbac.WorkspaceAgentScopeParams {
136
- WorkspaceID : row .WorkspaceTable .ID ,
137
- OwnerID : row .WorkspaceTable .OwnerID ,
138
- TemplateID : row .WorkspaceTable .TemplateID ,
139
- VersionID : row .WorkspaceBuild .TemplateVersionID ,
140
- }),
141
- }.WithCachedASTValue ()
112
+ subject , _ , err := UserRBACSubject (ctx , opts .DB , row .WorkspaceTable .OwnerID , rbac .WorkspaceAgentScope (rbac.WorkspaceAgentScopeParams {
113
+ WorkspaceID : row .WorkspaceTable .ID ,
114
+ OwnerID : row .WorkspaceTable .OwnerID ,
115
+ TemplateID : row .WorkspaceTable .TemplateID ,
116
+ VersionID : row .WorkspaceBuild .TemplateVersionID ,
117
+ }))
142
118
143
119
ctx = context .WithValue (ctx , workspaceAgentContextKey {}, row .WorkspaceAgent )
144
120
ctx = context .WithValue (ctx , latestBuildContextKey {}, row .WorkspaceBuild )
0 commit comments