public static async Task <IEnumerable <AbstractPermission> > GenericPermissionsFromCache(
            this IPermissionsCache cache,
            int tenantId,
            int userId,
            string version,
            string viewPrefix,
            string action,
            CancellationToken cancellation)
        {
            var permissions = (await cache.GetPermissionss(userId, tenantId, version, cancellation)).Data.Permissions;

            // Apply view filter
            permissions = permissions.Where(e => e.View.StartsWith(viewPrefix) || e.View == "all");

            // Apply action filter (read action is implicity in all
            if (action != PermissionActions.Read)
            {
                permissions = permissions.Where(e => e.Action == action || e.Action == "All");
            }

            // Return
            return(permissions.Select(p => new AbstractPermission
            {
                Action = p.Action,
                Criteria = p.Criteria,
                Mask = null,
                View = p.View
            }));
        }
Exemplo n.º 2
0
        public async Task <Versioned <PermissionsForClient> > PermissionsForClient(CancellationToken cancellation)
        {
            await Initialize(cancellation);

            return(await _permissionsCache.GetPermissionss(UserId, _behavior.TenantId, _behavior.PermissionsVersion, cancellation));
        }