示例#1
0
        public File CreateGroupFolder(int roleID, int portalID, UserInfo currentUser)
        {
            FileController ctrl = new FileController();
            File rootGroupFolder = new File();

            //rootGroupFolder.ChildCount = 0;
            rootGroupFolder.CreatedByUserID = currentUser.UserID;
            rootGroupFolder.CreatedByUserName = currentUser.DisplayName;
            rootGroupFolder.CreatedDate = System.DateTime.Now;
            rootGroupFolder.IsInTrash = false;
            rootGroupFolder.IsFolder = true;
            rootGroupFolder.ItemType = 0;
            rootGroupFolder.LastModifiedByUserID = currentUser.UserID;
            rootGroupFolder.LastModifiedByUserName = currentUser.DisplayName;
            rootGroupFolder.LastModifiedDate = System.DateTime.Now;
            RoleController ctrlRole = new RoleController();
            RoleInfo role = ctrlRole.GetRole(roleID, portalID);
            rootGroupFolder.Name = role.RoleName;
            rootGroupFolder.ParentID = GetRootGroupsFolder(portalID, currentUser.UserID).ID;
            rootGroupFolder.PortalID = portalID;
            rootGroupFolder.RoleID = roleID;

            ctrl.Create(rootGroupFolder);

            Permission permission = new Permission();
            permission.CanAddFiles = true;
            permission.CanAddFolders = true;
            permission.CanDelete = false;
            permission.CanModify = false;
            permission.CanModifyPermission = false;
            permission.CanSee = true;
            permission.FileID = rootGroupFolder.ID;
            permission.ModuleID = 0;
            permission.PortalID = portalID;
            permission.RoleID = role.RoleID;
            permission.RoleName = role.RoleName;

            PermissionController ctrlPerm = new PermissionController();
            ctrlPerm.Create(permission);

            return rootGroupFolder;
        }
        protected void lbnOK_Click(object sender, EventArgs e)
        {
            try
            {

                //check file type first
                //if (fileUpload.HasFile)
                //{
                //    string strAllowedFiles = DotNetNuke.Entities.Controllers.HostController.Instance.GetString("FileExtensions");
                //    string[] strSearchPatterns = strAllowedFiles.Split(',');
                //    string uploadType = fileUpload.PostedFile.FileName.Substring(fileUpload.PostedFile.FileName.LastIndexOf('.')+1);
                //    if (!strAllowedFiles.Contains(uploadType))
                //    {
                //        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "File type not allowed", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                //        return;
                //    }
                //}

                //create file
                DNNQuickApps.Modules.QuickDocsPro.FileController objQuickFiles = new DNNQuickApps.Modules.QuickDocsPro.FileController();
                DNNQuickApps.Modules.QuickDocsPro.File objFile = new DNNQuickApps.Modules.QuickDocsPro.File();
                //if (!Convert.ToBoolean(Settings["IsSearchable"].ToString()))
                //{
                //    objFile.ModuleID = ModuleId;
                //}
                objFile.PortalID = PortalId;
                objFile.CreatedByUserID = UserId;
                objFile.CreatedDate = System.DateTime.Now;
                objFile.LastModifiedDate = System.DateTime.Now;
                objFile.LastModifiedByUserID = UserId;
                objFile.VersionsToKeep = -1;
                objFile.VersionNumber = 1;

                //check files type (shared, user, groups)
                String strFilesModuleType = Settings["FilesMode"].ToString();
                if (strFilesModuleType == "UserFiles" || strFilesModuleType == "GroupFiles")
                {
                    if (strFilesModuleType == "UserFiles")
                    {
                        //get UserID parameter
                        if (this.Request.QueryString["UserID"] != null)
                        {
                            _userIDParameter = Convert.ToInt32(this.Request.QueryString["UserID"]);
                        }
                        objFile.HomeFolderUserID = _userIDParameter;
                    }
                    else //group files
                    {
                        //get UserID parameter
                        if (this.Request.QueryString["GroupID"] != null)
                        {
                            _roleIDParameter = Convert.ToInt32(this.Request.QueryString["GroupID"]);
                        }
                        objFile.RoleID = _roleIDParameter;
                    }
                }

                if (UserId != -1)
                {
                    objFile.CreatedByUserName = UserInfo.DisplayName;
                    objFile.LastModifiedByUserName = UserInfo.DisplayName;
                }
                else
                {
                    objFile.CreatedByUserName = "******";
                    objFile.LastModifiedByUserName = "******";
                }

                //create file or folder
                if (this.Request.QueryString["Type"] != null)
                {
                    ItemType = Convert.ToInt32(this.Request.QueryString["Type"]);
                }

                if (ItemType == 1)//File
                {
                    //check file exists
                    if (asyncFileUpload.UploadedFiles.Count == 0)
                    {
                        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "Please select a valid file to upload", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    objFile.Name = "File Upload";
                    objFile.ItemType = 1;
                }
                else if (ItemType == 0) //folder
                {
                    objFile.Name = txtName.Text;
                    objFile.ItemType = 0;
                    objFile.IsFolder = true;
                }
                else if (ItemType == 2) //Hyperlink
                {
                    objFile.Name = txtName.Text;
                    objFile.ItemType = 2;
                    objFile.LinkURL = txtHyperlink.Text;
                }
                else
                {
                    Response.Redirect(Globals.NavigateURL(), true);
                }

                if (this.Request.QueryString["Parent"] != null)
                {
                    ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                }
                objFile.ParentID = ParentID;
                objFile.Description = "";

                //create file

                objQuickFiles.Create(objFile);

                if (ItemType == 1) //file
                {

                    //create file version and copy attributes from current version
                    DNNQuickApps.Modules.QuickDocsPro.File objVersionFile = new DNNQuickApps.Modules.QuickDocsPro.File();
                    //if (!Convert.ToBoolean(Settings["IsSearchable"].ToString()))
                    //{
                    //    objVersionFile.ModuleID = ModuleId;
                    //}
                    objVersionFile.PortalID = PortalId;
                    objVersionFile.CreatedByUserID = objFile.CreatedByUserID;
                    objVersionFile.CreatedDate = objFile.LastModifiedDate;
                    objVersionFile.CreatedByUserName = objFile.CreatedByUserName;
                    objVersionFile.LastModifiedDate = objFile.LastModifiedDate;
                    objVersionFile.LastModifiedByUserID = objFile.LastModifiedByUserID;
                    objVersionFile.LastModifiedByUserName = objFile.LastModifiedByUserName;
                    objVersionFile.LinkURL = objFile.LinkURL;
                    objVersionFile.ItemType = objFile.ItemType;
                    objVersionFile.VersionsToKeep = -1;
                    objVersionFile.VersionNumber = objFile.VersionNumber;
                    objVersionFile.ParentID = objFile.ID;
                    objVersionFile.Name = "Version Upload";
                    objVersionFile.Description = objFile.Description;
                    objVersionFile.HomeFolderUserID = objFile.HomeFolderUserID;
                    objVersionFile.RoleID = objFile.RoleID;

                    objQuickFiles.Create(objVersionFile);

                    //upload file version
                    FileConfigurationController configCtrl = new FileConfigurationController();
                    List<FileConfiguration> configs = configCtrl.GetItems(PortalId) as List<FileConfiguration>;

                    if (configs[0].StorageType == "UNC")
                    {
                        objVersionFile.CreatePath(configs[0].FilesLocation);
                        //fileUpload.SaveAs(configs[0].FilesLocation + objVersionFile.GetFullPath());
                        asyncFileUpload.UploadedFiles[0].SaveAs(configs[0].FilesLocation + objVersionFile.GetFullPath());
                    }
                    else
                    {
                        objVersionFile.CreatePath(Server.MapPath(configs[0].FilesLocation));
                        //fileUpload.SaveAs(Server.MapPath(configs[0].FilesLocation) + objVersionFile.GetFullPath());
                        asyncFileUpload.UploadedFiles[0].SaveAs(Server.MapPath(configs[0].FilesLocation) + objVersionFile.GetFullPath());
                    }

                    //List<string> fileNameAndExtension = objVersionFile.GetFileNameAndExtension(fileUpload.FileName);
                    List<string> fileNameAndExtension = objVersionFile.GetFileNameAndExtension(asyncFileUpload.UploadedFiles[0].FileName);

                    objVersionFile.AttachmentName = asyncFileUpload.UploadedFiles[0].FileName;// fileUpload.FileName;
                    objVersionFile.AttachmentPath = objVersionFile.GetFullPath();
                    objVersionFile.FileType = asyncFileUpload.UploadedFiles[0].ContentType;// fileUpload.PostedFile.ContentType;
                    objVersionFile.FileLength = (int)asyncFileUpload.UploadedFiles[0].ContentLength;// fileUpload.PostedFile.ContentLength;
                    objVersionFile.Name = fileNameAndExtension[0];
                    objVersionFile.Extension = fileNameAndExtension[1];

                    objFile.AttachmentPath = objVersionFile.GetFullPath();
                    objFile.FileType = asyncFileUpload.UploadedFiles[0].ContentType;// fileUpload.PostedFile.ContentType;
                    objFile.FileLength = (int)asyncFileUpload.UploadedFiles[0].ContentLength;// fileUpload.PostedFile.ContentLength;
                    objFile.Name = fileNameAndExtension[0];
                    objFile.Extension = fileNameAndExtension[1];

                    objQuickFiles.Update(objVersionFile);
                    objQuickFiles.Update(objFile);
                }

                    //create permissions
                    PermissionController objQuickPermissions = new PermissionController();

                    foreach (GridViewRow row in gridPermissions.Rows)
                    {
                        if ((((CheckBox)row.FindControl("chkCanSee")).Checked))
                        {
                            Permission perm = new Permission();
                            perm.CanSee = true;
                            perm.CanAddFiles = ((CheckBox)row.FindControl("chkCanAddFolders")).Checked;
                            perm.CanAddFolders = ((CheckBox)row.FindControl("chkCanAddItems")).Checked;
                            perm.CanModify = ((CheckBox)row.FindControl("chkCanModify")).Checked;
                            perm.CanDelete = ((CheckBox)row.FindControl("chkCanDelete")).Checked;
                            perm.CanModifyPermission = ((CheckBox)row.FindControl("chkCanModifyPermission")).Checked;
                            perm.FileID = objFile.ID;

                            int userID = Int32.Parse(row.Cells[8].Text);
                            int roleID = Int32.Parse(row.Cells[10].Text);
                            string userName = row.Cells[9].Text;
                            string roleName = row.Cells[11].Text;

                            if (userID > 0)
                            {
                                perm.UserID = userID;
                                perm.UserName = userName;
                            }

                            if (roleID > 0)
                            {
                                perm.RoleID = roleID;
                                perm.RoleName = roleName;
                            }

                            objQuickPermissions.Create(perm);
                        }
                    }

                //refresh cac
                SynchronizeModule();

                //Redirect back to the parent folder page
                //Redirect back to the portal home page

                string strItemType = "Folder";
                switch (ItemType)
                {
                    case 0:
                        strItemType = "Folder";
                        break;
                    case 1:
                        strItemType = "File";
                        break;
                    case 2:
                        strItemType = "Hyperlink";
                        break;
                }

                #region "Audit"
                //Audit: Create Item
                AuditController ctrlAudit = new AuditController();
                Audit createAudit = new Audit() { EventDate = objFile.CreatedDate, EventDetails = "File name: " + objFile.Name, EventName = "Created", FileID = objFile.ID, UserID = UserId };
                ctrlAudit.Create(createAudit);
                #endregion

                string successMessage = String.Format("Success=New {0} '{1}' created.", strItemType, objFile.Name);

                this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + objFile.ParentID, "ModuleID=" + ModuleId.ToString(), "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, successMessage), true);

            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
示例#3
0
        public File CreateUserFolder(int userID, int portalID, UserInfo currentUser)
        {
            FileController ctrl = new FileController();
            File rootUserFolder = new File();
            //rootUserFolder.ChildCount = 0;
            rootUserFolder.CreatedByUserID = currentUser.UserID;
            rootUserFolder.CreatedByUserName = currentUser.DisplayName;
            rootUserFolder.CreatedDate = System.DateTime.Now;
            rootUserFolder.IsInTrash = false;
            rootUserFolder.IsFolder = true;
            rootUserFolder.ItemType = 0;
            rootUserFolder.LastModifiedByUserID = currentUser.UserID;
            rootUserFolder.LastModifiedByUserName = currentUser.DisplayName;
            rootUserFolder.LastModifiedDate = System.DateTime.Now;
            UserController ctrlUser = new UserController();
            UserInfo user = ctrlUser.GetUser(portalID, userID);
            rootUserFolder.Name = user.DisplayName;
            rootUserFolder.ParentID = GetRootUsersFolder(portalID, userID).ID;
            rootUserFolder.PortalID = portalID;
            rootUserFolder.HomeFolderUserID = user.UserID;

            ctrl.Create(rootUserFolder);

            //all users read permission
            Permission AllUserspermission = new Permission();
            AllUserspermission.CanAddFiles = false;
            AllUserspermission.CanAddFolders = false;
            AllUserspermission.CanDelete = false;
            AllUserspermission.CanModify = false;
            AllUserspermission.CanModifyPermission = false;
            AllUserspermission.CanSee = true;
            AllUserspermission.FileID = rootUserFolder.ID;
            AllUserspermission.ModuleID = 0;
            AllUserspermission.PortalID = portalID;
            AllUserspermission.RoleID = 1000000;
            AllUserspermission.RoleName = "All Users";

            PermissionController ctrlPerm = new PermissionController();
            ctrlPerm.Create(AllUserspermission);

            //add user add items permission
            Permission userPermission = new Permission();
            userPermission.CanAddFiles = true;
            userPermission.CanAddFolders = true;
            userPermission.CanDelete = false;
            userPermission.CanModify = false;
            userPermission.CanModifyPermission = false;
            userPermission.CanSee = true;
            userPermission.FileID = rootUserFolder.ID;
            userPermission.ModuleID = 0;
            userPermission.PortalID = portalID;
            userPermission.UserID = user.UserID;
            userPermission.UserName = user.Username;

            ctrlPerm.Create(userPermission);

            return rootUserFolder;
        }
示例#4
0
        public File CreateRootSharedFolder(int userID, int portalID)
        {
            FileController ctrl = new FileController();
            UserController ctrlUser = new UserController();
            UserInfo user = ctrlUser.GetUser(portalID, userID);

            //create root shared folder
            File rootPortalFolder = new File();
            //rootPortalFolder.ChildCount = 0;
            rootPortalFolder.CreatedByUserID = userID;
            rootPortalFolder.CreatedByUserName = user.DisplayName;
            rootPortalFolder.CreatedDate = System.DateTime.Now;
            rootPortalFolder.IsInTrash = false;
            rootPortalFolder.IsFolder = true;
            rootPortalFolder.ItemType = 0;
            rootPortalFolder.LastModifiedByUserID = userID;
            rootPortalFolder.LastModifiedByUserName = user.DisplayName;
            rootPortalFolder.LastModifiedDate = System.DateTime.Now;
            rootPortalFolder.Name = "Site Root Folder";
            rootPortalFolder.Description = "";
            rootPortalFolder.ParentID = -1;
            rootPortalFolder.PortalID = portalID;

            ctrl.Create(rootPortalFolder);

            //add default permission
            PermissionController ctrlPerm = new PermissionController();
            Permission perm = new Permission();
            perm.CanAddFiles = true;
            perm.CanAddFolders = true;
            perm.CanSee = true;
            perm.FileID = rootPortalFolder.ID;
            perm.PortalID = portalID;
            perm.RoleID = 1000000;
            perm.RoleName = "All Users";

            ctrlPerm.Create(perm);

            //update files config
            FileConfigurationController ctrlConfig = new FileConfigurationController();
            var configs = ctrlConfig.GetItems(portalID) as List<FileConfiguration>;
            configs[0].RootUsersFolderID = rootPortalFolder.ID;
            ctrlConfig.Update(configs[0]);

            return rootPortalFolder;
        }
        private void ApplyPermissionsToDirectChildren(File file, List<Permission> filePermissions)
        {
            FileController fileCtrl = new FileController();
            PermissionController permCtrl = new PermissionController();
            //List<File> childFiles = fileCtrl.GetItemsByParent(file.ID, UserId, PortalId, PortalSettings.AdministratorRoleId, "");
            List<File> childFiles = fileCtrl.GetItems(file.ID) as List<File>;
            foreach (File childFile in childFiles)
            {
                //check edit permission
                if (childFile.CanEditPermissions(UserId, PortalId, PortalSettings.AdministratorRoleId, false))
                {
                    //delete existing permissions
                    List<Permission> deletePermissions = permCtrl.GetItems(childFile.ID) as List<Permission>;
                    foreach (Permission deletePermission in deletePermissions)
                    {
                        Permission permissionToDelete = permCtrl.Get(deletePermission.ID, childFile.ID);
                        permCtrl.Delete(permissionToDelete);
                    }

                    //add file permissions
                    foreach (Permission filePermission in filePermissions)
                    {
                        Permission newPermission = new Permission();
                        newPermission.ID = filePermission.ID;
                        newPermission.ModuleID = filePermission.ModuleID;
                        newPermission.PortalID = filePermission.PortalID;
                        newPermission.CanSee = filePermission.CanSee;
                        newPermission.CanModify = filePermission.CanModify;
                        newPermission.CanAddFiles = filePermission.CanAddFiles;
                        newPermission.CanAddFolders = filePermission.CanAddFolders;
                        newPermission.CanDelete = filePermission.CanDelete;
                        newPermission.CanModifyPermission = filePermission.CanModifyPermission;
                        newPermission.IsOwner = filePermission.IsOwner;
                        newPermission.RoleID = filePermission.RoleID;
                        newPermission.RoleName = filePermission.RoleName;
                        newPermission.UserID = filePermission.UserID;
                        newPermission.UserName = filePermission.UserName;

                        //assign new permission to child item
                        newPermission.FileID = childFile.ID;
                        permCtrl.Create(newPermission);
                    }

                    //report updated file
                    _updatedPermissionFiles.Add(childFile);
                }
                else
                {
                    //report non-updated file
                    _notUpdatedPermissionFiles.Add(childFile);
                }

                //do child files
                ApplyPermissionsToDirectChildren(childFile, filePermissions);
            }
        }
        protected void lbnOK_Click(object sender, EventArgs e)
        {
            try
            {

                ParentID = -1;
                if (this.Request.QueryString["Parent"] != null)
                {
                    ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                }

                if (this.Request.QueryString["View"] != null)
                {
                    _sourceView = this.Request.QueryString["View"];
                }

                if (this.Request.QueryString["ID"] != null)
                {
                    this.ItemID = Int32.Parse(this.Request.QueryString["ID"]);
                }
                else
                {
                    this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + ParentID.ToString(), "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, "Warning=Could not save updates.  File not found."), true);
                }

                //get file
                DNNQuickApps.Modules.QuickDocsPro.FileController objQuickFiles = new DNNQuickApps.Modules.QuickDocsPro.FileController();
                DNNQuickApps.Modules.QuickDocsPro.File objFile = objQuickFiles.Get(ItemID);
                objFile.ModuleID = ModuleId;
                objFile.LastModifiedDate = System.DateTime.Now;
                objFile.Name = txtName.Text;
                objFile.Description = txtDescription.Text;
                objFile.LastModifiedByUserID = UserId;

                //update link url
                if (objFile.ItemType == 2) //link
                {
                    objFile.LinkURL = txtHyperlink.Text;
                }

                if (UserId != -1)
                {
                    objFile.LastModifiedByUserName = UserInfo.DisplayName;
                }
                else
                {
                    objFile.LastModifiedByUserName = "******";
                }

                try
                {
                    objFile.VersionsToKeep = Int32.Parse(txtVersionsToKeep.Text);
                }
                catch
                {

                }

                if (objFile.CanEditPermissions(UserId, PortalId, PortalSettings.AdministratorRoleId, true))
                {
                    //delete existing permissions
                    PermissionController permCtrl = new PermissionController();
                    List<Permission> permissionsToDelete = permCtrl.GetItems(objFile.ID) as List<Permission>;
                    for (int i = 0; i < permissionsToDelete.Count; i++)
                    {
                        permCtrl.Delete(permissionsToDelete[i]);
                    }

                    //create updated permissions
                    PermissionController objQuickPermissions = new PermissionController();
                    foreach (GridViewRow row in gridPermissions.Rows)
                    {
                        if ((((CheckBox)row.FindControl("chkCanSee")).Checked))
                        {
                            Permission perm = new Permission();
                            perm.CanSee = true;
                            perm.CanAddFiles = ((CheckBox)row.FindControl("chkCanAddItems")).Checked;
                            perm.CanAddFolders = ((CheckBox)row.FindControl("chkCanAddFolders")).Checked;
                            perm.CanModify = ((CheckBox)row.FindControl("chkCanModify")).Checked;
                            perm.CanDelete = ((CheckBox)row.FindControl("chkCanDelete")).Checked;
                            perm.CanModifyPermission = ((CheckBox)row.FindControl("chkCanModifyPermission")).Checked;
                            perm.FileID = objFile.ID;

                            int userID = Int32.Parse(row.Cells[8].Text);
                            int roleID = Int32.Parse(row.Cells[10].Text);
                            string userName = row.Cells[9].Text;
                            string roleName = row.Cells[11].Text;

                            if (userID > 0)
                            {
                                perm.UserID = userID;
                                perm.UserName = userName;
                            }

                            if (roleID > 0)
                            {
                                perm.RoleID = roleID;
                                perm.RoleName = roleName;
                            }

                            objQuickPermissions.Create(perm);
                        }
                    }
                }

                objQuickFiles.Update(objFile);

                #region "Audit"
                //Audit: Updated Item
                AuditController ctrlAudit = new AuditController();
                Audit updatedAudit = new Audit() { EventDate = objFile.LastModifiedDate, EventDetails = "", EventName = "Updated", FileID = objFile.ID, UserID = UserId };
                ctrlAudit.Create(updatedAudit);
                #endregion

                //refresh cache
                SynchronizeModule();

                if (chkApplyToSubItems.Checked)
                {
                    //apply permissions to sub-items
                    ApplyPermissionsToSubItems(objFile);
                    return;
                }

                //Redirect back to the portal home page
                this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + ParentID.ToString(), "View=" + _sourceView, "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, "Success=Changes saved."), true);
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }