Example #1
0
 void ApplyInstructorsReadAccessPermissionsToDropBox(SPWeb web, DropBox dropBox)
 {
     foreach (SlkUser instructor in assignmentProperties.Instructors)
     {
         AssignmentFolder.ApplySharePointPermission(web, dropBox.DropBoxList, instructor.SPUser, SPRoleType.Reader);
     }
 }
Example #2
0
        /// <summary>Creates an assignment folder.</summary>
        public void CreateAssignmentFolder()
        {
            Microsoft.SharePoint.Utilities.SPUtility.ValidateFormDigest();

            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(assignmentProperties.SPSiteGuid))
                {
                    using (SPWeb spWeb = spSite.OpenWeb(assignmentProperties.SPWebGuid))
                    {
                        DropBox dropBox = new DropBox(store, spWeb);

                        //Get the folder if it exists
                        if (dropBox.GetAssignmentFolder(assignmentProperties) != null)
                        {
                            throw new SafeToDisplayException(culture.Resources.AssFolderAlreadyExists);
                        }

                        AssignmentFolder assignmentFolder = dropBox.CreateAssignmentFolder(assignmentProperties);
                        ApplyInstructorsReadAccessPermissions(assignmentFolder, spWeb, dropBox);

                        //Create a Subfolder for each learner
                        foreach (SlkUser learner in assignmentProperties.Learners)
                        {
                            SPUser spLearner = learner.SPUser;
                            assignmentFolder.ApplyPermission(spLearner, SPRoleType.Reader);
                            AssignmentFolder.ApplySharePointPermission(spWeb, dropBox.DropBoxList, learner.SPUser, SPRoleType.Reader);
                            assignmentFolder.CreateLearnerAssignmentFolder(spLearner);
                        }
                    }
                }
            });
        }
Example #3
0
        /// <summary>Creates an assignment folder.</summary>
        /// <returns>The created folder or null if it already exists.</returns>
        public AssignmentFolder CreateSelfAssignmentFolder()
        {
            AssignmentFolder assignmentFolder = null;

            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(assignmentProperties.SPSiteGuid))
                {
                    using (SPWeb spWeb = spSite.OpenWeb(assignmentProperties.SPWebGuid))
                    {
                        DropBox dropBox = new DropBox(store, spWeb);

                        //Get the folder if it exists
                        assignmentFolder = dropBox.GetAssignmentFolder(assignmentProperties);

                        //Create the assignment folder if it does not exist
                        if (assignmentFolder == null)
                        {
                            assignmentFolder = dropBox.CreateAssignmentFolder(assignmentProperties);
                            assignmentFolder.ApplyPermission(CurrentUser, SPRoleType.Reader);
                            assignmentFolder.CreateLearnerAssignmentFolder(CurrentUser);
                        }
                        else
                        {
                            assignmentFolder = null;
                        }
                    }
                }
            });
            return assignmentFolder;
        }
Example #4
0
 /// <summary>Returns all files for an assignment grouped by learner.</summary>
 public Dictionary<string, List<SPFile>> AllFiles()
 {
     using (SPSite site = new SPSite(assignmentProperties.SPSiteGuid, SPContext.Current.Site.Zone))
     {
         using (SPWeb web = site.OpenWeb(assignmentProperties.SPWebGuid))
         {
             DropBox dropBox = new DropBox(store, web);
             return dropBox.AllFiles(assignmentProperties.Id.GetKey());
         }
     }
 }
        void DeleteAssociatedView()
        {
            SPList dropBox = assignmentFolder.ParentList;

            try
            {
                SPView view = dropBox.Views[DropBox.AssignmentViewName(properties)];
                dropBox.Views.Delete(view.ID);
            }
            catch (ArgumentException)
            {
                // No view
            }
        }
Example #6
0
        /// <summary>Sets the correct permissions when the item is submitted.</summary>
        /// <param name="web">The web the assignment is for.</param>
        void ApplySubmittedPermissions(SPWeb web)
        {
            DropBox dropBox = new DropBox(store, web);
            AssignmentFolder assignmentFolder = dropBox.GetAssignmentFolder(assignmentProperties);

            if (assignmentFolder == null)
            {
                assignmentFolder = dropBox.CreateAssignmentFolder(assignmentProperties);
            }
            else
            {
                AssignmentFolder learnerSubFolder = assignmentFolder.FindLearnerFolder(CurrentUser);
                ApplySubmittedPermissions(learnerSubFolder);
            }
        }
Example #7
0
        /// <summary>Applies permissions to the learner folder and creates it if required.</summary>
        /// <param name="user">The learner to create the folder for.</param>
        /// <param name="learnerPermissions">The permissions to set.</param>
        /// <param name="instructorPermissions">The instructor permissions to set.</param>
        /// <param name="removeObserverPermissions">Whether to remove observer permissions or not.</param>
        void ApplyAssignmentPermission(SPUser user, SPRoleType learnerPermissions, SPRoleType instructorPermissions, bool removeObserverPermissions)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(assignmentProperties.SPSiteGuid))
                {
                    using (SPWeb spWeb = spSite.OpenWeb(assignmentProperties.SPWebGuid))
                    {
                        DropBox dropBox = new DropBox(store, spWeb);
                        AssignmentFolder assignmentFolder = dropBox.GetAssignmentFolder(assignmentProperties);

                        if (assignmentFolder != null)
                        {
                            // Get the learner sub folder
                            AssignmentFolder learnerSubFolder = assignmentFolder.FindLearnerFolder(user);

                            if (learnerSubFolder == null)
                            {
                                learnerSubFolder = assignmentFolder.CreateLearnerAssignmentFolder(user);
                            }

                            // Apply learner permissions
                            learnerSubFolder.RemovePermissions(user);
                            if (learnerPermissions != SPRoleType.None)
                            {
                                learnerSubFolder.ApplyPermission(user, learnerPermissions);
                            }

                            // Apply instructor permissions
                            foreach (SlkUser instructor in assignmentProperties.Instructors)
                            {
                                learnerSubFolder.RemovePermissions(instructor.SPUser);
                                learnerSubFolder.ApplyPermission(instructor.SPUser, instructorPermissions);
                            }

                            if (removeObserverPermissions)
                            {
                                learnerSubFolder.RemoveObserverPermission();
                            }
                        }
                    }
                }
            });
        }
Example #8
0
        /// <summary>Uploads files to the learner's drop box.</summary>
        /// <param name="files">The files to upload.</param>
        /// <param name="existingFilesToKeep">Existing files to keep.</param>
        public void UploadFiles(AssignmentUpload[] files, int[] existingFilesToKeep)
        {
            SPUser currentUser = CurrentUser;

            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(assignmentProperties.SPSiteGuid))
                {
                    spSite.CatchAccessDeniedException = false;
                    using (SPWeb spWeb = spSite.OpenWeb(assignmentProperties.SPWebGuid))
                    {
                        DropBox dropBox = new DropBox(store, spWeb);
                        AssignmentFolder assignmentFolder = dropBox.GetOrCreateAssignmentFolder(assignmentProperties);
                        assignmentFolder.ApplyPermission(currentUser, SPRoleType.Reader);

                        AssignmentFolder learnerSubFolder = assignmentFolder.FindLearnerFolder(currentUser);

                        if (learnerSubFolder == null)
                        {
                            learnerSubFolder = assignmentFolder.CreateLearnerAssignmentFolder(currentUser);
                        }
                        else
                        {
                            learnerSubFolder.ResetIsLatestFiles(existingFilesToKeep, currentUser.ID);
                        }

                        CheckExtensions(spSite, files);

                        using (new AllowUnsafeUpdates(spWeb))
                        {
                            SlkUser currentSlkUser = new SlkUser(currentUser);
                            foreach (AssignmentUpload upload in files)
                            {
                                learnerSubFolder.SaveFile(upload.Name, upload.Stream, currentSlkUser);
                            }
                        }

                        ApplySubmittedPermissions(spWeb);
                    }
                }
            });
        }
Example #9
0
        private AssignmentFile SaveFile(SPFile file)
        {
            AssignmentFile assignmentFile = null;
            using (SPSite destinationSite = new SPSite(assignmentProperties.SPSiteGuid))
            {
                destinationSite.CatchAccessDeniedException = false;
                using (SPWeb destinationWeb = destinationSite.OpenWeb(assignmentProperties.SPWebGuid))
                {
                    using (new AllowUnsafeUpdates(destinationWeb))
                    {
                        // Temporarily turn off property promotion. Possible cause for exceptions saving docs. I don't actually know
                        // if settings this will disable it as without an update it's not persisted and we don't want to persist the
                        // setting, just turn it off for this addition. It may even work asynchronously.
                        destinationWeb.ParserEnabled = false;
                        SPUser learner = CurrentUser;
                        DropBox dropBox = new DropBox(store, destinationWeb);
                        AssignmentFolder assignmentFolder = dropBox.GetAssignmentFolder(assignmentProperties);
                        AssignmentFolder learnerSubFolder = null;

                        if (assignmentFolder == null)
                        {
                            assignmentFolder = dropBox.CreateAssignmentFolder(assignmentProperties);
                        }

                        // ApplyAssignmentPermission creates the learner folder if required
                        ApplyAssignmentPermission(learner, SPRoleType.Contributor, SPRoleType.Reader, true);
                        learnerSubFolder = assignmentFolder.FindLearnerFolder(learner);

                        using (Stream stream = file.OpenBinaryStream())
                        {
                            assignmentFile = learnerSubFolder.SaveFile(file.Name, stream, new SlkUser(learner));
                        }
                    }
                }
            }

            return assignmentFile;
        }
Example #10
0
        /// <summary>Initializes a new instance of <see cref="AssignmentDownloader"/>.</summary>
        /// <param name="assignmentProperties">The assignment properties</param>
        public AssignmentDownloader(AssignmentProperties assignmentProperties)
        {
            // Create temporary folder
            tempFolder = Path.Combine(Path.Combine(Path.GetTempPath(), "SLK_Temp"), Guid.NewGuid().ToString());
            Directory.CreateDirectory(tempFolder);

            // Create assignment folder
            string assignmentFolderName = DropBox.GenerateFolderName(assignmentProperties);
            string assignmentFolderPath = Path.Combine(tempFolder, assignmentFolderName);

            Directory.CreateDirectory(assignmentFolderPath);

            // TODO: Potential clash here if 2 people download at same time
            zippedFilePath = Path.Combine(tempFolder, assignmentFolderName + ".zip");

            ExtractAssignmentsFromSharePoint(assignmentProperties, assignmentFolderPath);

            FastZip zipper = new FastZip();

            zipper.CreateZip(zippedFilePath, assignmentFolderPath, true, null);

            zippedFileName = assignmentFolderName;
        }
Example #11
0
        /// <summary>Returns the last submitted files for the given learner.</summary>
        public AssignmentFile[] LastSubmittedFiles(SPUser user, bool forceUnlock)
        {
            if (user == null)
            {
                return null;
            }

            int currentUser = CurrentUser.ID;

            AssignmentFile[] toReturn = null;
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(assignmentProperties.SPSiteGuid))
                {
                    using (SPWeb spWeb = spSite.OpenWeb(assignmentProperties.SPWebGuid))
                    {
                        DropBox dropBox = new DropBox(store, spWeb);
                        toReturn = dropBox.LastSubmittedFiles(new SlkUser(user), assignmentProperties.Id.GetKey(), forceUnlock, currentUser);
                    }
                }
            });
            return toReturn;
        }
Example #12
0
        /// <summary>Deletes the assignment folder.</summary>
        public void DeleteAssignmentFolder()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(assignmentProperties.SPSiteGuid))
                {
                    using (SPWeb spWeb = spSite.OpenWeb(assignmentProperties.SPWebGuid))
                    {
                        DropBox dropBox = new DropBox(store, spWeb);

                        //Get the folder if it exists
                        AssignmentFolder assignmentFolder = dropBox.GetAssignmentFolder(assignmentProperties);

                        if (assignmentFolder != null)
                        {
                            using (new AllowUnsafeUpdates(spWeb))
                            {
                                assignmentFolder.Delete();
                            }
                        }
                    }
                }
            });
        }
Example #13
0
 /// <summary>Clears the permissions on a folder.</summary>
 /// <param name="folder">The folder to clear the permissions for.</param>
 public static void ClearPermissions(SPListItem folder)
 {
     DropBox.RemoveRoleAssignments(folder, folder.ParentList.ParentWeb);
     folder.Update();
 }
Example #14
0
 void ClearPermissions()
 {
     DropBox.RemoveRoleAssignments(dropBoxList, web);
 }
        static string LearnerFolderName(SPUser learner)
        {
            string folderName = learner.LoginName;

            return(DropBox.MakeTitleSafe(folderName));
        }
Example #16
0
 void ApplyInstructorsReadAccessPermissions(AssignmentFolder folder, SPWeb web, DropBox dropBox)
 {
     // In one instance had an issue that instructors couldn't see uploaded assignments in OWA if they
     // didn't have read access on the drop box.
     ApplyInstructorsReadAccessPermissionsToDropBox(web, dropBox);
     ApplyInstructorsReadAccessPermissions(folder);
 }
Example #17
0
        /// <summary>Function to update the DropBox document library after the current assignment being edited</summary>
        /// <param name="oldAssignmentProperties">The old assignment properties</param>
        public void UpdateAssignment(AssignmentProperties oldAssignmentProperties)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(assignmentProperties.SPSiteGuid))
                {
                    using (SPWeb spWeb = spSite.OpenWeb(assignmentProperties.SPWebGuid))
                    {
                        using (new AllowUnsafeUpdates(spWeb))
                        {
                            DropBox dropBox = new DropBox(store, spWeb);

                            string oldAssignmentFolderName = DropBox.GenerateFolderName(oldAssignmentProperties);
                            string newAssignmentFolderName = DropBox.GenerateFolderName(assignmentProperties);

                            // If assignment title has been changed, create a new assignment folder and move old assignment folder contents to it
                            if (string.Compare(oldAssignmentFolderName,  newAssignmentFolderName, true, CultureInfo.InvariantCulture) != 0)
                            {
                                dropBox.ChangeFolderName(oldAssignmentFolderName, newAssignmentFolderName);
                            }

                            // Get new assignment folder, or the old one if the title has not been changed
                            // in both cases, the value of the current assignment folder name will be stored in newAssignmentFolderName
                            AssignmentFolder assignmentFolder = dropBox.GetAssignmentFolder(assignmentProperties);

                            if (assignmentFolder != null)
                            {
                                assignmentFolder.RemoveAllPermissions();

                                // Grant assignment instructors Read permission on the assignment folder
                                ApplyInstructorsReadAccessPermissions(assignmentFolder, spWeb, dropBox);

                                // Delete subfolders of the learners who have been removed from the assignment
                                DeleteRemovedLearnerFolders(assignmentFolder, oldAssignmentProperties);

                                foreach (SlkUser learner in assignmentProperties.Learners)
                                {
                                    // Grant assignment learners Read permission on the assignment folder and drop box
                                    assignmentFolder.ApplyPermission(learner.SPUser, SPRoleType.Reader);
                                    AssignmentFolder.ApplySharePointPermission(spWeb, dropBox.DropBoxList, learner.SPUser, SPRoleType.Reader);

                                    AssignmentFolder learnerSubFolder = assignmentFolder.FindLearnerFolder(learner.SPUser);
                                    LearnerAssignmentProperties result = assignmentProperties.ResultForLearner(learner);

                                    if (learnerSubFolder == null)
                                    {
                                        // Create a new subfolder for this learner
                                        learnerSubFolder = assignmentFolder.CreateLearnerAssignmentFolder(learner.SPUser);
                                    }

                                    if (result != null)
                                    {
                                        AssignUpdatePermissions(learnerSubFolder, learner.SPUser, result.Status);
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }