Ejemplo n.º 1
0
        /// <summary>
        /// Sets the default permissions for the anonymous users group in the given wiki, properly importing version 2.0 values.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <param name="anonymous">The anonymous users group.</param>
        /// <returns><c>true</c> if the operation succeeded, <c>false</c> otherwise.</returns>
        public static bool SetAnonymousGroupDefaultPermissions(string wiki, UserGroup anonymous)
        {
            bool done = true;

            AuthWriter authWriter = new AuthWriter(Collectors.CollectorsBox.GetSettingsProvider(wiki));

            // Properly import Private/Public Mode wiki
            if (Settings.GetPrivateAccess(wiki))
            {
                // Nothing to do, because without any explicit grant, Anonymous users cannot do anything
            }
            else if (Settings.GetPublicAccess(wiki))
            {
                // Public access, allow modification and propagate file management permissions if they were allowed for anonymous users
                done &= authWriter.SetPermissionForNamespace(AuthStatus.Grant, null, Actions.ForNamespaces.ModifyPages, anonymous);
                done &= authWriter.SetPermissionForNamespace(AuthStatus.Grant, null, Actions.ForNamespaces.DownloadAttachments, anonymous);
                if (Settings.GetUsersCanCreateNewPages(wiki))
                {
                    done &= authWriter.SetPermissionForNamespace(AuthStatus.Grant, null, Actions.ForNamespaces.CreatePages, anonymous);
                }
                if (Settings.GetUsersCanCreateNewCategories(wiki) || Settings.GetUsersCanManagePageCategories(wiki))
                {
                    done &= authWriter.SetPermissionForNamespace(AuthStatus.Grant, null, Actions.ForNamespaces.ManageCategories, anonymous);
                }
                if (Settings.GetFileManagementInPublicAccessAllowed(wiki))
                {
                    SetupFileManagementPermissions(wiki, anonymous);
                }
            }
            else
            {
                // Standard configuration, only allow read permissions
                done &= authWriter.SetPermissionForNamespace(AuthStatus.Grant, null, Actions.ForNamespaces.ReadPages, anonymous);
                done &= authWriter.SetPermissionForNamespace(AuthStatus.Grant, null, Actions.ForNamespaces.ReadDiscussion, anonymous);
                done &= authWriter.SetPermissionForNamespace(AuthStatus.Grant, null, Actions.ForNamespaces.DownloadAttachments, anonymous);

                foreach (IFilesStorageProviderV60 prov in Collectors.CollectorsBox.FilesProviderCollector.GetAllProviders(wiki))
                {
                    done &= authWriter.SetPermissionForDirectory(AuthStatus.Grant, prov, "/", Actions.ForDirectories.DownloadFiles, anonymous);
                }
            }

            return(done);
        }