mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: authz 'any_org' to return if at least 1 org has perms (#14009)
* chore: authz 'any_org' to return if at least 1 org has perms Allows checking if a user can do an action in any organization, rather than a specific one. Allows asking general questions on the UI to determine which elements to show. * more strict, add comments to policy * add unit tests and extend to /authcheck api * make field optional
This commit is contained in:
@ -23,6 +23,12 @@ type Object struct {
|
||||
Owner string `json:"owner"`
|
||||
// OrgID specifies which org the object is a part of.
|
||||
OrgID string `json:"org_owner"`
|
||||
// AnyOrgOwner will disregard the org_owner when checking for permissions
|
||||
// Use this to ask, "Can the actor do this action on any org?" when
|
||||
// the exact organization is not important or known.
|
||||
// E.g: The UI should show a "create template" button if the user
|
||||
// can create a template in any org.
|
||||
AnyOrgOwner bool `json:"any_org"`
|
||||
|
||||
// Type is "workspace", "project", "app", etc
|
||||
Type string `json:"type"`
|
||||
@ -115,6 +121,7 @@ func (z Object) All() Object {
|
||||
Type: z.Type,
|
||||
ACLUserList: map[string][]policy.Action{},
|
||||
ACLGroupList: map[string][]policy.Action{},
|
||||
AnyOrgOwner: z.AnyOrgOwner,
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,6 +133,7 @@ func (z Object) WithIDString(id string) Object {
|
||||
Type: z.Type,
|
||||
ACLUserList: z.ACLUserList,
|
||||
ACLGroupList: z.ACLGroupList,
|
||||
AnyOrgOwner: z.AnyOrgOwner,
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,6 +145,7 @@ func (z Object) WithID(id uuid.UUID) Object {
|
||||
Type: z.Type,
|
||||
ACLUserList: z.ACLUserList,
|
||||
ACLGroupList: z.ACLGroupList,
|
||||
AnyOrgOwner: z.AnyOrgOwner,
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,6 +158,21 @@ func (z Object) InOrg(orgID uuid.UUID) Object {
|
||||
Type: z.Type,
|
||||
ACLUserList: z.ACLUserList,
|
||||
ACLGroupList: z.ACLGroupList,
|
||||
// InOrg implies AnyOrgOwner is false
|
||||
AnyOrgOwner: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (z Object) AnyOrganization() Object {
|
||||
return Object{
|
||||
ID: z.ID,
|
||||
Owner: z.Owner,
|
||||
// AnyOrgOwner cannot have an org owner also set.
|
||||
OrgID: "",
|
||||
Type: z.Type,
|
||||
ACLUserList: z.ACLUserList,
|
||||
ACLGroupList: z.ACLGroupList,
|
||||
AnyOrgOwner: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,6 +185,7 @@ func (z Object) WithOwner(ownerID string) Object {
|
||||
Type: z.Type,
|
||||
ACLUserList: z.ACLUserList,
|
||||
ACLGroupList: z.ACLGroupList,
|
||||
AnyOrgOwner: z.AnyOrgOwner,
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,6 +198,7 @@ func (z Object) WithACLUserList(acl map[string][]policy.Action) Object {
|
||||
Type: z.Type,
|
||||
ACLUserList: acl,
|
||||
ACLGroupList: z.ACLGroupList,
|
||||
AnyOrgOwner: z.AnyOrgOwner,
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,5 +210,6 @@ func (z Object) WithGroupACL(groups map[string][]policy.Action) Object {
|
||||
Type: z.Type,
|
||||
ACLUserList: z.ACLUserList,
|
||||
ACLGroupList: groups,
|
||||
AnyOrgOwner: z.AnyOrgOwner,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user