Пример #1
0
        public static async Task <OperationResult> AdjustUserRoleLevel(string adminId, string uid, int rid, int del)
        {
            OperationResult OpResult = new OperationResult();
            var             maxp     = await MemberAdminContext.GetMaxPriority(adminId);

            var cntx = Cntx;
            UserServiceProxy usvc = new UserServiceProxy();
            var u = usvc.LoadEntityByKey(cntx, uid);

            if (u == null)
            {
                OpResult.Result = new { ok = false, msg = string.Format(ResourceUtils.GetString("b66098049404e4de1356242e8aa6444a", "User \"{0}\" is not found."), uid) };
                return(OpResult);
            }
            UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy();
            var uir = await uirsvc.LoadEntityByKeyAsync(cntx, rid, u.ID);

            if (uir == null)
            {
                OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("78257cace857db766d54e6568d7f912b", "The user is not in this role.") };
                return(OpResult);
            }
            uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(cntx, uir);

            if (maxp.Major < uir.RoleRef.RolePriority || maxp.Major == uir.RoleRef.RolePriority && uir.SubPriority + del > maxp.Major)
            {
                OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("5986d63fe301793ee7f5b2134a8f8787", "Modifying more priviledged role is not authorized.") };
                return(OpResult);
            }
            var oldPrio = uir.SubPriority;

            uir.SubPriority += del;
            uir.LastModified = DateTime.UtcNow;
            uir.AdminID      = adminId;
            await uirsvc.AddOrUpdateEntitiesAsync(cntx, new UsersInRoleSet(), new UsersInRole[] { uir });

            uir.UserID = u.ID;
            uir.RoleID = rid;
            await AddUserRoleHistory(uir, UserRoleOperations.Modified);

            UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy();
            var memb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, uid);

            var notice = new SimpleMessage
            {
                TypeId = 1,
                Title  = string.Format(ResourceUtils.GetString("54da39696e8014b5ded7a0eaeac1dfc4", "The relative priority of your role: [{0}] is changed from {1} to {2}.", memb.AcceptLanguages),
                                       uir.RoleRef.DistinctString, oldPrio, uir.SubPriority),
                Data = "{ id=\"" + rid + "\", type=\"role\", name=\"" + uir.RoleRef.DistinctString + "\" }"
            };

            OpResult.Result  = new { ok = true, msg = "" };
            OpResult.notices = new SimpleMessage[] { notice };
            return(OpResult);
        }
Пример #2
0
        public static async Task <OperationResult> RemoveUserFromRole(string adminId, string uid, int rid)
        {
            OperationResult OpResult = new OperationResult();
            var             maxp     = await MemberAdminContext.GetMaxPriority(adminId);

            var cntx = Cntx;
            UserServiceProxy usvc = new UserServiceProxy();
            var u = await usvc.LoadEntityByKeyAsync(cntx, uid);

            if (u == null)
            {
                OpResult.Result = new { ok = false, msg = string.Format(ResourceUtils.GetString("b66098049404e4de1356242e8aa6444a", "User \"{0}\" is not found."), uid) };
                return(OpResult);
            }
            UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy();
            var uir = await uirsvc.LoadEntityByKeyAsync(cntx, rid, u.ID);

            if (uir == null)
            {
                OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("78257cace857db766d54e6568d7f912b", "The user is not in this role.") };
                return(OpResult);
            }
            uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(cntx, uir);

            if (maxp.Major < uir.RoleRef.RolePriority || maxp.Major == uir.RoleRef.RolePriority && uir.SubPriority > maxp.Major)
            {
                OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("0437b5660f17723dc29c3fa7e08e08a0", "Removing more priviledged role is not authorized.") };
                return(OpResult);
            }
            await uirsvc.DeleteEntitiesAsync(cntx, new UsersInRoleSet(), new UsersInRole[] { uir });

            uir.UserID = u.ID;
            uir.RoleID = rid;
            await AddUserRoleHistory(uir, UserRoleOperations.Deleted);

            UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy();
            var memb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, uid);

            OpResult.Result  = new { ok = true, msg = "", available = new { id = rid, name = uir.RoleRef.RoleName, path = uir.RoleRef.DistinctString, op = true } };
            OpResult.notices = new SimpleMessage[]
            {
                new SimpleMessage
                {
                    TypeId = 1,
                    Title  = string.Format(ResourceUtils.GetString("9708d527fbbf0d9752fc2c741615fb58", "Your role: [{0}] is removed.", memb.AcceptLanguages), uir.RoleRef.DistinctString),
                    Data   = "{ id=\"" + rid + "\", type=\"role\", name=\"" + uir.RoleRef.DistinctString + "\" }"
                }
            };
            return(OpResult);
        }
Пример #3
0
        public static async Task <dynamic> ListUsersInRole(string adminId, int id)
        {
            RoleServiceProxy rsvc = new RoleServiceProxy();
            var r = await rsvc.LoadEntityByKeyAsync(Cntx, id);

            List <dynamic> users = new List <dynamic>();

            if (r == null)
            {
                return new { ok = false, msg = ResourceUtils.GetString("2dcb0c4ea3d378571beac6927e1a4a99", "The role is not found!"), users = users }
            }
            ;
            var maxp = await MemberAdminContext.GetMaxPriority(adminId);

            var uirs = await rsvc.MaterializeAllUsersInRolesAsync(Cntx, r);

            UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy();

            foreach (var uir in uirs)
            {
                uir.User_UserID = await uirsvc.MaterializeUser_UserIDAsync(Cntx, uir);

                uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(Cntx, uir);

                var umax = await MemberAdminContext.GetMaxPriority(uir.User_UserID.ID);

                bool canOp = false;
                if (maxp.Major >= umax.Major)
                {
                    canOp = maxp.Major > r.RolePriority || maxp.Major == r.RolePriority && maxp.Minor >= uir.SubPriority;
                }
                users.Add(new { id = uir.RoleRef.ID, uid = uir.User_UserID.ID, name = uir.RoleRef.RoleName, username = uir.User_UserID.Username, path = Utils.GetHtmlRolePath(uir.RoleRef.DistinctString), level = uir.SubPriority, op = canOp });
            }
            return(new { ok = true, msg = "", users = users });
        }
    }
 public static async Task<dynamic> ListUsersInRole(string adminId, int id)
 {
     RoleServiceProxy rsvc = new RoleServiceProxy();
     var r = await rsvc.LoadEntityByKeyAsync(Cntx, id);
     List<dynamic> users = new List<dynamic>();
     if (r == null)
         return new { ok = false, msg = ResourceUtils.GetString("2dcb0c4ea3d378571beac6927e1a4a99", "The role is not found!"), users = users };
     var maxp = await MemberAdminContext.GetMaxPriority(adminId);
     var uirs = await rsvc.MaterializeAllUsersInRolesAsync(Cntx, r);
     UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy();
     foreach (var uir in uirs)
     {
         uir.User_UserID = await uirsvc.MaterializeUser_UserIDAsync(Cntx, uir);
         uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(Cntx, uir);
         var umax = await MemberAdminContext.GetMaxPriority(uir.User_UserID.ID);
         bool canOp = false;
         if (maxp.Major >= umax.Major)
             canOp = maxp.Major > r.RolePriority || maxp.Major == r.RolePriority && maxp.Minor >= uir.SubPriority;
         users.Add(new { id = uir.RoleRef.ID, uid = uir.User_UserID.ID, name = uir.RoleRef.RoleName, username = uir.User_UserID.Username, path = Utils.GetHtmlRolePath(uir.RoleRef.DistinctString), level = uir.SubPriority, op = canOp });
     }
     return new { ok = true, msg = "", users = users };
 }
 public static async Task<OperationResult> RemoveUserFromRole(string adminId, string uid, int rid)
 {
     OperationResult OpResult = new OperationResult();
     var maxp = await MemberAdminContext.GetMaxPriority(adminId);
     var cntx = Cntx;
     UserServiceProxy usvc = new UserServiceProxy();
     var u = await usvc.LoadEntityByKeyAsync(cntx, uid);
     if (u == null)
     {
         OpResult.Result = new { ok = false, msg = string.Format(ResourceUtils.GetString("b66098049404e4de1356242e8aa6444a", "User \"{0}\" is not found."), uid) };
         return OpResult;
     }
     UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy();
     var uir = await uirsvc.LoadEntityByKeyAsync(cntx, rid, u.ID);
     if (uir == null)
     {
         OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("78257cace857db766d54e6568d7f912b", "The user is not in this role.") };
         return OpResult;
     }
     uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(cntx, uir);
     if (maxp.Major < uir.RoleRef.RolePriority || maxp.Major == uir.RoleRef.RolePriority && uir.SubPriority > maxp.Major)
     {
         OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("0437b5660f17723dc29c3fa7e08e08a0", "Removing more priviledged role is not authorized.") };
         return OpResult;
     }
     await uirsvc.DeleteEntitiesAsync(cntx, new UsersInRoleSet(), new UsersInRole[] { uir });
     uir.UserID = u.ID;
     uir.RoleID = rid;
     await AddUserRoleHistory(uir, UserRoleOperations.Deleted);
     UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy();
     var memb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, uid);
     OpResult.Result = new { ok = true, msg = "", available = new { id = rid, name = uir.RoleRef.RoleName, path = uir.RoleRef.DistinctString, op = true } };
     OpResult.notices = new SimpleMessage[]
     {
         new SimpleMessage 
         {
             TypeId = 1,
             Title = string.Format(ResourceUtils.GetString("9708d527fbbf0d9752fc2c741615fb58", "Your role: [{0}] is removed.", memb.AcceptLanguages), uir.RoleRef.DistinctString), 
             Data = "{ id=\"" + rid + "\", type=\"role\", name=\"" + uir.RoleRef.DistinctString + "\" }"
         }
     };
     return OpResult;
 }
 public static async Task<OperationResult> AdjustUserRoleLevel(string adminId, string uid, int rid, int del)
 {
     OperationResult OpResult = new OperationResult();
     var maxp = await MemberAdminContext.GetMaxPriority(adminId);
     var cntx = Cntx;
     UserServiceProxy usvc = new UserServiceProxy();
     var u = usvc.LoadEntityByKey(cntx, uid);
     if (u == null)
     {
         OpResult.Result = new { ok = false, msg = string.Format(ResourceUtils.GetString("b66098049404e4de1356242e8aa6444a", "User \"{0}\" is not found."), uid) };
         return OpResult;
     }
     UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy();
     var uir = await uirsvc.LoadEntityByKeyAsync(cntx, rid, u.ID);
     if (uir == null)
     {
         OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("78257cace857db766d54e6568d7f912b", "The user is not in this role.") };
         return OpResult;
     }
     uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(cntx, uir);
     if (maxp.Major < uir.RoleRef.RolePriority || maxp.Major == uir.RoleRef.RolePriority && uir.SubPriority + del > maxp.Major)
     {
         OpResult.Result = new { ok = false, msg = ResourceUtils.GetString("5986d63fe301793ee7f5b2134a8f8787", "Modifying more priviledged role is not authorized.") };
         return OpResult;
     }
     var oldPrio = uir.SubPriority;
     uir.SubPriority += del;
     uir.LastModified = DateTime.UtcNow;
     uir.AdminID = adminId;
     await uirsvc.AddOrUpdateEntitiesAsync(cntx, new UsersInRoleSet(), new UsersInRole[] { uir });
     uir.UserID = u.ID;
     uir.RoleID = rid;
     await AddUserRoleHistory(uir, UserRoleOperations.Modified);
     UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy();
     var memb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, uid);
     var notice = new SimpleMessage
     {
         TypeId = 1,
         Title = string.Format(ResourceUtils.GetString("54da39696e8014b5ded7a0eaeac1dfc4", "The relative priority of your role: [{0}] is changed from {1} to {2}.", memb.AcceptLanguages),
                               uir.RoleRef.DistinctString, oldPrio, uir.SubPriority),
         Data = "{ id=\"" + rid + "\", type=\"role\", name=\"" + uir.RoleRef.DistinctString + "\" }"
     };
     OpResult.Result = new { ok = true, msg = "" };
     OpResult.notices = new SimpleMessage[] { notice };
     return OpResult;
 }
 public static async Task<dynamic> RemoveUserFromRole(string adminId, string uid, int rid)
 {
     var maxp = await MemberAdminContext.GetMaxPriority(adminId);
     UserServiceProxy usvc = new UserServiceProxy();
     var u = await usvc.LoadEntityByKeyAsync(Cntx, uid);
     if (u == null)
         return new { ok = false, msg = string.Format(ResourceUtils.GetString("b66098049404e4de1356242e8aa6444a", "User \"{0}\" is not found."), uid) };
     UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy();
     var uir = await uirsvc.LoadEntityByKeyAsync(Cntx, rid, u.ID);
     if (uir == null)
         return new { ok = false, msg = ResourceUtils.GetString("78257cace857db766d54e6568d7f912b", "The user is not in this role.") };
     uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(Cntx, uir);
     if (maxp.Major < uir.RoleRef.RolePriority || maxp.Major == uir.RoleRef.RolePriority && uir.SubPriority > maxp.Major)
         return new { ok = false, msg = ResourceUtils.GetString("0437b5660f17723dc29c3fa7e08e08a0", "Removing more priviledged role is not authorized.") };
     await uirsvc.DeleteEntitiesAsync(Cntx, new UsersInRoleSet(), new UsersInRole[] { uir });
     uir.UserID = u.ID;
     uir.RoleID = rid;
     await AddUserRoleHistory(uir, UserRoleOperations.Deleted);
     return new { ok = true, msg = "", available = new { id = rid, name = uir.RoleRef.RoleName, path = uir.RoleRef.DistinctString, op = true } };
 }
 public static async Task<dynamic> AdjustUserRoleLevel(string adminId, string uid, int rid, int del)
 {
     var maxp = await MemberAdminContext.GetMaxPriority(adminId);
     UserServiceProxy usvc = new UserServiceProxy();
     var u = usvc.LoadEntityByKey(Cntx, uid);
     if (u == null)
         return new { ok = false, msg = string.Format(ResourceUtils.GetString("b66098049404e4de1356242e8aa6444a", "User \"{0}\" is not found."), uid) };
     UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy();
     var uir = await uirsvc.LoadEntityByKeyAsync(Cntx, rid, u.ID);
     if (uir == null)
         return new { ok = false, msg = ResourceUtils.GetString("78257cace857db766d54e6568d7f912b", "The user is not in this role.") };
     uir.RoleRef = await uirsvc.MaterializeRoleRefAsync(Cntx, uir);
     if (maxp.Major < uir.RoleRef.RolePriority || maxp.Major == uir.RoleRef.RolePriority && uir.SubPriority + del > maxp.Major)
         return new { ok = false, msg = ResourceUtils.GetString("5986d63fe301793ee7f5b2134a8f8787", "Modifying more priviledged role is not authorized.") };
     uir.SubPriority += del;
     uir.LastModified = DateTime.UtcNow;
     uir.AdminID = adminId;
     await uirsvc.AddOrUpdateEntitiesAsync(Cntx, new UsersInRoleSet(), new UsersInRole[] { uir });
     uir.UserID = u.ID;
     uir.RoleID = rid;
     await AddUserRoleHistory(uir, UserRoleOperations.Modified);
     return new { ok = true, msg = "" };
 }