Ejemplo n.º 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
            [RequestBodyType(typeof(GetUserRolesRequest), "get user roles")] GetUserRolesRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                if (req.IsValid(out var validationResults))
                {
                    GetUserRolesResponse response = await _mediator.Send(req, cancellationToken);

                    return(new OkObjectResult(ResponseWrapper <GetUserRolesResponse, GroupServiceErrorCode> .CreateSuccessfulResponse(response)));
                }
                else
                {
                    return(new ObjectResult(ResponseWrapper <GetUserRolesResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.ValidationError, validationResults))
                    {
                        StatusCode = 422
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogErrorAndNotifyNewRelic($"Unhandled error in GetUserGroups", ex);
                return(new ObjectResult(ResponseWrapper <GetUserRolesResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Ejemplo n.º 2
0
        private IEnumerable <IUserRole> GetRoles()
        {
            GetUserRolesRequest request = new GetUserRolesRequest(Login);

            UserRoleCollection userRoleCollection = connection.Get <UserRoleCollection>(request);

            return(userRoleCollection.UserRoles);
        }
Ejemplo n.º 3
0
        public GetUserRolesResponse Any(GetUserRolesRequest request)
        {
            GetUserRolesResponse resp = new GetUserRolesResponse();

            using (var con = this.TenantDbFactory.ObjectsDB.GetNewConnection())
            {
                con.Open();
                string sql = string.Empty;
                if (request.id > 0)
                {
                    sql = @"SELECT id, role_name, description FROM eb_roles;
                             SELECT id, role_name, description FROM eb_roles WHERE id IN(SELECT role_id FROM eb_role2user WHERE user_id = @id AND eb_del = FALSE)";
                }
                else
                {
                    sql = "SELECT id,role_name, description FROM eb_roles";
                }

                DbParameter[] parameters =
                {
                    this.TenantDbFactory.ObjectsDB.GetNewParameter("id", System.Data.DbType.Int32, request.id)
                };

                var dt = this.TenantDbFactory.ObjectsDB.DoQueries(sql, parameters);

                Dictionary <string, object> returndata = new Dictionary <string, object>();
                List <int> subroles = new List <int>();
                foreach (EbDataRow dr in dt.Tables[0].Rows)
                {
                    List <string> list = new List <string>();
                    list.Add(dr[1].ToString());
                    list.Add(dr[2].ToString());
                    returndata[dr[0].ToString()] = list;
                }

                if (dt.Tables.Count > 1)
                {
                    foreach (EbDataRow dr in dt.Tables[1].Rows)
                    {
                        subroles.Add(Convert.ToInt32(dr[0]));
                    }
                    returndata.Add("roles", subroles);
                }
                resp.Data = returndata;
            }
            return(resp);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Get([FromRoute] GetUserRolesRequest request)
        {
            IActionResult result = null;

            List <UserRole> applications = await Server.GetUserRoles(request.Application);

            if (applications != null)
            {
                result = Factory.CreateSuccessResponse(applications);
            }
            else
            {
                result = Factory.CreateNoContentResponse();
            }

            return(result);
        }
Ejemplo n.º 5
0
        public async Task ShouldGetUserRoles()
        {
            var tester = await setup();

            var adminUser = await tester.AdminUser();

            var hubApp = await tester.HubApp();

            var addUserRole = await hubApp.Role(HubInfo.Roles.AddUser);

            await adminUser.AddRole(addUserRole);

            var defaultModifier = await hubApp.DefaultModifier();

            var request = new GetUserRolesRequest
            {
                UserID     = adminUser.ID.Value,
                ModifierID = defaultModifier.ID.Value
            };
            var roles = await tester.Execute(request, adminUser);

            Assert.That(roles.Select(r => r.Name), Has.One.EqualTo(HubInfo.Roles.AddUser.Value), "Should get user roles");
        }
Ejemplo n.º 6
0
 public Task <ResultContainer <AppRoleModel[]> > GetUserRoles([FromBody] GetUserRolesRequest model)
 {
     return(api.Group("AppUser").Action <GetUserRolesRequest, AppRoleModel[]>("GetUserRoles").Execute(model));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// The get user roles.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The Get user roles response collection.
        /// </returns>
        public List<GetUserRolesResponse> GetUserRoles(GetUserRolesRequest request)
        {
            var user = this.userRepository.GetUserByEmail(request.IdentityToken);
            if (user != null)
            {
                if (user.Roles != null)
                {
                    return user.Roles.ConvertToGetUserRolesResponseCollection();
                }
            }

            return new List<GetUserRolesResponse>();
        }
Ejemplo n.º 8
0
 public GetUserRolesResponse GetUserRoles(GetUserRolesRequest request)
 {
     return(Execute <GetUserRolesRequest, GetUserRolesResponse>(
                request,
                response => response.List = _userFacade.GetUserRoles(request.UserId)));
 }