Exemple #1
0
 void ApplyInstructorsReadAccessPermissionsToDropBox(SPWeb web, DropBox dropBox)
 {
     foreach (SlkUser instructor in assignmentProperties.Instructors)
     {
         AssignmentFolder.ApplySharePointPermission(web, dropBox.DropBoxList, instructor.SPUser, SPRoleType.Reader);
     }
 }
Exemple #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);
                        }
                    }
                }
            });
        }
Exemple #3
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);
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }