public virtual bool IsUserHasAccess(IIntranetUser user, Enum activityType, IntranetActivityActionEnum action, Guid?activityId = null)
        {
            if (user == null)
            {
                return(false);
            }

            if (IsUserWebmaster(user))
            {
                return(true);
            }

            var permission         = $"{activityType.ToString()}{action}";
            var userHasPermissions = IsRoleHasPermissions(user.Role, permission);

            if (userHasPermissions && activityId.HasValue)
            {
                var service  = _activitiesServiceFactory.GetService <IIntranetActivityService <IIntranetActivity> >(activityType);
                var activity = service.Get(activityId.Value);

                if (activity is IHaveOwner owner)
                {
                    return(owner.OwnerId == user.Id);
                }
            }

            return(userHasPermissions);
        }
        public virtual bool IsCurrentUserHasAccess(Enum activityType, IntranetActivityActionEnum action, Guid?activityId = null)
        {
            var currentUser = _intranetUserService.GetCurrentUser();

            if (currentUser == null)
            {
                return(false);
            }

            var result = IsUserHasAccess(currentUser, activityType, action, activityId);

            return(result);
        }
示例#3
0
        private bool CanPerform(IIntranetActivity cached, IntranetActivityActionEnum action)
        {
            var currentUser = _intranetUserService.GetCurrentUser();

            var isWebmaster = _permissionsService.IsUserWebmaster(currentUser);

            if (isWebmaster)
            {
                return(true);
            }

            var ownerId = Get(cached.Id).OwnerId;
            var isOwner = ownerId == currentUser.Id;

            var isUserHasPermissions = _permissionsService.IsRoleHasPermissions(currentUser.Role, Type, action);

            return(isOwner && isUserHasPermissions);
        }
 public RestrictedActionAttribute(int activityTypeId, IntranetActivityActionEnum action)
 {
     _activityTypeId = activityTypeId;
     _action         = action;
 }
        public static bool IsRoleHasPermissions(this IPermissionsService service, IRole role, Enum activityType, IntranetActivityActionEnum action)
        {
            var permission = service.GetPermissionFromTypeAndAction(activityType, action);

            return(service.IsRoleHasPermissions(role, permission));
        }
示例#6
0
        protected virtual IEnumerable <IIntranetUser> GetUsersWithAccess(Enum activityType, IntranetActivityActionEnum action)
        {
            var result = _intranetUserService
                         .GetAll()
                         .Where(user => _permissionsService.IsUserHasAccess(user, activityType, action))
                         .OrderBy(user => user.DisplayedName);

            return(result);
        }
 public GroupRestrictedActionAttribute(IntranetActivityActionEnum action)
 {
     _action = action;
 }
        public bool HasPermission(IRole role, IntranetActivityActionEnum action)
        {
            var hasPermission = _permissionsService.IsRoleHasPermissions(role, $"Group{action}");

            return(hasPermission);
        }
 public virtual string GetPermissionFromTypeAndAction(Enum activityType, IntranetActivityActionEnum action)
 {
     return($"{activityType.ToString()}{action}");
 }
 public ContentRestrictedActionAttribute(Enum activityType, IntranetActivityActionEnum action)
 {
     _activityType = activityType;
     _action       = action;
 }