Example #1
0
        public IActionResult AddUserRoles([FromBody] AddUserRolesModel model)
        {
            if (model.UserId.IsEmpty() || model.RoleId.IsEmpty())
            {
                return(NotSpecifiedRecord());
            }
            var userRoles       = new List <SystemUserRoles>();
            var existsUserRoles = _systemUserRolesService.Query(x => x.Where(f => f.SystemUserId.In(model.UserId) && f.RoleId.In(model.RoleId)));

            foreach (var uid in model.UserId)
            {
                foreach (var rid in model.RoleId)
                {
                    if (existsUserRoles.Exists(x => x.RoleId == rid && x.SystemUserId == uid))
                    {
                        continue;
                    }
                    var entity = new SystemUserRoles
                    {
                        SystemUserId     = uid,
                        RoleId           = rid,
                        SystemUserRoleId = Guid.NewGuid()
                    };
                    userRoles.Add(entity);
                }
            }
            if (userRoles.NotEmpty())
            {
                _systemUserRolesService.CreateMany(userRoles);
            }
            return(SaveSuccess());
        }
Example #2
0
        private void BindUserEntityPermissions(QueryExpression query)
        {
            if (this._user != null)
            {
                if (!this._user.IsSuperAdmin && this._user.Roles.IsEmpty())
                {
                    this._user.Roles = _systemUserRolesService.Query(n => n.Where(f => f.SystemUserId == this._user.SystemUserId));
                }
            }

            if (this._user != null && !this._user.IsSuperAdmin && this._user.Roles.NotEmpty())
            {
                var roles    = this._user.Roles.Select(r => r.RoleId);
                var entities = query.GetAllEntityNames();
                var entIds   = _entityFinder.FindByNames(entities.ToArray()).Select(n => n.EntityId);
                this._user.RoleObjectAccessEntityPermission = _roleObjectAccessEntityPermissionService.GetPermissions(entIds, roles, AccessRightValue.Read);
            }
        }
Example #3
0
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="fetch">查询参数</param>
        /// <param name="wrapOptionName">是否包含选项名称</param>
        /// <returns></returns>
        public PagedList <dynamic> Execute(FetchDescriptor fetch, bool wrapOptionName = false)
        {
            //bool hasChange = false;
            GetMetaDatas(fetch);
            if (fetch.User != null)
            {
                if (!fetch.User.IsSuperAdmin && fetch.User.Roles.IsEmpty())
                {
                    fetch.User.Roles = _systemUserRolesService.Query(n => n.Where(f => f.SystemUserId == fetch.User.SystemUserId));
                }
                this.User.Roles = fetch.User.Roles;
            }

            if (fetch.User != null && !fetch.User.IsSuperAdmin && fetch.User.Roles.NotEmpty())
            {
                var roles    = fetch.User.Roles.Select(r => r.RoleId);
                var entities = this.QueryExpression.GetAllEntityNames();
                var entIds   = _entityFinder.FindByNames(entities.ToArray()).Select(n => n.EntityId);
                fetch.User.RoleObjectAccessEntityPermission = _roleObjectAccessEntityPermissionService.GetPermissions(entIds, roles, AccessRightValue.Read);
                this.User.RoleObjectAccessEntityPermission  = fetch.User.RoleObjectAccessEntityPermission;
            }
            //this.User.UserName = "******";
            //this.SetRetrieveConditions(this.User, this.QueryExpression);

            if (fetch.Keyword.IsNotEmpty())
            {
                if (this.QueryExpression.Criteria == null || (this.QueryExpression.Criteria.Conditions.IsEmpty() && this.QueryExpression.Criteria.Filters.IsEmpty()))
                {
                    this.QueryExpression.Criteria = new FilterExpression(LogicalOperator.And);
                }
                else
                {
                    this.QueryExpression.Criteria.FilterOperator = LogicalOperator.And;
                }
                if (fetch.Field.IsNotEmpty())
                {
                    MakeFilterByKeyword(this.QueryExpression, fetch.Keyword, fetch.Field);
                }
                else
                {
                    MakeFilterByKeyword(this.QueryExpression, fetch.Keyword);
                }
                //hasChange = true;
            }
            //过滤
            if (fetch.Filter != null && (fetch.Filter.Filters.Count > 0 || fetch.Filter.Conditions.Count > 0))
            {
                this.QueryExpression.Criteria.AddFilter(fetch.Filter);
                //hasChange = true;
            }
            //排序
            if (fetch.Sort != null)
            {
                //重置排序
                this.QueryExpression.Orders.Clear();
                this.QueryExpression.AddOrder(fetch.Sort.Name, fetch.Sort.SortAscending ? OrderType.Ascending : OrderType.Descending);
                //hasChange = true;
            }
            //无指定排序时,默认第一列
            if (this.QueryExpression.Orders.IsEmpty())
            {
                if (this.QueryResolver.AttributeList.Exists(n => n.Name.IsCaseInsensitiveEqual("createdon")))
                {
                    this.QueryExpression.AddOrder("createdon", OrderType.Descending);
                }
                else
                {
                    this.QueryExpression.AddOrder(this.QueryExpression.ColumnSet.Columns.First(), OrderType.Descending);
                }
                //hasChange = true;
            }

            PagedList <dynamic> result = new PagedList <dynamic>();

            if (fetch.GetAll)
            {
                var data = this.QueryResolver.Query(noneReadFields: NonePermissionFields);
                result.Items = data;
            }
            else
            {
                result = this.QueryResolver.QueryPaged(noneReadFields: NonePermissionFields);
            }
            if (wrapOptionName)
            {
                result.Items = WrapOptionName(result.Items);
            }

            return(result);
        }