/// <summary>
        /// The add section to user group.
        /// </summary>
        /// <param name="formulateSection">
        /// The formulate section.
        /// </param>
        /// <param name="userGroup">
        /// The user group.
        /// </param>
        private void AddSectionToUserGroup(ISection formulateSection, IUserGroup userGroup)
        {
            if (userGroup == null)
            {
                Logger.Warn <HandleInstallAndUpgradeComponent>(
                    $"Skipping permit access. No user group was found.");
                return;
            }

            if (userGroup.AllowedSections.Contains(formulateSection.Alias))
            {
                Logger.Info <HandleInstallAndUpgradeComponent>(
                    $"Skipping permit access. {formulateSection.Name} Section already exists on User Group, {userGroup.Name}.");
                return;
            }

            try
            {
                userGroup.AddAllowedSection(formulateSection.Alias);
                UserService.Save(userGroup);

                Logger.Info <HandleInstallAndUpgradeComponent>(
                    $"Successfully added {formulateSection.Name} Section to User Group, {userGroup.Name}.");
            }
            catch (Exception ex)
            {
                Logger.Error <HandleInstallAndUpgradeComponent>(ex, $"Error adding {formulateSection.Name} Section to User Group, {userGroup.Name}.");
            }
        }
示例#2
0
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext context)
        {
            //Check to see if appSetting AnalyticsStartupInstalled is true or even present
            string installAppSetting = WebConfigurationManager.AppSettings[AppSettingKey];

            if (string.IsNullOrEmpty(installAppSetting) || installAppSetting != true.ToString())
            {
                var install = new Helpers.Installer();

                //Check to see if section needs to be added
                install.AddSection(context);

                //Add Section Dashboard XML
                install.AddSectionDashboard();

                //Add Content dashboard XML
                install.AddContentSectionDashboard();

                // Grant the admin group access to the worfklow section
                //since the app is starting, we don't have a current user. Safest assumption is the installer was an admin
                IUserGroup adminGroup = context.Services.UserService.GetUserGroupByAlias("admin");
                adminGroup.AddAllowedSection("workflow");
                context.Services.UserService.Save(adminGroup, null, false);

                //All done installing our custom stuff
                //As we only want this to run once - not every startup of Umbraco
                Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("/");
                webConfig.AppSettings.Settings.Add(AppSettingKey, true.ToString());
                webConfig.Save();
            }

            //Add OLD Style Package Event
            InstalledPackage.BeforeDelete += InstalledPackage_BeforeDelete;
        }
示例#3
0
        public bool Execute(string packageName, XElement xmlData)
        {
            //Add Fastly section to admin group on install
            IUserGroup adminGroup = Current.Services.UserService.GetUserGroupByAlias("admin");

            adminGroup.AddAllowedSection("fastlyUmbraco");

            return(true);
        }
        public void Can_Add_And_Remove_Sections_From_UserGroup()
        {
            var userGroup = new UserGroup(ShortStringHelper)
            {
                Alias = "Group1",
                Name  = "Group 1"
            };

            userGroup.AddAllowedSection("content");
            userGroup.AddAllowedSection("mediat");
            UserService.Save(userGroup);

            IUserGroup result1 = UserService.GetUserGroupById(userGroup.Id);

            Assert.AreEqual(2, result1.AllowedSections.Count());

            // adds some allowed sections
            userGroup.AddAllowedSection("test1");
            userGroup.AddAllowedSection("test2");
            userGroup.AddAllowedSection("test3");
            userGroup.AddAllowedSection("test4");
            UserService.Save(userGroup);

            result1 = UserService.GetUserGroupById(userGroup.Id);

            Assert.AreEqual(6, result1.AllowedSections.Count());

            // simulate clearing the sections
            foreach (string s in userGroup.AllowedSections)
            {
                result1.RemoveAllowedSection(s);
            }

            // now just re-add a couple
            result1.AddAllowedSection("test3");
            result1.AddAllowedSection("test4");
            UserService.Save(result1);

            // Assert
            // re-get
            result1 = UserService.GetUserGroupById(userGroup.Id);
            Assert.AreEqual(2, result1.AllowedSections.Count());
        }
示例#5
0
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext context)
        {
            //Check to see if appSetting is true or even present
            string installAppSetting = WebConfigurationManager.AppSettings[Constants.AppSettingKey];

            if (string.IsNullOrEmpty(installAppSetting))
            {
                //Check to see if section needs to be added
                Installer.AddSection(context);

                //Add Section Dashboard XML
                Installer.AddSectionDashboard();

                //Add Content dashboard XML
                Installer.AddContentSectionDashboard();

                // Grant the admin group access to the worfklow section
                //since the app is starting, we don't have a current user. Safest assumption is the installer was an admin
                IUserGroup adminGroup = context.Services.UserService.GetUserGroupByAlias("admin");
                adminGroup.AddAllowedSection("workflow");
                context.Services.UserService.Save(adminGroup, null, false);

                //All done installing our custom stuff
                //As we only want this to run once - not every startup of Umbraco
                Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("/");
                webConfig.AppSettings.Settings.Add(Constants.AppSettingKey, true.ToString());
                webConfig.Save();
            }

            //Add OLD Style Package Event
            InstalledPackage.BeforeDelete += InstalledPackage_BeforeDelete;

            ServerVariablesParser.Parsing += ServerVariablesParser_Parsing;

            // add route for offline-preview
            RouteTable.Routes.MapUmbracoRoute(
                "OfflinePreviewRoute",
                "workflow-preview/{nodeId}/{userId}/{taskid}/{guid}",
                new
            {
                controller = "OfflinePreview",
                action     = "Index",
                nodeId     = UrlParameter.Optional,
                userId     = UrlParameter.Optional,
                taskId     = UrlParameter.Optional,
                guid       = UrlParameter.Optional
            },
                new RouteHandler());
        }