public UserRoleDto[] Execute(GetRolesByUserQuery dataQuery)
        {
            // can view only own roles list
            if (dataQuery.UserId != _userPrincipal.Info.Id)
            {
                throw new UnauthorizedAccessException();
            }

            var user = _userProvider.Get(dataQuery.UserId);

            var roles = _userRoleProvider.GetUserRoles(user);

            var userroles = roles
                            .Select(new RoleRenderer().GetSpec())
                            .ToArray();

            foreach (var userRole in userroles)
            {
                var groupInfo = _solutionGroupManager.GetBySid(userRole.Sid);

                userRole.GroupName = groupInfo.GroupName;
            }

            return(userroles);
        }
Beispiel #2
0
        public UserRoleDto[] Execute([NotNull] GetRolesByProjectQuery dataQuery)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException(nameof(dataQuery));
            }

            if (!_userAuthorityValidator.HasUserAuthorities(
                    _userPrincipal.Info.Id,
                    new[]
            {
                Authorities.UI.Project.Settings.ViewAccessControl
            },
                    dataQuery.ProjectId))
            {
                throw new UnauthorizedAccessException();
            }

            var roles = _roleProvider.Get(dataQuery.ProjectId);

            var spec = new RoleRenderer().GetSpec();

            var userRolesDto = roles.Select(_ => spec.Invoke(_)).ToArray();

            foreach (var userRole in userRolesDto)
            {
                var groupInfo = _solutionGroupManager.GetBySid(userRole.Sid);

                userRole.GroupName = groupInfo.GroupName;
            }

            return(userRolesDto.ToArray());
        }