Permissions in KAFE

An Account or a Role can have any of the following permissions:

Permissions with the dagger symbol (†) are inheritable -- have effects on the entity's descendants -- the others concern only the entity itself.

# Explicit and inherited permissions

Permissions can be either explicit for a specific entity or trickle down from its ancestors:

system
- authors
- accounts
- organizations
    - playlists
    - roles
    - project groups
        - projects
            - artifacts
                - shards

# EntityPermissionInfo

Complete descriptions of who has which permissions for an entity with specific Id and how they got 'em.

Parents

Direct parent entities whose permissions affect the described entity. It is important when the entity is reparented.

Grantors

All transitive parent entities whose permissions affect the described entity. For example, if this entity is a project, Grantors are the parent project group, the organization, and system. It is important when propagating changes from parents to all of their descendants.

# EntityPermissionEventProjection

The core of the KAFE's permission system. Creates and changes EntityPermissionInfo documents. Each subset of events has specific effects:

# Entity creation events

OrganizationCreated (OrganizationId,    ...)
ProjectGroupCreated (ProjectGroupId,    ...)
ProjectCreated      (ProjectId,         ...)
PlaylistCreated     (PlaylistId,        ...)
AuthorCreated       (AuthorId,          ...)
ArtifactCreated     (ArtifactId,        ...)
AccountCreated      (AccountId,         ...)
RoleCreated         (RoleId,            ...)

When any of the events above is recorded, a new EntityPermissionInfo is created. Those accounts with inheritable permission to any ancestor entity (or system) are given those inheritable permissions to this entity as well.

# Explicit Account or Role permissions

AccountPermissionSet    (AccountId, EntityId, Permission);
RolePermissionSet       (RoleId,    EntityId, Permission);

When any of the events above is recorded, a new explicit Permission is assigned to EntityPermissionInfo for EntityId for the specified AccountId or RoleId. If Permission (or any of its flags) is inheritable it is spread (using the list of grantors) to all descendant entities of EntityId. With role permission changes, EntityPermissionInfo gains an entry for the role and an entry for each member of that role.

# Global permission changes

ProjectGroupGlobalPermissionsChanged    (ProjectGroupId,    GlobalPermissions)
ProjectGlobalPermissionsChanged         (ProjectId,         GlobalPermissions)
PlaylistGlobalPermissionsChanged        (PlaylistId,        GlobalPermissions)

Project groups, projects, and playlist can have global permissions. These permissions apply to all users with accounts and also anonymous users. They are limited to Permission.Publishable which includes Read, Inspect, and Append. These perms are not recorded as entries but are instead saved into a special GlobalPermission property that must be added to any explicit or inherited account or role permissions.

# Role assignments

AccountRoleSet      (AccountId, RoleId)
AccountRoleUnset    (AccountId, RoleId)

# Moves