Skip to content

Commit afe328b

Browse files
committed
groups changes
1 parent c2e1196 commit afe328b

File tree

11 files changed

+28
-48
lines changed

11 files changed

+28
-48
lines changed

coderd/database/databasefake/databasefake.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,6 @@ func (q *fakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd
10011001
tpl.Icon = arg.Icon
10021002
tpl.MaxTtl = arg.MaxTtl
10031003
tpl.MinAutostartInterval = arg.MinAutostartInterval
1004-
tpl.IsPrivate = arg.IsPrivate
10051004
q.templates[idx] = tpl
10061005
return tpl, nil
10071006
}
@@ -1766,7 +1765,6 @@ func (q *fakeQuerier) InsertTemplate(_ context.Context, arg database.InsertTempl
17661765
MaxTtl: arg.MaxTtl,
17671766
MinAutostartInterval: arg.MinAutostartInterval,
17681767
CreatedBy: arg.CreatedBy,
1769-
IsPrivate: arg.IsPrivate,
17701768
}
17711769
template = template.SetUserACL(database.UserACL{})
17721770
q.templates = append(q.templates, template)

coderd/database/dump.sql

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000054_template_acl.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
BEGIN;
22

33
ALTER TABLE templates ADD COLUMN user_acl jsonb NOT NULL default '{}';
4-
ALTER TABLE templates ADD COLUMN is_private boolean NOT NULL default 'false';
4+
ALTER TABLE templates ADD COLUMN group_acl jsonb NOT NULL default '{}';
55

66
CREATE TYPE template_role AS ENUM (
77
'read',

coderd/database/modelmethods.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
// UserACL is a map of user_ids to permissions.
1111
type UserACL map[string]TemplateRole
1212

13+
// Group is a map of user_ids to permissions.
14+
type GroupACL map[string]TemplateRole
15+
1316
func (u UserACL) Actions() map[string][]rbac.Action {
1417
aclRBAC := make(map[string][]rbac.Action, len(u))
1518
for k, v := range u {
@@ -33,6 +36,8 @@ func (t Template) UserACL() UserACL {
3336
return acl
3437
}
3538

39+
func (t Template) GroupACL() Gr
40+
3641
func (t Template) SetUserACL(acl UserACL) Template {
3742
raw, err := json.Marshal(acl)
3843
if err != nil {
@@ -69,9 +74,6 @@ func (s APIKeyScope) ToRBAC() rbac.Scope {
6974

7075
func (t Template) RBACObject() rbac.Object {
7176
obj := rbac.ResourceTemplate
72-
if t.IsPrivate {
73-
obj = rbac.ResourceTemplatePrivate
74-
}
7577
return obj.InOrg(t.OrganizationID).WithACLUserList(t.UserACL().Actions())
7678
}
7779

coderd/database/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 14 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templates.sql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ INSERT INTO
6868
max_ttl,
6969
min_autostart_interval,
7070
created_by,
71-
icon,
72-
is_private
71+
icon
7372
)
7473
VALUES
75-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING *;
74+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *;
7675

7776
-- name: UpdateTemplateActiveVersionByID :exec
7877
UPDATE
@@ -101,8 +100,7 @@ SET
101100
max_ttl = $4,
102101
min_autostart_interval = $5,
103102
name = $6,
104-
icon = $7,
105-
is_private = $8
103+
icon = $7
106104
WHERE
107105
id = $1
108106
RETURNING

coderd/database/sqlc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ rename:
4040
ids: IDs
4141
jwt: JWT
4242
user_acl: userACL
43+
group_acl: userACL

coderd/rbac/builtin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ var (
108108
Name: templateAdmin,
109109
DisplayName: "Template Admin",
110110
Site: permissions(map[string][]Action{
111-
ResourceTemplate.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
112-
ResourceTemplatePrivate.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
111+
ResourceTemplate.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
113112
// CRUD all files, even those they did not upload.
114113
ResourceFile.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
115114
ResourceWorkspace.Type: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},

coderd/rbac/object.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ var (
6262
Type: "group",
6363
}
6464

65-
ResourceTemplatePrivate = Object{
66-
Type: "template_private",
67-
}
68-
6965
ResourceFile = Object{
7066
Type: "file",
7167
}

coderd/templates.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
262262
MaxTtl: int64(maxTTL),
263263
MinAutostartInterval: int64(minAutostartInterval),
264264
CreatedBy: apiKey.UserID,
265-
IsPrivate: createTemplate.IsPrivate,
266265
})
267266
if err != nil {
268267
return xerrors.Errorf("insert template: %s", err)
@@ -533,8 +532,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
533532
req.Icon == template.Icon &&
534533
req.MaxTTLMillis == time.Duration(template.MaxTtl).Milliseconds() &&
535534
req.MinAutostartIntervalMillis == time.Duration(template.MinAutostartInterval).Milliseconds() &&
536-
len(req.UserPerms) == 0 &&
537-
(req.IsPrivate == nil || req.IsPrivate != nil && *req.IsPrivate == template.IsPrivate) {
535+
len(req.UserPerms) == 0 {
538536
return nil
539537
}
540538

@@ -544,7 +542,6 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
544542
icon := req.Icon
545543
maxTTL := time.Duration(req.MaxTTLMillis) * time.Millisecond
546544
minAutostartInterval := time.Duration(req.MinAutostartIntervalMillis) * time.Millisecond
547-
isPrivate := template.IsPrivate
548545

549546
if name == "" {
550547
name = template.Name
@@ -555,9 +552,6 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
555552
if minAutostartInterval == 0 {
556553
minAutostartInterval = time.Duration(template.MinAutostartInterval)
557554
}
558-
if req.IsPrivate != nil {
559-
isPrivate = *req.IsPrivate
560-
}
561555

562556
if len(req.UserPerms) > 0 {
563557
userACL := template.UserACL()
@@ -585,7 +579,6 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
585579
Icon: icon,
586580
MaxTtl: int64(maxTTL),
587581
MinAutostartInterval: int64(minAutostartInterval),
588-
IsPrivate: isPrivate,
589582
})
590583
if err != nil {
591584
return err
@@ -876,7 +869,6 @@ func (api *API) convertTemplate(
876869
CreatedByID: template.CreatedBy,
877870
CreatedByName: createdByName,
878871
UserRoles: convertTemplateACL(template.UserACL()),
879-
IsPrivate: template.IsPrivate,
880872
}
881873
}
882874

0 commit comments

Comments
 (0)