Exemplo n.º 1
0
        public async Task <HttpResponseMessage> ModifyPermission([FromBody] PermissionModel model)
        {
            var user = GetSessionUser(Request.Headers.GetCookies().FirstOrDefault());

            try
            {
                Guid NodeId        = Guid.Empty;
                var  currentEntity = await MyCoreApi.FindNodeByIdAsync(model.nodeid);

                if (currentEntity != null)
                {
                    NodeId = currentEntity.Id;
                }
                if (!await MyCoreApi.Authorization(NodeId, user, "1"))
                {
                    throw new Exception("Not authorization!");
                }
                currentEntity.SetUser(model.user);
                currentEntity.QueryToParentPermission = model.inherit;
                currentEntity.OthersPermission        = model.others;
                currentEntity.GroupPermission.Clear();
                foreach (var item in model.groups)
                {
                    var index = item.IndexOf(":::");
                    if (index < 0)
                    {
                        return(new HttpResponseMessage(HttpStatusCode.Forbidden));
                    }
                    var key   = item.Substring(0, index);
                    var value = item.Substring(index + 3);
                    if (key.Equals("") || value.Equals(""))
                    {
                        return(new HttpResponseMessage(HttpStatusCode.Forbidden));
                    }
                    currentEntity.GroupPermission.Add(key, value);
                }
                await MyCoreApi.CoreService.SaveAsync(currentEntity);

                return(new HttpResponseMessage(HttpStatusCode.OK));
            } catch (Exception e)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(e.Message)
                });
            }
        }
Exemplo n.º 2
0
 public ActionResult <PermissionModel> GetPermissionDetailById(string permissionUid)
 {
     try
     {
         using (var permissionService = new PermissionService())
         {
             PermissionModel permissionObject = permissionService.GetPermissionDetailById(permissionUid);
             if (permissionObject != null)
             {
                 using (var userService = new UserServices())
                 {
                     permissionObject.Role_List = userService.GetUserRoleList();
                 }
             }
             return(permissionObject);
         }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message, null);
         return(BadRequest(ex.Message));
     }
 }