Exemplo n.º 1
0
        public async Task <IActionResult> FindRolesAsync([FromRoute] Guid scopeId)
        {
            List <Role> roles;

            if (this.UserHasScope(ScopeScopes.Admin))
            {
                roles = await _getRolesService.GetByScopeIdAsync(scopeId);
            }
            else
            {
                roles = await _getRolesService.GetByScopeIdAsync(scopeId, this.GetUserId());
            }

            var found = roles.Select(r => RoleResponseDto.FromRole(r, false));

            return(Ok(found));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DeleteRoleRelationAsync([FromRoute] Guid userId, [FromRoute] Guid roleId)
        {
            List <Role> roles;

            if (this.UserHasScope(UserScopes.Admin) || userId == this.GetUserId())
            {
                roles = await _deleteUserRoleRelationService.DeleteRoleRelationAsync(userId, roleId);
            }
            else
            {
                throw new ForbiddenException();
            }

            var remaining = roles.Select(r => RoleResponseDto.FromRole(r, false));

            return(Ok(remaining));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetRolesAsync([FromRoute] Guid userId)
        {
            List <Role> roles;

            if (this.UserHasScope(UserScopes.Admin) || userId == this.GetUserId())
            {
                roles = await _getRolesService.GetByUserIdAsync(userId);
            }
            else
            {
                throw new ForbiddenException();
            }

            var found = roles.Select(a => RoleResponseDto.FromRole(a, false));

            return(Ok(found));
        }
Exemplo n.º 4
0
        public static ScopeResponseDto FromScope(Scope scope, bool includeChildren)
        {
            var dto = new ScopeResponseDto
            {
                scope_id       = scope.ScopeId,
                name           = scope.Name,
                description    = scope.Description,
                application_id = scope.ApplicationId,
                created_date   = scope.CreatedDateTime,
                modified_date  = scope.ModifiedDateTime
            };

            if (includeChildren)
            {
                dto.roles = scope.Roles?.Select(r =>
                                                RoleResponseDto.FromRole(r, false)).ToList();
            }

            return(dto);
        }
Exemplo n.º 5
0
        public static ApplicationResponseDto FromApplication(Application application, bool includeChildren)
        {
            var dto = new ApplicationResponseDto
            {
                application_id = application.ApplicationId,
                name           = application.Name,
                description    = application.Description,
                type           = application.Type,
                homepage_uri   = application.HomepageUri,
                redirect_uri   = application.RedirectUri,
                client_id      = application.ClientId,
                user_id        = application.UserId,
                created_date   = application.CreatedDateTime,
                modified_date  = application.ModifiedDateTime
            };

            if (includeChildren)
            {
                dto.roles = application.Roles?.Select(r =>
                                                      RoleResponseDto.FromRole(r, true)).ToList();
            }

            return(dto);
        }