Exemplo n.º 1
0
    /// <summary>
    ///     Returns a collection of all menu items that can be on a content node
    /// </summary>
    /// <param name="item"></param>
    /// <returns></returns>
    protected MenuItemCollection GetAllNodeMenuItems(IUmbracoEntity item)
    {
        MenuItemCollection menu = _menuItemCollectionFactory.Create();

        AddActionNode <ActionNew>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionDelete>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionCreateBlueprintFromContent>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionMove>(item, menu, hasSeparator: true, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionCopy>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionSort>(item, menu, hasSeparator: true, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionAssignDomain>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionRights>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionProtect>(item, menu, hasSeparator: true, opensDialog: true, useLegacyIcon: false);

        if (_emailSender.CanSendRequiredEmail())
        {
            menu.Items.Add(new MenuItem("notify", LocalizedTextService)
            {
                Icon            = "icon-megaphone",
                SeparatorBefore = true,
                OpensDialog     = true,
                UseLegacyIcon   = false
            });
        }

        if ((item is DocumentEntitySlim documentEntity && documentEntity.IsContainer) == false)
        {
            menu.Items.Add(new RefreshNode(LocalizedTextService, true));
        }

        return(menu);
    }
        /// <summary>
        /// Returns a collection of all menu items that can be on a content node
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected MenuItemCollection GetAllNodeMenuItems(IUmbracoEntity item)
        {
            var menu = _menuItemCollectionFactory.Create();

            AddActionNode <ActionNew>(item, menu, opensDialog: true);
            AddActionNode <ActionDelete>(item, menu, opensDialog: true);
            AddActionNode <ActionCreateBlueprintFromContent>(item, menu, opensDialog: true);
            AddActionNode <ActionMove>(item, menu, true, opensDialog: true);
            AddActionNode <ActionCopy>(item, menu, opensDialog: true);
            AddActionNode <ActionSort>(item, menu, true, opensDialog: true);
            AddActionNode <ActionAssignDomain>(item, menu, opensDialog: true);
            AddActionNode <ActionRights>(item, menu, opensDialog: true);
            AddActionNode <ActionProtect>(item, menu, true, opensDialog: true);

            if (_emailSender.CanSendRequiredEmail())
            {
                AddActionNode <ActionNotify>(item, menu, true, opensDialog: true);
            }

            if ((item is DocumentEntitySlim documentEntity && documentEntity.IsContainer) == false)
            {
                menu.Items.Add(new RefreshNode(LocalizedTextService, true));
            }

            return(menu);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the server variables for authenticated users
        /// </summary>
        /// <returns></returns>
        internal async Task <Dictionary <string, object> > GetServerVariablesAsync()
        {
            var globalSettings           = _globalSettings;
            var backOfficeControllerName = ControllerExtensions.GetControllerName <BackOfficeController>();
            var defaultVals = new Dictionary <string, object>
            {
                {
                    "umbracoUrls", new Dictionary <string, object>
                    {
                        // TODO: Add 'umbracoApiControllerBaseUrl' which people can use in JS
                        // to prepend their URL. We could then also use this in our own resources instead of
                        // having each URL defined here explicitly - we can do that in v8! for now
                        // for umbraco services we'll stick to explicitly defining the endpoints.

                        { "externalLoginsUrl", _linkGenerator.GetPathByAction(nameof(BackOfficeController.ExternalLogin), backOfficeControllerName, new { area = Constants.Web.Mvc.BackOfficeArea }) },
                        { "externalLinkLoginsUrl", _linkGenerator.GetPathByAction(nameof(BackOfficeController.LinkLogin), backOfficeControllerName, new { area = Constants.Web.Mvc.BackOfficeArea }) },
                        { "gridConfig", _linkGenerator.GetPathByAction(nameof(BackOfficeController.GetGridConfig), backOfficeControllerName, new { area = Constants.Web.Mvc.BackOfficeArea }) },
                        // TODO: This is ultra confusing! this same key is used for different things, when returning the full app when authenticated it is this URL but when not auth'd it's actually the ServerVariables address
                        { "serverVarsJs", _linkGenerator.GetPathByAction(nameof(BackOfficeController.Application), backOfficeControllerName, new { area = Constants.Web.Mvc.BackOfficeArea }) },
                        //API URLs
                        {
                            "packagesRestApiBaseUrl", Constants.PackageRepository.RestApiBaseUrl
                        },
                        {
                            "redirectUrlManagementApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <RedirectUrlManagementController>(
                                controller => controller.GetEnableState())
                        },
                        {
                            "tourApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <TourController>(
                                controller => controller.GetTours())
                        },
                        {
                            "embedApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <RteEmbedController>(
                                controller => controller.GetEmbed("", 0, 0))
                        },
                        {
                            "userApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <UsersController>(
                                controller => controller.PostSaveUser(null))
                        },
                        {
                            "userGroupsApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <UserGroupsController>(
                                controller => controller.PostSaveUserGroup(null))
                        },
                        {
                            "contentApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <ContentController>(
                                controller => controller.PostSave(null))
                        },
                        {
                            "publicAccessApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <PublicAccessController>(
                                controller => controller.GetPublicAccess(0))
                        },
                        {
                            "mediaApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MediaController>(
                                controller => controller.GetRootMedia())
                        },
                        {
                            "iconApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <IconController>(
                                controller => controller.GetIcon(""))
                        },
                        {
                            "imagesApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <ImagesController>(
                                controller => controller.GetBigThumbnail(""))
                        },
                        {
                            "sectionApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <SectionController>(
                                controller => controller.GetSections())
                        },
                        {
                            "treeApplicationApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <ApplicationTreeController>(
                                controller => controller.GetApplicationTrees(null, null, null, TreeUse.None))
                        },
                        {
                            "contentTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <ContentTypeController>(
                                controller => controller.GetAllowedChildren(0))
                        },
                        {
                            "mediaTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MediaTypeController>(
                                controller => controller.GetAllowedChildren(0))
                        },
                        {
                            "macroRenderingApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MacroRenderingController>(
                                controller => controller.GetMacroParameters(0))
                        },
                        {
                            "macroApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MacrosController>(
                                controller => controller.Create(null))
                        },
                        {
                            "authenticationApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <AuthenticationController>(
                                controller => controller.PostLogin(null))
                        },
                        {
                            "currentUserApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <CurrentUserController>(
                                controller => controller.PostChangePassword(null))
                        },
                        {
                            "entityApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <EntityController>(
                                controller => controller.GetById(0, UmbracoEntityTypes.Media))
                        },
                        {
                            "dataTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <DataTypeController>(
                                controller => controller.GetById(0))
                        },
                        {
                            "dashboardApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <DashboardController>(
                                controller => controller.GetDashboard(null))
                        },
                        {
                            "logApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <LogController>(
                                controller => controller.GetPagedEntityLog(0, 0, 0, Direction.Ascending, null))
                        },
                        {
                            "memberApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MemberController>(
                                controller => controller.GetByKey(Guid.Empty))
                        },
                        {
                            "packageApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <PackageController>(
                                controller => controller.GetCreatedPackages())
                        },
                        {
                            "relationApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <RelationController>(
                                controller => controller.GetById(0))
                        },
                        {
                            "rteApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <RichTextPreValueController>(
                                controller => controller.GetConfiguration())
                        },
                        {
                            "stylesheetApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <StylesheetController>(
                                controller => controller.GetAll())
                        },
                        {
                            "memberTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MemberTypeController>(
                                controller => controller.GetAllTypes())
                        },
                        {
                            "memberTypeQueryApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MemberTypeQueryController>(
                                controller => controller.GetAllTypes())
                        },
                        {
                            "memberGroupApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MemberGroupController>(
                                controller => controller.GetAllGroups())
                        },
                        {
                            "updateCheckApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <UpdateCheckController>(
                                controller => controller.GetCheck())
                        },
                        {
                            "templateApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <TemplateController>(
                                controller => controller.GetById(0))
                        },
                        {
                            "memberTreeBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MemberTreeController>(
                                controller => controller.GetNodes("-1", null))
                        },
                        {
                            "mediaTreeBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <MediaTreeController>(
                                controller => controller.GetNodes("-1", null))
                        },
                        {
                            "contentTreeBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <ContentTreeController>(
                                controller => controller.GetNodes("-1", null))
                        },
                        {
                            "tagsDataBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <TagsDataController>(
                                controller => controller.GetTags("", "", null))
                        },
                        {
                            "examineMgmtBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <ExamineManagementController>(
                                controller => controller.GetIndexerDetails())
                        },
                        {
                            "healthCheckBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <HealthCheckController>(
                                controller => controller.GetAllHealthChecks())
                        },
                        {
                            "templateQueryApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <TemplateQueryController>(
                                controller => controller.PostTemplateQuery(null))
                        },
                        {
                            "codeFileApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <CodeFileController>(
                                controller => controller.GetByPath("", ""))
                        },
                        {
                            "publishedStatusBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <PublishedStatusController>(
                                controller => controller.GetPublishedStatusUrl())
                        },
                        {
                            "dictionaryApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <DictionaryController>(
                                controller => controller.DeleteById(int.MaxValue))
                        },
                        {
                            "publishedSnapshotCacheStatusBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <PublishedSnapshotCacheStatusController>(
                                controller => controller.GetStatus())
                        },
                        {
                            "helpApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <HelpController>(
                                controller => controller.GetContextHelpForPage("", "", ""))
                        },
                        {
                            "backOfficeAssetsApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <BackOfficeAssetsController>(
                                controller => controller.GetSupportedLocales())
                        },
                        {
                            "languageApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <LanguageController>(
                                controller => controller.GetAllLanguages())
                        },
                        {
                            "relationTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <RelationTypeController>(
                                controller => controller.GetById(1))
                        },
                        {
                            "logViewerApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <LogViewerController>(
                                controller => controller.GetNumberOfErrors(null, null))
                        },
                        {
                            "webProfilingBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <WebProfilingController>(
                                controller => controller.GetStatus())
                        },
                        {
                            "tinyMceApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <TinyMceController>(
                                controller => controller.UploadImage(null))
                        },
                        {
                            "imageUrlGeneratorApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <ImageUrlGeneratorController>(
                                controller => controller.GetCropUrl(null, null, null, null))
                        },
                        {
                            "elementTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <ElementTypeController>(
                                controller => controller.GetAll())
                        },
                        {
                            "previewHubUrl", _previewRoutes.GetPreviewHubRoute()
                        },
                        {
                            "trackedReferencesApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl <TrackedReferencesController>(
                                controller => controller.GetPagedReferences(0, 1, 1, false))
                        }
                    }
                },
                {
                    "umbracoSettings", new Dictionary <string, object>
                    {
                        { "umbracoPath", _globalSettings.GetBackOfficePath(_hostingEnvironment) },
                        { "mediaPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoMediaPath).TrimEnd(Constants.CharArrays.ForwardSlash) },
                        { "appPluginsPath", _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.AppPlugins).TrimEnd(Constants.CharArrays.ForwardSlash) },
                        {
                            "imageFileTypes",
                            string.Join(",", _imageUrlGenerator.SupportedImageFileTypes)
                        },
                        {
                            "disallowedUploadFiles",
                            string.Join(",", _contentSettings.DisallowedUploadFiles)
                        },
                        {
                            "allowedUploadFiles",
                            string.Join(",", _contentSettings.AllowedUploadFiles)
                        },
                        {
                            "maxFileSize",
                            GetMaxRequestLength()
                        },
                        { "keepUserLoggedIn", _securitySettings.KeepUserLoggedIn },
                        { "usernameIsEmail", _securitySettings.UsernameIsEmail },
                        { "cssPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoCssPath).TrimEnd(Constants.CharArrays.ForwardSlash) },
                        { "allowPasswordReset", _securitySettings.AllowPasswordReset },
                        { "loginBackgroundImage", _contentSettings.LoginBackgroundImage },
                        { "loginLogoImage", _contentSettings.LoginLogoImage },
                        { "hideBackofficeLogo", _contentSettings.HideBackOfficeLogo },
                        { "disableDeleteWhenReferenced", _contentSettings.DisableDeleteWhenReferenced },
                        { "disableUnpublishWhenReferenced", _contentSettings.DisableUnpublishWhenReferenced },
                        { "showUserInvite", _emailSender.CanSendRequiredEmail() },
                        { "canSendRequiredEmail", _emailSender.CanSendRequiredEmail() },
                        { "showAllowSegmentationForDocumentTypes", false },
                        { "minimumPasswordLength", _memberPasswordConfigurationSettings.RequiredLength },
                        { "minimumPasswordNonAlphaNum", _memberPasswordConfigurationSettings.GetMinNonAlphaNumericChars() },
                        { "sanitizeTinyMce", _globalSettings.SanitizeTinyMce }
                    }
                },
                {
                    "umbracoPlugins", new Dictionary <string, object>
                    {
                        // for each tree that is [PluginController], get
                        // alias -> areaName
                        // so that routing (route.js) can look for views
                        { "trees", GetPluginTrees().ToArray() }
                    }
                },
                {
                    "isDebuggingEnabled", _hostingEnvironment.IsDebugMode
                },
                {
                    "application", GetApplicationState()
                },
                {
                    "externalLogins", new Dictionary <string, object>
                    {
                        {
                            // TODO: It would be nicer to not have to manually translate these properties
                            // but then needs to be changed in quite a few places in angular
                            "providers", (await _externalLogins.GetBackOfficeProvidersAsync())
                            .Select(p => new
                            {
                                authType   = p.ExternalLoginProvider.AuthenticationType,
                                caption    = p.AuthenticationScheme.DisplayName,
                                properties = p.ExternalLoginProvider.Options
                            })
                            .ToArray()
                        }
                    }
                },
                {
                    "features", new Dictionary <string, object>
                    {
                        {
                            "disabledFeatures", new Dictionary <string, object>
                            {
                                { "disableTemplates", _features.Disabled.DisableTemplates }
                            }
                        }
                    }
                }
            };

            return(defaultVals);
        }
Exemplo n.º 4
0
    /// <summary>
    ///     Invites a user
    /// </summary>
    /// <param name="userSave"></param>
    /// <returns></returns>
    /// <remarks>
    ///     This will email the user an invite and generate a token that will be validated in the email
    /// </remarks>
    public async Task<ActionResult<UserDisplay?>> PostInviteUser(UserInvite userSave)
    {
        if (userSave == null)
        {
            throw new ArgumentNullException(nameof(userSave));
        }

        if (userSave.Message.IsNullOrWhiteSpace())
        {
            ModelState.AddModelError("Message", "Message cannot be empty");
        }

        if (_securitySettings.UsernameIsEmail)
        {
            // ensure it's the same
            userSave.Username = userSave.Email;
        }
        else
        {
            // first validate the username if we're showing it
            ActionResult<IUser?> userResult = CheckUniqueUsername(userSave.Username,
                u => u.LastLoginDate != default || u.EmailConfirmedDate.HasValue);
            if (userResult.Result is not null)
            {
                return userResult.Result;
            }
        }

        IUser? user = CheckUniqueEmail(userSave.Email,
            u => u.LastLoginDate != default || u.EmailConfirmedDate.HasValue);

        if (ModelState.IsValid == false)
        {
            return ValidationProblem(ModelState);
        }

        if (!_emailSender.CanSendRequiredEmail())
        {
            return ValidationProblem("No Email server is configured");
        }

        // Perform authorization here to see if the current user can actually save this user with the info being requested
        Attempt<string?> canSaveUser = _userEditorAuthorizationHelper.IsAuthorized(
            _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser, user, null, null, userSave.UserGroups);
        if (canSaveUser == false)
        {
            return ValidationProblem(canSaveUser.Result, StatusCodes.Status401Unauthorized);
        }

        if (user == null)
        {
            // we want to create the user with the UserManager, this ensures the 'empty' (special) password
            // format is applied without us having to duplicate that logic
            var identityUser = BackOfficeIdentityUser.CreateNew(_globalSettings, userSave.Username, userSave.Email,
                _globalSettings.DefaultUILanguage);
            identityUser.Name = userSave.Name;

            IdentityResult created = await _userManager.CreateAsync(identityUser);
            if (created.Succeeded == false)
            {
                return ValidationProblem(created.Errors.ToErrorMessage());
            }

            // now re-look the user back up
            user = _userService.GetByEmail(userSave.Email);
        }

        // map the save info over onto the user
        user = _umbracoMapper.Map(userSave, user);

        if (user is not null)
        {
            // ensure the invited date is set
            user.InvitedDate = DateTime.Now;

            // Save the updated user (which will process the user groups too)
            _userService.Save(user);
        }

        UserDisplay? display = _umbracoMapper.Map<UserDisplay>(user);

        // send the email
        await SendUserInviteEmailAsync(display, _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Name,
            _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Email, user, userSave.Message);

        display?.AddSuccessNotification(_localizedTextService.Localize("speechBubbles", "resendInviteHeader"),
            _localizedTextService.Localize("speechBubbles", "resendInviteSuccess", new[] { user?.Name }));
        return display;
    }