internal void AddEditInfo(ToSic.Eav.Interfaces.IEntity entity, Dictionary <string, object> dictionary) { // Add additional information in case we're in edit mode if (DotNetNuke.Common.Globals.IsEditMode() || (Sxc?.Environment?.Permissions?.UserMayEditContent ?? false)) { dictionary.Add(Constants.JsonModifiedNodeName, entity.Modified); var title = entity.GetBestTitle(Languages); if (string.IsNullOrEmpty(title)) { title = "(no title)"; } //if (entity is IHasEditingData) dictionary.Add(Constants.JsonEntityEditNodeName, entity is IHasEditingData ? (object)new { sortOrder = ((IHasEditingData)entity).SortOrder, isPublished = entity.IsPublished, } : new { entityId = entity.EntityId, title = title, // entity.Title?[Languages[0]].ToString() ?? "(no title)", isPublished = entity.IsPublished, }); } }
internal override void UpdateTitle(ToSic.Eav.Interfaces.IEntity titleItem) { Log.Add("update title"); // todo: this should probably do the more complex stuff // to ensure that it happens on all versions of this module (all languages) // used to work once... //if (titleItem?.GetBestValue("EntityTitle") != null) // SxcContext.ModuleInfo.ModuleTitle = titleItem.GetBestValue("EntityTitle").ToString(); // 2017-04-01 2dm before: // var languages = ZoneHelpers.CulturesWithState(SxcContext.ModuleInfo.PortalID, SxcContext.ZoneId.Value); var languages = SxcContext.Environment /*new Environment.DnnEnvironment(Log)*/.ZoneMapper.CulturesWithState(SxcContext.ModuleInfo.PortalID, SxcContext.ZoneId.Value); // Find Module for default language var moduleController = new DotNetNuke.Entities.Modules.ModuleController(); var originalModule = moduleController.GetModule(SxcContext.ModuleInfo.ModuleID); foreach (var dimension in languages) { if (!originalModule.IsDefaultLanguage) { originalModule = originalModule.DefaultLanguageModule; } try // this can sometimes fail, like if the first item is null - https://github.com/2sic/2sxc/issues/817 { // Break if default language module is null if (originalModule == null) { return; } // Get Title value of Entitiy in current language var titleValue = titleItem.Title[dimension.Key].ToString(); // Find module for given Culture var moduleByCulture = moduleController.GetModuleByCulture(originalModule.ModuleID, originalModule.TabID, SxcContext.ModuleInfo.PortalID, DotNetNuke.Services.Localization.LocaleController.Instance.GetLocale(dimension.Key)); // Break if no title module found if (moduleByCulture == null || titleValue == null) { return; } moduleByCulture.ModuleTitle = titleValue; moduleController.UpdateModule(moduleByCulture); } catch { // ignored } } }
internal Dictionary <string, object> PrepareOldFormat(ToSic.Eav.Interfaces.IEntity entity) { // var ser = new Serializer(SxcInstance, _dimensions); var dicNew = GetDictionaryFromEntity(entity); var dicToSerialize = ConvertNewSerRelToOldSerRel(dicNew); dicToSerialize.Add(Constants.JsonEntityIdNodeName, entity.EntityId); return(dicToSerialize); }
public override Dictionary <string, object> GetDictionaryFromEntity(ToSic.Eav.Interfaces.IEntity entity) { // Do groundwork var dictionary = base.GetDictionaryFromEntity(entity); AddPresentation(entity, dictionary); AddEditInfo(entity, dictionary); return(dictionary); }
public PermissionController(int?zoneId, int appId, Guid typeGuid, ToSic.Eav.Interfaces.IEntity targetItem, ModuleInfo module = null) { ZoneId = zoneId; AppId = appId; TypeGuid = typeGuid; if (targetItem != null) { TargetItem = targetItem; } Module = module; }
/// <summary> /// Check if a specific permission entity allows for the desired permission /// </summary> /// <param name="permissionEntity">The entity describing a permission</param> /// <param name="desiredActionCode">A key like r (for read), u (for update) etc. which is the level you want to check</param> /// <returns></returns> private bool DoesPermissionAllow(ToSic.Eav.Interfaces.IEntity permissionEntity, char desiredActionCode) { // Check if it's a grant-read permission - otherwise stop here var grnt = permissionEntity.GetBestValue(Grant).ToString(); if (grnt.IndexOf(desiredActionCode) == -1) // Grant doesn't contain read, so stop here { return(false); } // Check if the current user fits the reason for this grant try { // check general permissions var condition = permissionEntity.GetBestValue(Condition).ToString(); if (condition.ToLower().StartsWith(_salPrefix)) { var salWord = condition.Substring(_salPrefix.Length); var sal = (SecurityAccessLevel)Enum.Parse(typeof(SecurityAccessLevel), salWord); // check anonymous - this is always valid, even if not in a module context if (sal == SecurityAccessLevel.Anonymous) { return(true); } // check within module context if (Module == null) { throw new Exception("trying to check permission " + _salPrefix + ", but don't have module in context"); } return(DotNetNuke.Security.Permissions.ModulePermissionController .HasModuleAccess(sal, CustomPermissionKey, Module)); } // check owner conditions if (condition == _keyOwner) { // if it's an entity, possibly also check owner-permissions if (TargetItem != null && TargetItem.Owner == Environment.Dnn7.UserIdentity.CurrentUserIdentityToken) { return(true); } } } catch { // something happened, in this case we assume that this rule cannot described a "is allowed" return(false); } // If the code gets here, we apparently don't know what the rule is about - return false return(false); }
internal void AddPresentation(ToSic.Eav.Interfaces.IEntity entity, Dictionary <string, object> dictionary) { // Add full presentation object if it has one...because there we need more than just id/title if (entity is EntityInContentGroup && !dictionary.ContainsKey(AppConstants.Presentation)) { var entityInGroup = (EntityInContentGroup)entity; if (entityInGroup.Presentation != null) { dictionary.Add(AppConstants.Presentation, GetDictionaryFromEntity(entityInGroup.Presentation)); //, language)); } } }
} // must be internal for further use cases /// <summary> /// Constructor with EntityModel and DimensionIds /// </summary> public DynamicEntity(ToSic.Eav.Interfaces.IEntity entityModel, string[] dimensions, SxcInstance sexy) { Entity = entityModel; _dimensions = dimensions; SxcInstance = sexy; }
public Template(ToSic.Eav.Interfaces.IEntity templateEntity) { _templateEntity = templateEntity ?? throw new Exception("Template entity is null"); }