コード例 #1
0
ファイル: RoleController.cs プロジェクト: zzdxpq007/xms
        public IActionResult SaveRolePermissions([FromBody] EditRolePermissionsModel model)
        {
            var resourceOwner = _resourceOwnerService.FindByName(model.ResourceName);

            if (resourceOwner == null)
            {
                return(NotFound());
            }
            var Role = _roleService.FindById(model.RoleId);

            if (Role.Name.IsCaseInsensitiveEqual(RoleDefaults.ADMINISTRATOR))
            {
                return(JError(T["notallow_edit"]));
            }
            if (ModelState.IsValid)
            {
                _roleObjectAccessService.DeleteByRole(model.RoleId, resourceOwner.ModuleName);
                if (model.ObjectId.NotEmpty())
                {
                    List <RoleObjectAccess> roleObjectAccess = new List <RoleObjectAccess>();
                    var objectTypeCode = Module.Core.ModuleCollection.GetIdentity(resourceOwner.ModuleName);
                    int i = 0;
                    foreach (var item in model.ObjectId)
                    {
                        var roa = new RoleObjectAccess
                        {
                            RoleObjectAccessId = Guid.NewGuid(),
                            RoleId             = model.RoleId,
                            ObjectId           = item,
                            ObjectTypeCode     = objectTypeCode
                        };
                        if (model.Mask == null)
                        {
                            roa.AccessRightsMask = 1;
                        }
                        else if (model.Mask != null && model.Mask[i] > 0)
                        {
                            roa.AccessRightsMask = (int)model.Mask[i];
                        }
                        if (roa.AccessRightsMask > 0 && !roleObjectAccess.Exists(x => x.ObjectId == item && x.ObjectTypeCode == objectTypeCode))
                        {
                            roleObjectAccess.Add(roa);
                        }
                        i++;
                    }

                    if (roleObjectAccess.NotEmpty())
                    {
                        _roleObjectAccessService.CreateMany(roleObjectAccess);
                    }
                }
                return(SaveSuccess());
            }
            return(SaveFailure(GetModelErrors()));
        }
コード例 #2
0
        public bool CreateMany(string objectTypeName, Guid objectId, params Guid[] roleId)
        {
            Guard.NotEmpty(roleId, nameof(roleId));
            List <RoleObjectAccess> accessList = new List <RoleObjectAccess>();

            foreach (var rid in roleId)
            {
                var ar = new RoleObjectAccess
                {
                    ObjectId       = objectId,
                    ObjectTypeCode = ModuleCollection.GetIdentity(objectTypeName),
                    RoleId         = rid
                };
                accessList.Add(ar);
            }
            return(_roleObjectAccessRepository.CreateMany(accessList));
        }
コード例 #3
0
 public bool Update(RoleObjectAccess entity)
 {
     return(_roleObjectAccessRepository.Update(entity));
 }