コード例 #1
0
        void AssignUpdatePermissions(AssignmentFolder folder, SPUser learner, LearnerAssignmentState? status)
        {
            folder.RemoveAllPermissions();

            if (status != null)
            {
                switch (status.Value)
                {
                    case LearnerAssignmentState.NotStarted:
                        break;

                    case LearnerAssignmentState.Active:
                        ApplyInstructorsReadAccessPermissions(folder);
                        folder.ApplyPermission(learner, SPRoleType.Contributor);
                        break;

                    case LearnerAssignmentState.Completed:
                        ApplyInstructorsContributeAccessPermissions(folder);
                        break;

                    case LearnerAssignmentState.Final:
                        ApplyInstructorsReadAccessPermissions(folder);
                        folder.ApplyPermission(learner, SPRoleType.Reader);
                        break;
                }
            }
        }
コード例 #2
0
 void ApplyInstructorsReadAccessPermissions(AssignmentFolder folder)
 {
     foreach (SlkUser instructor in assignmentProperties.Instructors)
     {
         folder.ApplyPermission(instructor.SPUser, SPRoleType.Reader);
     }
 }
コード例 #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;
        }
コード例 #4
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);
                        }
                    }
                }
            });
        }
コード例 #5
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();
                            }
                        }
                    }
                }
            });
        }
コード例 #6
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);
                    }
                }
            });
        }
コード例 #7
0
        void ApplySubmittedPermissions(AssignmentFolder learnerSubFolder)
        {
            // IF the assignment is auto return, the learner will still be able to view the drop box assignment files
            // otherwise, learner permissions will be removed from the learner's subfolder in the Drop Box document library
            if (assignmentProperties.AutoReturn == false)
            {
                learnerSubFolder.RemovePermissions(CurrentUser);
            }

            // Grant instructors contribute permission on learner subfolder
            foreach (SlkUser instructor in assignmentProperties.Instructors)
            {
                if (instructor.SPUser == null)
                {
                    throw new SafeToDisplayException(string.Format(culture.Culture, culture.Resources.DropBoxManagerUploadFilesNoInstructor, instructor.Name));
                }
                learnerSubFolder.RemovePermissions(instructor.SPUser);
                learnerSubFolder.ApplyPermission(instructor.SPUser, SPRoleType.Contributor);
            }
        }
コード例 #8
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);
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }