mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add new workspace:share action type (#20198)
Closes [coder/internal#1012](https://github.com/coder/internal/issues/1012)
This commit is contained in:
@@ -1792,7 +1792,7 @@ func (q *querier) DeleteWorkspaceACLByID(ctx context.Context, id uuid.UUID) erro
|
||||
return w.WorkspaceTable(), nil
|
||||
}
|
||||
|
||||
return fetchAndExec(q.log, q.auth, policy.ActionUpdate, fetch, q.db.DeleteWorkspaceACLByID)(ctx, id)
|
||||
return fetchAndExec(q.log, q.auth, policy.ActionShare, fetch, q.db.DeleteWorkspaceACLByID)(ctx, id)
|
||||
}
|
||||
|
||||
func (q *querier) DeleteWorkspaceAgentPortShare(ctx context.Context, arg database.DeleteWorkspaceAgentPortShareParams) error {
|
||||
@@ -3388,7 +3388,7 @@ func (q *querier) GetWorkspaceACLByID(ctx context.Context, id uuid.UUID) (databa
|
||||
if err != nil {
|
||||
return database.GetWorkspaceACLByIDRow{}, err
|
||||
}
|
||||
if err := q.authorizeContext(ctx, policy.ActionCreate, workspace); err != nil {
|
||||
if err := q.authorizeContext(ctx, policy.ActionShare, workspace); err != nil {
|
||||
return database.GetWorkspaceACLByIDRow{}, err
|
||||
}
|
||||
return q.db.GetWorkspaceACLByID(ctx, id)
|
||||
@@ -5312,7 +5312,7 @@ func (q *querier) UpdateWorkspaceACLByID(ctx context.Context, arg database.Updat
|
||||
return w.WorkspaceTable(), nil
|
||||
}
|
||||
|
||||
return fetchAndExec(q.log, q.auth, policy.ActionCreate, fetch, q.db.UpdateWorkspaceACLByID)(ctx, arg)
|
||||
return fetchAndExec(q.log, q.auth, policy.ActionShare, fetch, q.db.UpdateWorkspaceACLByID)(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) UpdateWorkspaceAgentConnectionByID(ctx context.Context, arg database.UpdateWorkspaceAgentConnectionByIDParams) error {
|
||||
|
||||
@@ -1732,20 +1732,20 @@ func (s *MethodTestSuite) TestWorkspace() {
|
||||
ws := testutil.Fake(s.T(), faker, database.Workspace{})
|
||||
dbM.EXPECT().GetWorkspaceByID(gomock.Any(), ws.ID).Return(ws, nil).AnyTimes()
|
||||
dbM.EXPECT().GetWorkspaceACLByID(gomock.Any(), ws.ID).Return(database.GetWorkspaceACLByIDRow{}, nil).AnyTimes()
|
||||
check.Args(ws.ID).Asserts(ws, policy.ActionCreate)
|
||||
check.Args(ws.ID).Asserts(ws, policy.ActionShare)
|
||||
}))
|
||||
s.Run("UpdateWorkspaceACLByID", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
|
||||
w := testutil.Fake(s.T(), faker, database.Workspace{})
|
||||
arg := database.UpdateWorkspaceACLByIDParams{ID: w.ID}
|
||||
dbm.EXPECT().GetWorkspaceByID(gomock.Any(), w.ID).Return(w, nil).AnyTimes()
|
||||
dbm.EXPECT().UpdateWorkspaceACLByID(gomock.Any(), arg).Return(nil).AnyTimes()
|
||||
check.Args(arg).Asserts(w, policy.ActionCreate)
|
||||
check.Args(arg).Asserts(w, policy.ActionShare)
|
||||
}))
|
||||
s.Run("DeleteWorkspaceACLByID", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
|
||||
w := testutil.Fake(s.T(), faker, database.Workspace{})
|
||||
dbm.EXPECT().GetWorkspaceByID(gomock.Any(), w.ID).Return(w, nil).AnyTimes()
|
||||
dbm.EXPECT().DeleteWorkspaceACLByID(gomock.Any(), w.ID).Return(nil).AnyTimes()
|
||||
check.Args(w.ID).Asserts(w, policy.ActionUpdate)
|
||||
check.Args(w.ID).Asserts(w, policy.ActionShare)
|
||||
}))
|
||||
s.Run("GetLatestWorkspaceBuildByWorkspaceID", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
|
||||
w := testutil.Fake(s.T(), faker, database.Workspace{})
|
||||
|
||||
Generated
+3
-1
@@ -202,7 +202,9 @@ CREATE TYPE api_key_scope AS ENUM (
|
||||
'task:read',
|
||||
'task:update',
|
||||
'task:delete',
|
||||
'task:*'
|
||||
'task:*',
|
||||
'workspace:share',
|
||||
'workspace_dormant:share'
|
||||
);
|
||||
|
||||
CREATE TYPE app_sharing_level AS ENUM (
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
-- No-op: keep enum values to avoid dependency churn.
|
||||
-- If strict removal is required, create a new enum type without these values,
|
||||
-- cast columns, drop the old type, and rename.
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS 'workspace:share';
|
||||
ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS 'workspace_dormant:share';
|
||||
@@ -211,6 +211,8 @@ const (
|
||||
ApiKeyScopeTaskUpdate APIKeyScope = "task:update"
|
||||
ApiKeyScopeTaskDelete APIKeyScope = "task:delete"
|
||||
ApiKeyScopeTask APIKeyScope = "task:*"
|
||||
ApiKeyScopeWorkspaceShare APIKeyScope = "workspace:share"
|
||||
ApiKeyScopeWorkspaceDormantShare APIKeyScope = "workspace_dormant:share"
|
||||
)
|
||||
|
||||
func (e *APIKeyScope) Scan(src interface{}) error {
|
||||
@@ -441,7 +443,9 @@ func (e APIKeyScope) Valid() bool {
|
||||
ApiKeyScopeTaskRead,
|
||||
ApiKeyScopeTaskUpdate,
|
||||
ApiKeyScopeTaskDelete,
|
||||
ApiKeyScopeTask:
|
||||
ApiKeyScopeTask,
|
||||
ApiKeyScopeWorkspaceShare,
|
||||
ApiKeyScopeWorkspaceDormantShare:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -641,6 +645,8 @@ func AllAPIKeyScopeValues() []APIKeyScope {
|
||||
ApiKeyScopeTaskUpdate,
|
||||
ApiKeyScopeTaskDelete,
|
||||
ApiKeyScopeTask,
|
||||
ApiKeyScopeWorkspaceShare,
|
||||
ApiKeyScopeWorkspaceDormantShare,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user