File tree Expand file tree Collapse file tree 3 files changed +68
-3
lines changed Expand file tree Collapse file tree 3 files changed +68
-3
lines changed Original file line number Diff line number Diff line change 4
4
"testing"
5
5
6
6
"github.com/coder/coder/coderd/rbac"
7
+ "github.com/coder/coder/coderd/util/slice"
7
8
)
8
9
9
10
func TestObjectEqual (t * testing.T ) {
@@ -174,3 +175,20 @@ func TestObjectEqual(t *testing.T) {
174
175
})
175
176
}
176
177
}
178
+
179
+ // TestAllResources ensures that all resources have a unique type name.
180
+ func TestAllResources (t * testing.T ) {
181
+ var typeNames []string
182
+ resources := rbac .AllResources ()
183
+ for _ , r := range resources {
184
+ if r .Type == "" {
185
+ t .Errorf ("empty type name: %s" , r .Type )
186
+ continue
187
+ }
188
+ if slice .Contains (typeNames , r .Type ) {
189
+ t .Errorf ("duplicate type name: %s" , r .Type )
190
+ continue
191
+ }
192
+ typeNames = append (typeNames , r .Type )
193
+ }
194
+ }
Original file line number Diff line number Diff line change @@ -76,9 +76,26 @@ var builtInRoles = map[string]func(orgID string) Role{
76
76
return Role {
77
77
Name : owner ,
78
78
DisplayName : "Owner" ,
79
- Site : Permissions (map [string ][]Action {
80
- ResourceWildcard .Type : {WildcardSymbol },
81
- }),
79
+ Site : func () []Permission {
80
+ // Owner can do all actions on all resources, minus some exceptions.
81
+ resources := AllResources ()
82
+ var perms []Permission
83
+
84
+ for _ , r := range resources {
85
+ // Exceptions
86
+ if r .Equal (ResourceWildcard ) ||
87
+ r .Equal (ResourceWorkspaceExecution ) {
88
+ continue
89
+ }
90
+ // Owners can do everything else
91
+ perms = append (perms , Permission {
92
+ Negate : false ,
93
+ ResourceType : r .Type ,
94
+ Action : WildcardSymbol ,
95
+ })
96
+ }
97
+ return perms
98
+ }(),
82
99
Org : map [string ][]Permission {},
83
100
User : []Permission {},
84
101
}
You can’t perform that action at this time.
0 commit comments