public static Dictionary <string, object> GetAccessHeaders(this DataAccessControl accessControl) { var payload = new List <string>(); if (accessControl.Read) { payload.Add("read"); } if (accessControl.Write) { payload.Add("write"); } if (accessControl.Remove) { payload.Add("remove"); } return(new Dictionary <string, object> { { "x-zen-allowed", payload } }); }
public virtual Dictionary <string, object> Headers <T>(ref DataAccessControl accessControl, Dictionary <string, StringValues> requestHeaders, EActionScope scope, T model) where T : Data <T> { var ctx = new List <string>(); if (!CanBrowse()) { accessControl.Read = false; return(new Dictionary <string, object>()); } ctx.Add("browse"); if (requestHeaders?.ContainsKey(Mutator.CommonMetadataKeys.Set) == true) { if (!string.IsNullOrEmpty(requestHeaders[Mutator.CommonMetadataKeys.Set])) { if (requestHeaders[Mutator.CommonMetadataKeys.Set] != Constants.CURRENT_LIVE_WORKSET_TAG) { accessControl.Write = false; accessControl.Remove = false; } } } if (CanModify()) { ctx.Add("modify"); } else { accessControl.Write = false; accessControl.Remove = false; } return(new Dictionary <string, object> { { "x-zen-setversion", ctx } }); }
public virtual Dictionary <string, object> Headers <T>(ref DataAccessControl accessControl, Dictionary <string, StringValues> requestHeaders, EActionScope scope, T model) where T : Data <T> { var moderationSetup = ModerationHelper.Setup <T>(); var ctx = new Dictionary <string, object> { { "moderated", true } }; var customModerationPipeline = moderationSetup.CustomModerationPipeline; var allowedActions = moderationSetup.ModerationActions; if (customModerationPipeline != null && scope == EActionScope.Model) { allowedActions = customModerationPipeline.GetModerationActions(EActionType.Read, scope, null, model, null) ?? allowedActions; } if (allowedActions.Moderate) { ctx.Add("moderator", true); } if (allowedActions.Whitelisted) { ctx.Add("whiteListed", true); } if (allowedActions.Author) { ctx.Add("canPost", true); } if (customModerationPipeline != null) { var headerPayloadDictionary = new Dictionary <string, List <string> >(); var onInsert = customModerationPipeline.OnInsertAbstracts(); if (onInsert?.Any() == true) { headerPayloadDictionary.Add("add", onInsert); } var onUpdate = customModerationPipeline.OnUpdateAbstracts(); if (onUpdate?.Any() == true) { headerPayloadDictionary.Add("edit", onUpdate); } var onRemove = customModerationPipeline.OnRemoveAbstracts(); if (onRemove?.Any() == true) { headerPayloadDictionary.Add("del", onRemove); } if (headerPayloadDictionary.Any()) { ctx.Add("abstract", headerPayloadDictionary); } } var canShow = allowedActions.Read; ctx.Add("canShow", canShow); if (canShow) { var path = Current.Context.Request.Path.ToUriComponent(); path = path.Remove(path.Length - 1); if (path.Contains("moderation/task")) { path = path.Replace("moderation/task", ""); } ctx.Add("baseUrl", path); } var ret = new Dictionary <string, object> { { "x-zen-moderation", ctx } }; return(ret); }
public Dictionary <string, object> Headers <T>(ref DataAccessControl accessControl, Dictionary <string, StringValues> requestHeaders, EActionScope scope, T model) where T : Data <T> { return(null); }
internal static IHeaderDictionary AddModelHeaders <T>(this IHeaderDictionary responseHeaders, ref DataAccessControl accessControl, IQueryCollection sourceQuery, EActionScope scope, T model = null) where T : Data <T> { var sourceParameters = sourceQuery.ToDictionary(i => i.Key, i => i.Value); if (Info <T> .Settings?.Pipelines?.Before != null) { foreach (var pipelineMember in Info <T> .Settings.Pipelines.Before) { AddHeaders(responseHeaders, pipelineMember.Headers(ref accessControl, sourceParameters, scope, model)); } } if (Info <T> .Settings?.Pipelines?.After != null) { foreach (var pipelineMember in Info <T> .Settings.Pipelines.After) { AddHeaders(responseHeaders, pipelineMember.Headers(ref accessControl, sourceParameters, scope, model)); } } return(responseHeaders); }