示例#1
0
        public void Update()
        {
            var permissionId = this.Fixture.Get <Permission>().Id;

            {
                this.BeginTransaction();

                var cmd = new UpdatePermission(permissionId)
                {
                    Description = "编辑描述",
                    MarkedCode  = "addArticle"
                };
                var permission = cmd.Execute();
                this.Commit();
            }

            {
                this.BeginTransaction();

                var permission = PermissionCommon.FindByMarkedCode("addArticle", QueryLevel.None);
                Assert.AreEqual("发布文章", permission.Name);
                Assert.AreEqual("编辑描述", permission.Description);
                Assert.AreEqual("addArticle", permission.MarkedCode);

                this.Commit();
            }
        }
示例#2
0
        //update Permission

        public async Task UpdatePermission1(UpdatePermission result)
        {
            using var cmd   = Db.Connection.CreateCommand();
            cmd.CommandText = @"update db_final.permission SET db_final.permission.permission_name=@permission_name where permission_id = @id;";
            BindId9(cmd, result.id, result.permission_name);

            await cmd.ExecuteNonQueryAsync();
        }
示例#3
0
        public async Task <PermissionResponse> Update(UpdatePermission request)
        {
            var requestDataAccess = _mapper.Map <PermissionAccess>(request);
            var entity            = await _permissionDataAccess.UpdateAsync(requestDataAccess);

            var response = _mapper.Map <PermissionResponse>(entity);

            return(response);
        }
示例#4
0
        async public Task <IActionResult> Putpermission(int id, [FromBody] UpdatePermission body)
        {
            Db.Connection.Open();
            var query = new updatepermission(Db);

            body.id = id;
            await query.updatePermission(body);

            Db.Connection.Close();
            return(Ok());
        }
示例#5
0
 /// <summary>更新权限
 /// </summary>
 public void Handle(ICommandContext context, UpdatePermission command)
 {
     _lockService.ExecuteInLock(typeof(Permission).Name, () =>
     {
         _permissionService.Exist(command.ParentPermission);
         var info = new PermissionEditableInfo(
             command.Name,
             command.PermissionType,
             command.ParentPermission,
             command.PermissionUrl,
             command.Sort,
             command.Describe,
             command.ReMark);
         context.Get <Permission>(command.AggregateRootId).Update(info);
     });
 }
示例#6
0
        private async Task UpdateSinglePermissionUpdate(
            string originatingUserId,
            EfEnums.GuildProfilePermissionLevel activeLevel,
            UpdatePermission newPermission,
            UserWithData targetUser,
            int profileId,
            bool isAdmin)
        {
            int newPermissionOrder        = PermissionsOrder.Order((EfEnums.GuildProfilePermissionLevel)newPermission.NewPermissionLevel);
            int activeUserPermissionOrder = PermissionsOrder.Order(activeLevel);

            if (originatingUserId == targetUser.Id)
            {
                throw new UserReportableError($"User may not modify their own permissions.", (int)HttpStatusCode.BadRequest);
            }

            var targetUserLevel = await this.GetProfilePermissionForUserAsync(profileId, targetUser.Id);

            if (targetUserLevel == null)
            {
                throw new UserReportableError($"User {targetUser.Id} has not requested access!", (int)HttpStatusCode.BadRequest);
            }

            if (!isAdmin)
            {
                int targetUserOrder = PermissionsOrder.Order(targetUserLevel.Value);

                if (newPermissionOrder > PermissionsOrder.Order(activeLevel))
                {
                    throw new UserReportableError("User can't adjust permissions beyond their own level.", (int)HttpStatusCode.BadRequest);
                }

                if (PermissionsOrder.Order(activeLevel) < PermissionsOrder.Order(targetUserLevel.Value))
                {
                    throw new UserReportableError($"Can't adjust permissions on user with a higher permission level.",
                                                  (int)HttpStatusCode.BadRequest);
                }
            }

            var targetPermission = await this.context.User_GuildProfilePermissions.FirstOrDefaultAsync(
                x => x.ProfileId == profileId && x.UserId == targetUser.Id);

            targetPermission.PermissionLevelId = newPermission.NewPermissionLevel;

            await this.context.SaveChangesAsync();
        }
示例#7
0
 private async Task UpdateSinglePermission(
     string originatingUserId,
     EfEnums.GuildProfilePermissionLevel activeLevel,
     UpdatePermission newPermission,
     UserWithData targetUser,
     int profileId,
     bool isAdmin)
 {
     if (newPermission.Delete)
     {
         await this.UpdateSinglePermissionDelete(originatingUserId, activeLevel, targetUser, profileId, isAdmin);
     }
     else
     {
         await this.UpdateSinglePermissionUpdate(originatingUserId, activeLevel, newPermission, targetUser, profileId, isAdmin);
     }
 }
示例#8
0
        // PUT: api/Permission/5  Update permission
        public async Task <HandleResult> Put(string id, [FromBody] UpdatePermissionDto dto)
        {
            var command = new UpdatePermission(id,
                                               dto.Name,
                                               dto.PermissionType,
                                               dto.ParentPermission,
                                               dto.PermissionUrl,
                                               dto.Sort,
                                               dto.Describe,
                                               dto.ReMark);
            var result = await ExecuteCommandAsync(command);

            if (result.IsSuccess())
            {
                return(HandleResult.FromSuccess("更新成功"));
            }
            return(HandleResult.FromFail(result.GetErrorMessage()));
        }
示例#9
0
        public async Task <List <UpdatePermission> > ReadAllPermissionById(DbDataReader reader)
        {
            var posts = new List <UpdatePermission>();  // create an array of blogpost

            using (reader)
            {
                while (await reader.ReadAsync())
                {
                    var post = new UpdatePermission()
                    {
                        id = reader.GetInt32(0),
                        permission_name = reader.GetString(1),
                    };
                    posts.Add(post);
                }
            }
            return(posts);
        }