Example #1
0
        protected CUserEntity CreateUser(CUserEntity newUser)
        {
            try
            {
                COrganizeEntity organize = new COrganizeEntity(ConnString).Load(Usr_Organize);

                // create resource for user's folder
                CResourceEntity folderRes = new CResourceEntity(ConnString);
                folderRes.Res_Name   = "";
                folderRes.Res_Parent = organize.Org_Resource;
                folderRes.Res_Type   = (int)RESOURCETYPE.FOLDERRESOURCE;
                folderRes.Res_Id     = folderRes.Insert();

                folderRes.Res_Name = folderRes.Res_Id.ToString() + newUser.Usr_Member;
                folderRes.Update();

                // create user's folder
                String userPath = folderRes.MakeFullPath();
                Directory.CreateDirectory(userPath);

                // create user
                newUser.Usr_Resource = folderRes.Res_Id;
                newUser.ConnString   = ConnString;
                newUser.Usr_Id       = newUser.Insert();
                return(newUser);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #2
0
        public COrganizeEntity CreateOrganize(String organizeName)
        {
            try
            {
                // Check privilege
                CACLEntity acl = new CACLEntity();
                acl.Acl_Resource  = 0;
                acl.Acl_Operation = (int)ACLOPERATION.CREATEORGANIZE;
                if (!CheckPrivilege(acl))
                {
                    throw new Exception("当前用户无创建组织权限");
                }

                // create resource for this organize
                CResourceEntity res = new CResourceEntity(ConnString);
                res.Res_Name   = organizeName;
                res.Res_Parent = 0;
                res.Res_Type   = (int)RESOURCETYPE.ORGANIZERESOURCE;
                res.Res_Id     = res.Insert();

                // create default storage folder named as organize resource id
                String organizePath = Path.Combine(MidLayerSettings.AppPath, res.Res_Id.ToString() + organizeName);
                Directory.CreateDirectory(organizePath);

                // create resource for default folder of organize
                CResourceEntity folderRes = new CResourceEntity(ConnString);
                folderRes.Res_Name   = res.Res_Id.ToString() + organizeName;
                folderRes.Res_Parent = 0;
                folderRes.Res_Type   = (int)RESOURCETYPE.FOLDERRESOURCE;
                folderRes.Res_Id     = folderRes.Insert();

                // Create organize entity
                COrganizeEntity organize = new COrganizeEntity(ConnString);
                organize.Org_Name = organizeName;
                //organize = res.Res_Id;
                organize.Org_Resource = res.Res_Id;
                organize.Insert();

                // create archive folder for organzie
                String archivePath = Path.Combine(organizePath, "Archive");
                Directory.CreateDirectory(archivePath);

                // create resource for archive folder
                CResourceEntity archiveRes = new CResourceEntity(ConnString);
                archiveRes.Res_Name   = "Archive";
                archiveRes.Res_Parent = folderRes.Res_Id;
                archiveRes.Res_Type   = (int)RESOURCETYPE.FOLDERRESOURCE;
                archiveRes.Res_Id     = archiveRes.Insert();

                organize.Org_ArchiveRes = archiveRes.Res_Id;
                organize.Update();

                return(organize);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Example #3
0
        public void Permit(int userId, ACLROLETYPE roleType, int resourceId, ACLOPERATION operation)
        {
            // user have to have write privilege on resource
            CACLEntity acl = new CACLEntity();

            acl.Acl_Resource  = resourceId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限");
            }

            List <CACLEntity> userAcls = new List <CACLEntity>();

            if (roleType == ACLROLETYPE.USERROLE)
            {
                CUserEntity user = new CUserEntity(ConnString).Load(userId);
                userAcls = user.GetUserACLs();
            }
            else if (roleType == ACLROLETYPE.GROUPROLE)
            {
                CGroupEntity group = new CGroupEntity(ConnString).Load(userId);
                userAcls = group.GetGroupACLs();
            }

            // check if this acl conflicts with others
            CResourceEntity resource = new CResourceEntity(ConnString).Load(resourceId);

            foreach (CACLEntity userAcl in userAcls)
            {
                if (resource.IsChild(userAcl.Acl_Resource) && userAcl.Acl_Operation == (int)operation)
                {
                    throw new Exception("与其他权限冲突");
                }
            }

            // create acl
            CACLEntity acl1 = new CACLEntity(ConnString);

            acl1.Acl_Resource   = resourceId;
            acl1.Acl_Role       = userId;
            acl1.Acl_RType      = (int)roleType;
            acl1.Acl_Operation  = (int)operation;
            acl1.Acl_Creator    = this.Usr_Id;
            acl1.Acl_CreateTime = DateTime.Now;
            acl1.Insert();

            // remove all child privileges
            foreach (CACLEntity ua in userAcls)
            {
                resource = new CResourceEntity(ConnString).Load(ua.Acl_Resource);
                if (resource.IsChild(resourceId) && ua.Acl_Operation == (int)operation)
                {
                    ua.Delete();
                }
            }
        }
Example #4
0
        /// <summary>
        /// 更改关键字——赵英武
        /// </summary>
        /// <param name="resId"></param>
        /// <param name="keyword"></param>
        public void KeyWordChange(int resId, string keyword)
        {
            if (resId <= 0)
            {
                throw new Exception("系统错误");
            }

            CResourceEntity aRes = new CResourceEntity().Load(resId);

            aRes.Res_KeyWord = keyword;
            aRes.Update();
        }
Example #5
0
        // list all resources shared to me
        public List <CResourceEntity> ListShareResources()
        {
            List <CResourceEntity> resources  = new List <CResourceEntity>();
            COrganizeEntity        organize   = new COrganizeEntity(ConnString).Load(this.Usr_Organize);
            CResourceEntity        archiveRes = organize.GetArchiveFolder();

            if (Usr_Type == (int)USERTYPE.SYSTEMADMIN || Usr_Type == (int)USERTYPE.ORGANIZEADMIN)
            {
                return(resources);
            }

            List <CACLEntity> acls = GetAllACLs();

            foreach (CACLEntity acl in acls)
            {
                if (acl.Acl_Operation != (int)ACLOPERATION.READ && acl.Acl_Operation != (int)ACLOPERATION.WRITE)
                {
                    continue;
                }

                if (acl.Acl_Resource == organize.Org_Resource)
                {
                    continue;
                }

                CResourceEntity res = new CResourceEntity(ConnString).Load(acl.Acl_Resource);
                if (res.Res_Type != (int)RESOURCETYPE.FILERESOURCE && res.Res_Type != (int)RESOURCETYPE.FOLDERRESOURCE)
                {
                    continue;
                }

                bool existed = false;
                foreach (CResourceEntity r in resources)
                {
                    if (r.Res_Id == res.Res_Id)
                    {
                        existed = true;
                        break;
                    }
                }

                if (!existed && !res.IsChild(archiveRes.Res_Id) && !res.IsChild(Usr_Resource))
                {
                    resources.Add(res);
                }
            }

            return(resources);
        }
Example #6
0
        // List all Descendants of root that current user can read
        public List <CResourceEntity> ListDescendants(int root)
        {
            CACLEntity acl1 = new CACLEntity(ConnString);

            acl1.Acl_Resource  = root;
            acl1.Acl_Operation = (int)ACLOPERATION.READ;

            CResourceEntity parent = new CResourceEntity(ConnString).Load(root);

            if (CheckPrivilege(acl1))
            {
                return(parent.ListChildResources());
            }

            List <CResourceEntity> resources = new List <CResourceEntity>();
            List <CACLEntity>      acls      = GetAllACLs();

            foreach (CACLEntity acl in acls)
            {
                if (acl.Acl_Operation != (int)ACLOPERATION.READ && acl.Acl_Operation != (int)ACLOPERATION.WRITE)
                {
                    continue;
                }

                CResourceEntity res = new CResourceEntity(ConnString).Load(acl.Acl_Resource);
                if (res.Res_Type != (int)RESOURCETYPE.FILERESOURCE && res.Res_Type != (int)RESOURCETYPE.FOLDERRESOURCE)
                {
                    continue;
                }

                bool existed = false;
                foreach (CResourceEntity r in resources)
                {
                    if (r.Res_Id == res.Res_Id)
                    {
                        existed = true;
                        break;
                    }
                }

                if (!existed && res.IsChild(parent.Res_Id))
                {
                    resources.Add(res);
                }
            }

            return(resources);
        }
Example #7
0
        public void CutResource(int srcResId, int dstResId)
        {
            // copy resource
            CACLEntity acl = new CACLEntity(ConnString);

            acl.Acl_Resource  = srcResId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限!");
            }
            acl.Acl_Resource  = dstResId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限!");
            }

            CResourceEntity srcRes  = new CResourceEntity(ConnString).Load(srcResId);
            CResourceEntity dstRes  = new CResourceEntity(ConnString).Load(dstResId);
            String          srcPath = srcRes.MakeFullPath();

            if (dstRes.Res_Type != (int)RESOURCETYPE.FOLDERRESOURCE)
            {
                throw new Exception("粘贴的目标必须是目录!");
            }
            srcRes.MoveTo(dstRes);

            // cut folder/file
            String dstPath = dstRes.MakeFullPath();

            dstPath = Path.Combine(dstPath, srcRes.Res_Name);
            if (Directory.Exists(dstPath) || File.Exists(dstPath))
            {
                throw new Exception(dstPath + "与现有文件名冲突!");
            }
            if (srcRes.Res_Type == (int)RESOURCETYPE.FILERESOURCE)
            {
                File.Move(srcPath, dstPath);
            }
            else
            {
                Directory.Move(srcPath, dstPath);
            }
        }
Example #8
0
        // List all children that current user can read
        public List <CResourceEntity> ListResources(int parentId)
        {
            CACLEntity acl = new CACLEntity(ConnString);

            acl.Acl_Resource  = parentId;
            acl.Acl_Operation = (int)ACLOPERATION.READ;

            List <CResourceEntity> files = new List <CResourceEntity>();

            if (!CheckPrivilege(acl))
            {
                return(files);
            }

            CResourceEntity parent = new CResourceEntity(ConnString).Load(parentId);

            return(parent.ListChildResources());
        }
Example #9
0
        public void DeleteResource(int resourceId)
        {
            CACLEntity acl = new CACLEntity(ConnString);

            acl.Acl_Resource  = resourceId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限");
            }

            CResourceEntity res = new CResourceEntity(ConnString).Load(resourceId);

            res.Remove();

            CMailEntity mailRes = new CMailEntity();

            mailRes.Remove("this.M_Resource ='" + resourceId + "'");
        }
Example #10
0
        // return new resource id
        public CResourceEntity CreateFile(int parentId, String fileName, out String filePath)
        {
            CACLEntity acl = new CACLEntity();

            acl.Acl_Resource  = parentId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限");
            }

            // create folder
            CResourceEntity parent = new CResourceEntity(MidLayerSettings.ConnectionString).Load(parentId);

            if (parent == null)
            {
                throw new Exception("无法找到资源. ID=" + parentId);
            }

            String path = parent.MakeFullPath();

            if (!Directory.Exists(path))
            {
                throw new Exception("目录不存在: " + path);
            }
            path = Path.Combine(path, fileName);
            if (Directory.Exists(path) || File.Exists(path))
            {
                throw new Exception("名称冲突: " + path);
            }

            filePath = path;

            // create resource
            CResourceEntity res = new CResourceEntity(ConnString);

            res.Res_Name = fileName;
            res.Res_Type = (int)RESOURCETYPE.FILERESOURCE;
            parent.CreateChildResource(res);
            return(res);
        }
Example #11
0
        public override void Delete()
        {
            // delete all its acls
            String filter = "this.Acl_Creator=" + Usr_Id;

            new CACLEntity(ConnString).Delete(filter);

            filter = "this.Acl_Role=" + Usr_Id + " and this.Acl_RType=" + (int)ACLROLETYPE.USERROLE;
            new CACLEntity(ConnString).Delete(filter);

            // delete from all groups
            filter = "this.Urg_User=" + Usr_Id;
            new CUserGroupEntity(ConnString).Delete(filter);

            // delete all its resources
            CResourceEntity userDir = new CResourceEntity(ConnString).Load(Usr_Resource);
            String          path    = userDir.MakeFullPath();

            Directory.Delete(path, true);

            base.Delete();
        }
Example #12
0
        /// <summary>
        /// 更新文件——赵英武
        /// </summary>
        /// <param name="resId"></param>
        /// <param name="fileName"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public CResourceEntity UpdateFile(int resId, String fileName, out String filePath)
        {
            CACLEntity acl = new CACLEntity();

            acl.Acl_Resource  = resId;
            acl.Acl_Operation = (int)ACLOPERATION.WRITE;
            if (!CheckPrivilege(acl))
            {
                throw new Exception("没有写权限");
            }

            CResourceEntity res  = new CResourceEntity().Load(resId);
            string          path = res.MakeFullPath();

            if (!System.IO.File.Exists(path))
            {
                throw new Exception("要更新的文件不存在!");
            }

            filePath     = path;
            res.Res_Name = fileName;
            res.Update();
            return(res);
        }
Example #13
0
        // list resources of my workspace
        public List <CResourceEntity> ListMyResources()
        {
            CResourceEntity my = new CResourceEntity(ConnString).Load(Usr_Resource);

            return(my.ListChildResources());
        }
Example #14
0
        public bool CheckPrivilege(CACLEntity acl)
        {
            // system admin has all privileges
            if (Usr_Type == (int)USERTYPE.SYSTEMADMIN)
            {
                return(true);
            }

            // if resourceid of acl is 0, it's a system management
            // and no users have the privilege except system admin
            if (acl.Acl_Resource == 0)
            {
                return(false);
            }

            // if resourceid is the organize id of current user,
            // the user must be system admin
            if (acl.Acl_Resource == this.Usr_Organize)
            {
                if (this.Usr_Type == (int)USERTYPE.ORGANIZEADMIN)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            // get all groups containing current user
            String                  filter     = "this.Urg_User="******"this.Acl_Operation=" + acl.Acl_Operation.ToString();
                filter += " and this.Acl_Resource=" + resId.ToString();
                filter += " and this.Acl_Role=" + Usr_Id.ToString();
                filter += " and this.Acl_RType=" + ((int)ACLROLETYPE.USERROLE).ToString();
                List <CACLEntity> acls = acl.GetObjectList(filter);
                if (acls.Count > 0)
                {
                    return(true);
                }

                // check if user's groups have right on this resource
                foreach (CUserGroupEntity ug in userGroups)
                {
                    filter  = "this.Acl_Operation=" + acl.Acl_Operation.ToString();
                    filter += " and this.Acl_Resource=" + resId.ToString();
                    filter += " and this.Acl_Role=" + ug.Urg_Group.ToString();
                    filter += " and this.Acl_RType=" + ((int)ACLROLETYPE.GROUPROLE).ToString();
                    acls    = acl.GetObjectList(filter);
                    if (acls.Count > 0)
                    {
                        return(true);
                    }
                }

                // get parent id of this resource
                CResourceEntity resource = new CResourceEntity(ConnString).Load(resId);
                if (resource == null)
                {
                    break;
                }
                else
                {
                    resId = resource.Res_Parent;
                }
            }
            return(false);
        }