Managing Permissions
Managing permissions for Media items is based on the existing permission services for managing and checking access rights. It is possible to set permission not only for a type but also for a specific item. If no permission is set for a specific item, the item's type level is checked instead.
Using API
Use the MediaPermissionService for the following tasks:
-
Checking if the access to a Media item is granted or denied for a given principal:
// Assume you already have the following objects MediaModel media; UserModel user; // Can be for example fetched with userService.getCurrentUser() //Check if given user is permitted to read the given *Media* item boolean isGranted = mediaPermissionService.isReadAccessGranted(media, user);
-
Granting or denying access to a Media item for a given principal.
// Assume you already have the following objects MediaModel media; UserModel user; // Can be for example fetched with userService.getCurrentUser() //Grant the read permission for a user on a given *Media* item mediaPermissionService.grantReadPermission(media, user); //Deny the read permission for a user on a given *Media* item mediaPermissionService.denyReadPermission(media, user);
Using Backoffice
You can grant or deny access to a Media item for a give principal by opening specific Media item and going to Security tab.
Using ImpEx
Below you can find the example of an ImpEx import script for granting access to a Media item with code 1017895.jpg for the editor principal:
INSERT_UPDATE media; code[unique=true]; catalogVersion(catalog(id),version)[unique=true]; permittedPrincipals(uid); ;1017895.jpg; clothescatalog:Staged;editor;