cvat-ai--cvat
240 行
6.0 KiB
Rego
240 行
6.0 KiB
Rego
package projects
|
|
|
|
import rego.v1
|
|
|
|
import data.utils
|
|
import data.organizations
|
|
|
|
# input: {
|
|
# "scope": <
|
|
# "create"|
|
|
# "delete"|
|
|
# "download:exported_file"|
|
|
# "export:annotations"|
|
|
# "export:backup"|
|
|
# "export:dataset"|
|
|
# "import:backup"|
|
|
# "import:dataset"|
|
|
# "list"|
|
|
# "update:assignee"|
|
|
# "update:associated_storage"|
|
|
# "update:desc"|
|
|
# "update:organization"|
|
|
# "update:owner"|
|
|
# "update"|
|
|
# "view"|
|
|
# > or null,
|
|
# "auth": {
|
|
# "user": {
|
|
# "id": <num>,
|
|
# "privilege": <"admin"|"user"|"worker"> or null
|
|
# },
|
|
# "organization": {
|
|
# "id": <num>,
|
|
# "owner": {
|
|
# "id": <num>
|
|
# },
|
|
# "user": {
|
|
# "role": <"owner"|"maintainer"|"supervisor"|"worker"> or null
|
|
# }
|
|
# } or null,
|
|
# },
|
|
# "resource": {
|
|
# "id": <num>,
|
|
# "owner": { "id": <num> },
|
|
# "assignee": { "id": <num> },
|
|
# "organization": { "id": <num> } or null,
|
|
# "rq_job": { "owner": { "id": <num> } } or null,
|
|
# "destination": <"local" | "cloud_storage"> or undefined,
|
|
# }
|
|
# }
|
|
|
|
default allow := false
|
|
|
|
is_project_staff if {
|
|
utils.is_resource_owner
|
|
}
|
|
|
|
is_project_staff if {
|
|
utils.is_resource_assignee
|
|
}
|
|
|
|
allow if {
|
|
utils.is_admin
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.CREATE, utils.IMPORT_BACKUP}
|
|
utils.is_sandbox
|
|
utils.has_perm(utils.USER)
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.CREATE, utils.IMPORT_BACKUP}
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.has_perm(utils.USER)
|
|
organizations.has_perm(organizations.SUPERVISOR)
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.LIST
|
|
utils.is_sandbox
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.LIST
|
|
organizations.is_member
|
|
}
|
|
|
|
base_filter := {} if { # Django Q object to filter list of entries
|
|
utils.is_admin
|
|
} else := qobject if {
|
|
utils.is_sandbox
|
|
user := input.auth.user
|
|
qobject := ["|", {"owner_id": user.id}, {"assignee_id": user.id}]
|
|
} else := {} if {
|
|
utils.is_organization
|
|
utils.has_perm(utils.USER)
|
|
organizations.has_perm(organizations.MAINTAINER)
|
|
} else := qobject if {
|
|
organizations.has_perm(organizations.WORKER)
|
|
user := input.auth.user
|
|
qobject := ["|", {"owner_id": user.id}, {"assignee_id": user.id}]
|
|
}
|
|
|
|
filter := utils.add_organization_filter(base_filter, ["organization"])
|
|
|
|
allow if {
|
|
input.scope == utils.VIEW
|
|
utils.is_sandbox
|
|
is_project_staff
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.VIEW
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.has_perm(utils.USER)
|
|
organizations.has_perm(organizations.MAINTAINER)
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.VIEW
|
|
input.auth.organization.id == input.resource.organization.id
|
|
organizations.has_perm(organizations.WORKER)
|
|
is_project_staff
|
|
}
|
|
|
|
|
|
allow if {
|
|
input.scope in {utils.DELETE, utils.UPDATE_ASSOCIATED_STORAGE}
|
|
utils.is_sandbox
|
|
utils.has_perm(utils.WORKER)
|
|
utils.is_resource_owner
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.DELETE, utils.UPDATE_ASSOCIATED_STORAGE}
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.has_perm(utils.WORKER)
|
|
organizations.is_member
|
|
utils.is_resource_owner
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.DELETE, utils.UPDATE_ASSOCIATED_STORAGE}
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.has_perm(utils.USER)
|
|
organizations.is_staff
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.UPDATE_DESC, utils.IMPORT_DATASET}
|
|
utils.is_sandbox
|
|
is_project_staff
|
|
utils.has_perm(utils.WORKER)
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.UPDATE_DESC, utils.IMPORT_DATASET}
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.has_perm(utils.USER)
|
|
organizations.is_staff
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.UPDATE_DESC, utils.IMPORT_DATASET}
|
|
is_project_staff
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.has_perm(utils.WORKER)
|
|
organizations.is_member
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.UPDATE_ASSIGNEE
|
|
utils.is_sandbox
|
|
utils.is_resource_owner
|
|
utils.has_perm(utils.WORKER)
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.UPDATE_ASSIGNEE
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.is_resource_owner
|
|
utils.has_perm(utils.WORKER)
|
|
organizations.is_member
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.UPDATE_ASSIGNEE
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.has_perm(utils.USER)
|
|
organizations.is_staff
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.UPDATE_OWNER
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.is_resource_owner
|
|
utils.has_perm(utils.WORKER)
|
|
organizations.is_staff
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.UPDATE_OWNER
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.has_perm(utils.USER)
|
|
organizations.is_staff
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.EXPORT_ANNOTATIONS, utils.EXPORT_DATASET, utils.EXPORT_BACKUP}
|
|
utils.is_sandbox
|
|
is_project_staff
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.EXPORT_ANNOTATIONS, utils.EXPORT_DATASET, utils.EXPORT_BACKUP}
|
|
input.auth.organization.id == input.resource.organization.id
|
|
organizations.has_perm(organizations.SUPERVISOR)
|
|
is_project_staff
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.EXPORT_ANNOTATIONS, utils.EXPORT_DATASET, utils.EXPORT_BACKUP}
|
|
input.auth.organization.id == input.resource.organization.id
|
|
organizations.is_member
|
|
utils.is_resource_owner
|
|
}
|
|
|
|
allow if {
|
|
input.scope in {utils.EXPORT_ANNOTATIONS, utils.EXPORT_DATASET, utils.EXPORT_BACKUP}
|
|
input.auth.organization.id == input.resource.organization.id
|
|
utils.has_perm(utils.USER)
|
|
organizations.has_perm(organizations.MAINTAINER)
|
|
}
|
|
|
|
allow if {
|
|
input.scope == utils.DOWNLOAD_EXPORTED_FILE
|
|
input.auth.user.id == input.resource.rq_job.owner.id
|
|
}
|