Ejemplo n.º 1
0
        /// <inheritdoc/>
        public string Enable(string noParameterOrder = "random-y023n", bool?js = null, bool?api = null,
                             bool?forms = null, bool?context = null, bool?autoToolbar           = null, bool?styles = null)
        {
            Eav.Constants.ProtectAgainstMissingParameterNames(noParameterOrder, "Enable", $"{nameof(js)},{nameof(api)},{nameof(forms)},{nameof(context)},{nameof(autoToolbar)},{nameof(autoToolbar)},{nameof(styles)}");

            // check if feature enabled - if more than the api is needed
            // extend this list if new parameters are added
            if (forms.HasValue || styles.HasValue || context.HasValue || autoToolbar.HasValue)
            {
                var feats = new[] { FeatureIds.PublicForms };
                if (!Feats.EnabledOrException(feats, "public forms not available", out var exp))
                {
                    throw exp;
                }
            }

            // find the root host, as this is the one we must tell what js etc. we need
            var hostWithInternals = (BlockBuilder)Block.BlockBuilder.RootBuilder;

            if (js.HasValue || api.HasValue || forms.HasValue)
            {
                hostWithInternals.UiAddJsApi = (js ?? false) || (api ?? false) || (forms ?? false);
            }

            // only update the values if true, otherwise leave untouched
            if (api.HasValue || forms.HasValue)
            {
                hostWithInternals.UiAddEditApi = (api ?? false) || (forms ?? false);
            }

            if (styles.HasValue)
            {
                hostWithInternals.UiAddEditUi = styles.Value;
            }

            if (context.HasValue)
            {
                hostWithInternals.UiAddEditContext = context.Value;
            }

            if (autoToolbar.HasValue)
            {
                hostWithInternals.UiAutoToolbar = autoToolbar.Value;
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the object and performs all the initial security checks
        /// </summary>
        public AdamSecureState(IBlockBuilder blockBuilder, int appId, string contentType, string field, Guid guid, bool usePortalRoot, ILog log)
            : base(blockBuilder, appId, contentType, log)
        {
            // only do checks on field/guid if it's actually accessing that, if it's on the portal root, don't.
            if (!usePortalRoot)
            {
                Field = field;
                Guid  = guid;
            }

            var firstChecker          = PermissionCheckers.First().Value;
            var userMayAdminSomeFiles = firstChecker.UserMay(GrantSets.WritePublished);

            UserMayAdminSiteFiles = firstChecker.GrantedBecause == Conditions.EnvironmentGlobal ||
                                    firstChecker.GrantedBecause == Conditions.EnvironmentInstance;

            UserIsRestricted = !(usePortalRoot
                ? UserMayAdminSiteFiles
                : userMayAdminSomeFiles);


            Log.Add($"AdamSecureState - field:{field}, guid:{guid}, adminSome:{userMayAdminSomeFiles}, restricted:{UserIsRestricted}");

            SecurityChecks.ThrowIfAccessingRootButNotAllowed(usePortalRoot, UserIsRestricted);

            Log.Add("check if feature enabled");
            if (UserIsRestricted && !Feats.Enabled(FeaturesForRestrictedUsers))
            {
                throw Http.PermissionDenied(
                          $"low-permission users may not access this - {Feats.MsgMissingSome(FeaturesForRestrictedUsers)}");
            }

            PrepCore(App, guid, field, usePortalRoot);

            if (string.IsNullOrEmpty(contentType) || string.IsNullOrEmpty(field))
            {
                return;
            }

            Attribute = Definition(appId, contentType, field);
            if (!FileTypeIsOkForThisField(out var exp))
            {
                throw exp;
            }
        }
Ejemplo n.º 3
0
        public string Enable(string dontRelyOnParameterOrder = Constants.RandomProtectionParameter, bool?api = null, bool?forms = null, bool?context = null, bool?autoToolbar = null, bool?styles = null)
        {
            Constants.ProtectAgainstMissingParameterNames(dontRelyOnParameterOrder, "Enable", $"{nameof(api)},{nameof(forms)},{nameof(context)},{nameof(autoToolbar)},{nameof(autoToolbar)},{nameof(styles)}");

            // check if feature enabled
            var feats = new[] { FeatureIds.PublicForms };

            if (!Feats.EnabledOrException(feats, "public forms not available", out var exp))
            {
                throw exp;
            }
            //if (!Feats.Enabled(feats))
            //    throw new Exception($"public forms not available - {Feats.MsgMissingSome(feats)}");

            // only update the values if true, otherwise leave untouched
            if (api.HasValue || forms.HasValue)
            {
                SxcInstance.UiAddEditApi = api ?? forms.Value;
            }

            if (styles.HasValue)
            {
                SxcInstance.UiAddEditUi = styles.Value;
            }

            if (context.HasValue)
            {
                SxcInstance.UiAddEditContext = context.Value;
            }

            if (autoToolbar.HasValue)
            {
                SxcInstance.UiAutoToolbar = autoToolbar.Value;
            }

            return(null);
        }