Example #1
0
        public GetRolesResponse GetRoles(GetRolesRequest request)
        {
            Logger.Current.Verbose("Request to fetch Roles of an Account");
            GetRolesResponse response = new GetRolesResponse();

            if (request != null)
            {
                IEnumerable <RoleViewModel> roleViewModel;
                Logger.Current.Informational("Requested roles for AccountId : " + request.AccountId);
                IEnumerable <Role> roles = roleRepository.GetRoles(request.AccountId);
                if (roles != null)
                {
                    roleViewModel = Mapper.Map <IEnumerable <Role>, IEnumerable <RoleViewModel> >(roles);
                    if (roleViewModel != null)
                    {
                        response.RoleViewModel  = roleViewModel;
                        response.SubscriptionId = accountRepository.GetSubscriptionIdByAccountId(request.AccountId);
                    }
                }
                else
                {
                    response.RoleViewModel = null;
                }
            }
            return(response);
        }
Example #2
0
        public ActionResult RolesViewRead([DataSourceRequest] DataSourceRequest request, string name)
        {
            AddCookie("leadscorepagesize", request.PageSize.ToString(), 1);
            AddCookie("leadscorepagenumber", request.Page.ToString(), 1);
            GetRolesResponse response = roleService.GetRolesList(new GetRolesRequest()
            {
                Query = name,
                Limit = request.PageSize,
                PageNumber = request.Page,
                AccountId = UserExtensions.ToAccountID(this.Identity)
            });
            if (!this.Identity.IsSTAdmin())
            {
                if(response.SubscriptionId == 2)
                    response.RoleViewModel = response.RoleViewModel.Where(s => s.RoleName != "Account Administrator");
                else
                    response.RoleViewModel = response.RoleViewModel.Where(s => s.RoleName != "Account Administrator" && s.RoleName != "Marketing Administrator" && s.RoleName != "Sales Administrator" && s.RoleName != "Marketing");

            }
            

            int count = response.RoleViewModel.Count();
            return Json(new DataSourceResult
            {
                Data = response.RoleViewModel,
                Total = count
            }, JsonRequestBehavior.AllowGet);
        }
Example #3
0
        public void CanGetUserRolesOnNewAccount()
        {
            String username = "******";
            String password = "******";

            AccountRegistrationRequest request = new AccountRegistrationRequest()
            {
                Email    = "*****@*****.**",
                Password = password,
                Username = username,
            };

            AccountRegistrationResponse response = client.RegisterAccount(request);

            Assert.IsTrue(response.Token != null);
            Assert.IsTrue(response.User.Id != null);
            Assert.AreEqual(response.User.Username, username);

            GetRolesResponse roleResponse = client.GetRoles(new GetRolesRequest()
            {
            });

            Assert.IsTrue(roleResponse.Status.IsSuccess);
            Assert.IsTrue(roleResponse.Claims.Contains(UserClaim.User));
            Assert.IsFalse(roleResponse.Claims.Contains(UserClaim.Admin));
        }
        public async Task <GetRolesResponse> GetRoles()
        {
            var response = new GetRolesResponse
            {
                Roles = await _cache.Roles()
            };

            return(response);
        }
Example #5
0
        public GetRolesResponse GetRolesByCriteria(GetRolesRequest request)
        {
            GetRolesResponse          response = new GetRolesResponse();
            SecurityBusinessComponent bc       = DependencyInjectionHelper.GetSecurityBusinessComponent();

            IQueryable <Role> roles = bc.GetRolesByCriteria(request.SearchType, request.Rolename);

            response.Roles = SecurityAdapter.RolesToDTOs(roles);

            return(response);
        }
Example #6
0
        public ActionResult AddRolePermissions(short roleId)
        {
            RolePermissionsViewModel viewModel = new RolePermissionsViewModel();
            GetRolesResponse rolesResponse = roleService.GetRoles(new GetRolesRequest()
            {
                AccountId = this.Identity.ToAccountID()
            });
            if (rolesResponse != null && !rolesResponse.RoleViewModel.Any(r => r.RoleId == roleId))
                return RedirectToAction("NotFound", "Error");
            GetModulesResponse modulesResponse = roleService.GetModules(new GetModulesRequest()
            {
                AccountID = this.Identity.ToAccountID()
            });
            if (!this.Identity.IsSTAdmin())
            {
                if(rolesResponse.SubscriptionId == 2)
                    rolesResponse.RoleViewModel = rolesResponse.RoleViewModel.Where(s => s.RoleName != "Account Administrator");
                else
                    rolesResponse.RoleViewModel = rolesResponse.RoleViewModel.Where(s => s.RoleName != "Account Administrator" && s.RoleName != "Marketing Administrator" && s.RoleName != "Sales Administrator" && s.RoleName != "Marketing");


                modulesResponse.ModuleViewModel = modulesResponse.ModuleViewModel.Where(s => s.ModuleId != (byte)AppModules.AccountSettings);
            }
            viewModel.Modules = modulesResponse.ModuleViewModel;
            viewModel.Roles = rolesResponse.RoleViewModel;
            GetModulesForRoleResponse response = roleService.GetModulesForRole(new GetModulesForRoleRequest()
            {
                roleId = roleId
            });
            foreach (var item in response.moduleIds)
            {
                foreach (var module in viewModel.Modules)
                {
                    if (module.ModuleId == item)
                    {
                        module.IsSelected = true;
                    }
                    if (module.SubModules != null)
                    {
                        foreach (var submodule in module.SubModules)
                        {
                            if (submodule.ModuleId == item)
                            {
                                submodule.IsSelected = true;
                            }
                        }
                    }
                }
            }
            viewModel.SelectedRole = roleId;
            return View("RolePermissions", viewModel);
        }
Example #7
0
        public GetRolesResponse GetRoles()
        {
            var response = new GetRolesResponse();

            try
            {
                response.RolViewModel = RolMapper.ConvertToRolViewModel(_rolRepository.GetByCriteria(x => x.IsActivo));
                response.IsValid      = true;
            }
            catch (Exception ex)
            {
                response.IsValid      = false;
                response.ErrorMessage = ex.Message;
            }

            return(response);
        }
Example #8
0
        public async Task <GetRolesResponse> GetRoles()
        {
            var response = new GetRolesResponse();

            try
            {
                var roles = _mapper.Map <List <Roles>, List <Role> >(await _rolesContext.Roles.ToListAsync());

                response.RolesList         = roles;
                response.OperationSucceded = true;
            }
            catch (Exception)
            {
                response.OperationSucceded = false;
            }

            return(response);
        }
Example #9
0
        public void SuperUserAccountHasAdminClaimsFromRolesEndpoint()
        {
            SuperUser superUser = DbUserModel.CreateSuperUser().Result;

            client.Login(new AuthorizationRequest()
            {
                Password = superUser.password,
                Username = superUser.DbUserModel.UserModel.Username
            });

            GetRolesResponse roleResponse = client.GetRoles(new GetRolesRequest()
            {
            });

            Assert.IsTrue(roleResponse.Status.IsSuccess);
            Assert.IsTrue(roleResponse.Claims.Contains(UserClaim.User));
            Assert.IsTrue(roleResponse.Claims.Contains(UserClaim.Admin));
        }
Example #10
0
        public GetRolesResponse Any(GetRolesRequest request)
        {
            GetRolesResponse resp = new GetRolesResponse();

            using (var con = this.TenantDbFactory.ObjectsDB.GetNewConnection())
            {
                con.Open();
                string sql = "SELECT id,role_name FROM eb_roles";
                var    dt  = this.TenantDbFactory.ObjectsDB.DoQueries(sql);

                Dictionary <string, object> returndata = new Dictionary <string, object>();
                foreach (EbDataRow dr in dt.Tables[0].Rows)
                {
                    returndata[dr[0].ToString()] = dr[1].ToString();
                }
                resp.Data = returndata;
            }
            return(resp);
        }
        public override Task <GetRolesResponse> GetRoles(GetRolesRequest request, ServerCallContext context)
        {
            DbUserModel dbUserModel = context.UserState["user"] as DbUserModel;

            if (dbUserModel == null)
            {
                return(Task.FromResult(new GetRolesResponse()
                {
                    Status = ResponseFactory.createResponse(ResponseType.UNAUTHORIZED)
                }));
            }

            var response = new GetRolesResponse()
            {
                Status = ResponseFactory.createResponse(ResponseType.SUCCESS)
            };

            response.Claims.AddRange(dbUserModel.UserModel.Claims);
            return(Task.FromResult(response));
        }
 private IList <RoleDTO> getRoles(RoleSearchType searchType, string name, string role)
 {
     try
     {
         GetRolesRequest request = new GetRolesRequest();
         request.SearchType = searchType;
         request.Rolename   = name;
         request.Rolename   = role;
         GetRolesResponse response = Service.GetRolesByCriteria(request);
         return(response.Roles);
     }
     catch (Exception ex)
     {
         if (ExceptionPolicy.HandleException(ex, "PL Policy"))
         {
             throw;
         }
         return(new List <RoleDTO>());
     }
 }
Example #13
0
        public GetRolesResponse GetRolesList(GetRolesRequest request)
        {
            Logger.Current.Verbose("Request to fetch Roles of an Account");
            GetRolesResponse   response = new GetRolesResponse();
            IEnumerable <Role> roles    = roleRepository.FindAll(request.Query, request.Limit, request.PageNumber, request.AccountId);

            if (roles == null)
            {
                response.Exception = GetRoleNotFoundException();
            }
            else
            {
                IEnumerable <RoleViewModel> leadScoreList = Mapper.Map <IEnumerable <Role>, IEnumerable <RoleViewModel> >(roles);
                response.RoleViewModel  = leadScoreList;
                response.TotalHits      = roleRepository.FindAll(request.Query, request.AccountId).Count();
                response.SubscriptionId = accountRepository.GetSubscriptionIdByAccountId(request.AccountId);
            }

            return(response);
        }
Example #14
0
        public GetRolesResponse GetRoles(DataTableRequest request)
        {
            var response = new GetRolesResponse();

            try
            {
                var query    = FilterString(request.CustomFilters);
                var filtered = query.ApplyColumnSettings(request, RolMapper.GetPropertiePath);

                response.RolViewModel   = filtered.ConvertToRolViewModel();
                response.TotalElementos = query.Count();
                response.IsValid        = true;
            }
            catch (Exception ex)
            {
                response.IsValid      = false;
                response.ErrorMessage = ex.Message;
            }

            return(response);
        }
        public void TestGetRoles()
        {
            int roleId = 1;
            GetRolesResponse response = new GetRolesResponse();

            response.Roles.Add(new RoleDTO()
            {
                Id = roleId, RoleName = "FakeRole"
            });

            Expect.Once.On(service).Method("GetRolesByCriteria").Will(Return.Value(response));
            IList <RoleDTO> roles = serviceFacade.GetRolesByName("FakeRole");

            Assert.AreEqual(1, roles.Count);
            Assert.AreEqual(roles.First().Id, roleId);

            Expect.Once.On(service).Method("GetRolesByCriteria").Will(Return.Value(response));
            roles = serviceFacade.GetAllRoles();
            Assert.AreEqual(1, roles.Count);
            Assert.AreEqual(roles.First().Id, roleId);
        }