コード例 #1
0
        /// <summary>
        /// Delete System User Group and it's relationships
        /// </summary>
        /// <param name="group"></param>
        public static void DeleteSystemUserGroup(Simplified.Ring3.SystemUserGroup group)
        {
            // Remove System user member's
            Db.SlowSQL("DELETE FROM Simplified.Ring3.SystemUserGroupMember WHERE SystemUserGroup=?", group);

            group.Delete();
        }
コード例 #2
0
ファイル: Helper.cs プロジェクト: Prav962/UserAdmin
        public static void AssureUriPermission(string uri, SystemUserGroup group)
        {
            UriPermission permission = Db.SQL<UriPermission>("SELECT o.Permission FROM Simplified.Ring5.SystemUserGroupUriPermission o WHERE o.Permission.Uri=? AND o.SystemUserGroup=?", uri, group).First;

            if (permission == null) {

                Db.Transact(() => {
                    UriPermission p1 = new UriPermission() { Uri = uri, CanGet = true };
                    new SystemUserGroupUriPermission() { ToWhat = p1, WhatIs = group };
                });
            }
        }
コード例 #3
0
        public static void AddUserToGroup(SystemUser User, string GroupName)
        {
            SystemUserGroup group = Db.SQL<SystemUserGroup>("SELECT g FROM Simplified.Ring3.SystemUserGroup g WHERE g.Name = ?", GroupName).First;

            if (group == null) {
                group = new SystemUserGroup() {
                    Name = GroupName
                };
            }

            AddUserToGroup(User, group);
        }
コード例 #4
0
        void Handle(Input.AddUserToGroup action)
        {
            if (string.IsNullOrEmpty(this.SelectedSystemUserGroupID_))
            {
                action.Cancel();
                // TODO: Feedback!
                return;
            }

            Simplified.Ring3.SystemUserGroup group = Db.SQL <Simplified.Ring3.SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.ObjectID=?", this.SelectedSystemUserGroupID_).First;

            Simplified.Ring3.SystemUserGroupMember systemUserGroupMember = new Simplified.Ring3.SystemUserGroupMember();

            systemUserGroupMember.WhatIs = this.Data as Simplified.Ring3.SystemUser;
            systemUserGroupMember.ToWhat = group;

            this.SelectedSystemUserGroupID_ = null;
        }
コード例 #5
0
        public static void AddUserToGroup(SystemUser User, SystemUserGroup Group)
        {
            if (User == null) {
                throw new ArgumentNullException("User");
            }

            if (Group == null) {
                throw new ArgumentNullException("Group");
            }

            if (IsMemberOfGroup(User, Group)) {
                return;
            }

            SystemUserGroupMember member = new SystemUserGroupMember() {
                SystemUser = User,
                SystemUserGroup = Group
            };
        }
コード例 #6
0
        /// <summary>
        /// Remove System User as a Member of a SystemUserGroup
        /// </summary>
        /// <param name="user"></param>
        /// <param name="group"></param>
        public static void RemoveSystemUserFromSystemUserGroup(Simplified.Ring3.SystemUser user, Simplified.Ring3.SystemUserGroup group)
        {
            var removeGroup = Db.SQL <Simplified.Ring3.SystemUserGroupMember>("SELECT o FROM Simplified.Ring3.SystemUserGroupMember o WHERE o.WhatIs=? AND o.ToWhat=?", user, group).First;

            if (removeGroup != null)
            {
                removeGroup.Delete();
            }

            //group.RemoveMember(user);
        }
コード例 #7
0
 /// <summary>
 /// Add System User as a Member of a SystemUserGroup
 /// </summary>
 /// <param name="user"></param>
 /// <param name="group"></param>
 public static void AddSystemUserToSystemUserGroup(Simplified.Ring3.SystemUser user, Simplified.Ring3.SystemUserGroup group)
 {
     Simplified.Ring3.SystemUserGroupMember systemUserGroupMember = new Simplified.Ring3.SystemUserGroupMember();
     systemUserGroupMember.WhatIs = user;
     systemUserGroupMember.ToWhat = group;
     //systemUserGroupMember.SetSystemUser(user);
     //systemUserGroupMember.SetToWhat(group);
     //group.AddMember(systemUser);
 }
コード例 #8
0
        public static bool IsMemberOfGroup(SystemUser User, SystemUserGroup Group)
        {
            if (User == null || Group == null) {
                return false;
            }

            SystemUserGroupMember group = Db.SQL<SystemUserGroupMember>("SELECT o FROM Simplified.Ring3.SystemUserGroupMember o WHERE o.SystemUser = ? AND o.SystemUserGroup = ?", User, Group).First;

            return group != null;
        }
コード例 #9
0
ファイル: Helper.cs プロジェクト: Prav962/UserAdmin
        /// <summary>
        /// TODO: Avoid circular references!!
        /// </summary>
        /// <param name="group"></param>
        /// <param name="basedOnGroup"></param>
        /// <returns></returns>
        private static bool IsBasedOnGroup(SystemUserGroup group, SystemUserGroup basedOnGroup)
        {
            if (group == null) return false;

            // NOTE: To compare to objects queried from database we need to use .Equals(),  "==" wont work!!.
            if (group.Equals(basedOnGroup)) {
                return true;
            }

            if (IsBasedOnGroup(group.Parent, basedOnGroup)) {
                return true;
            }

            return false;
        }
コード例 #10
0
ファイル: Helper.cs プロジェクト: Prav962/UserAdmin
        private static UriPermission GetPermissionFromGroup(SystemUserGroup group, string url)
        {
            if (group == null) return null;

            UriPermission permission = Db.SQL<UriPermission>("SELECT o.Permission FROM Simplified.Ring5.SystemUserGroupUriPermission o WHERE o.Permission.Uri=? AND o.SystemUserGroup=?", url, group).First;
            if (permission != null) {
                return permission;
            }

            permission = GetPermissionFromGroup(group.Parent, url);
            if (permission != null) {
                return permission;
            }

            return null;
        }
コード例 #11
0
ファイル: Helper.cs プロジェクト: Prav962/UserAdmin
        //static public bool IsMemberOfAdminGroup(Simplified.Ring3.SystemUser user) {
        //    if (user == null) return false;
        //    Simplified.Ring3.SystemUser Group adminGroup = Db.SQL<Simplified.Ring3.SystemUser	Group>("SELECT o FROM Simplified.Ring3.SystemUser Group o WHERE o.Name=?", Program.AdminGroupName).First;
        //    return IsMemberOfGroup(user, adminGroup);
        //}
        public static bool IsMemberOfGroup(SystemUser user, SystemUserGroup basedOnGroup)
        {
            if (user == null) return false;
            if (basedOnGroup == null) return false;

            var groups = Db.SQL<SystemUserGroup>("SELECT o.SystemUserGroup FROM Simplified.Ring3.SystemUserGroupMember o WHERE o.SystemUser=?", user);
            foreach (var groupItem in groups) {

                bool flag = IsBasedOnGroup(groupItem, basedOnGroup);
                if (flag) {
                    return true;
                }
            }

            return false;
        }
コード例 #12
0
ファイル: Utils.cs プロジェクト: Starcounter/Warehouse
        public static void AssureAdminSystemUserGroupAndPermissions() {

            Db.Transact(() => {

                string admingroup = "Admin (System Users)";

                // Assure Warehouse Admin Group
                SystemUserGroup warehouseadminGroup = Db.SQL<SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", Security.WarehouseAdminGroupName).First;
                if (warehouseadminGroup == null) {
                    warehouseadminGroup = new SystemUserGroup();
                    warehouseadminGroup.Name = Security.WarehouseAdminGroupName;
                }

                // Find all admin's and add them to the warehouse admin group.
                SystemUserGroup adminGroup = Db.SQL<SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", admingroup).First;
                if (adminGroup != null) {
                    foreach (SystemUser user in adminGroup.Members) {
                        SystemUser.AddUserToGroup(user, warehouseadminGroup);
                    }
                }

                //if (warehouseadminGroup.Parent == null) {
                //    SystemUserGroup adminGroup = Db.SQL<SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", admingroup).First;
                //    if (adminGroup != null) {
                //        warehouseadminGroup.Parent = adminGroup;
                //    }
                //}

                //if (warehouseadminGroup.Members == null || !warehouseadminGroup.Members.Any()) {
                //    // Assure that there is atleast one user with admin rights to the warehouse

                //    SystemUser user = new SystemUser();
                //    user.Username = "******";
                //    user.Password = "******";

                //    string hashedPassword;
                //    Utils.GeneratePasswordHash(user.Username.ToLower(), user.Password.ToLower(), out hashedPassword);
                //    user.Password = hashedPassword;

                //    SystemUser.AddUserToGroup(user, warehouseadminGroup);
                //}
            });
        }