/// <inheritdoc /> public ContentApp GetContentAppFor(object o, IEnumerable <IReadOnlyUserGroup> userGroups) { string partA, partB; switch (o) { case IContent content: partA = "content"; partB = content.ContentType.Alias; break; case IMedia media: partA = "media"; partB = media.ContentType.Alias; break; default: return(null); } var rules = _showRules ?? (_showRules = ShowRule.Parse(_definition.Show).ToArray()); var userGroupsList = userGroups.ToList(); var okRole = false; var hasRole = false; var okType = false; var hasType = false; foreach (var rule in rules) { if (rule.PartA.InvariantEquals("role")) { // if roles have been ok-ed already, skip the rule if (okRole) { continue; } // remember we have role rules hasRole = true; foreach (var group in userGroupsList) { // if the entry does not apply, skip if (!rule.Matches("role", group.Alias)) { continue; } // if the entry applies, // if it's an exclude entry, exit, do not display the content app if (!rule.Show) { return(null); } // else ok to display, remember roles are ok, break from userGroupsList okRole = rule.Show; break; } } else // it is a type rule { // if type has been ok-ed already, skip the rule if (okType) { continue; } // remember we have type rules hasType = true; // if the entry does not apply, skip it if (!rule.Matches(partA, partB)) { continue; } // if the entry applies, // if it's an exclude entry, exit, do not display the content app if (!rule.Show) { return(null); } // else ok to display, remember type rules are ok okType = true; } } // if roles rules are specified but not ok, // or if type roles are specified but not ok, // cannot display the content app if ((hasRole && !okRole) || (hasType && !okType)) { return(null); } // else // content app can be displayed return(_app ?? (_app = new ContentApp { Alias = _definition.Alias, Name = _definition.Name, Icon = _definition.Icon, View = _definition.View, Weight = _definition.Weight })); }
/// <inheritdoc /> public ContentApp?GetContentAppFor(object o, IEnumerable <IReadOnlyUserGroup> userGroups) { string?partA, partB; switch (o) { case IContent content: partA = "content"; partB = content.ContentType.Alias; break; case IMedia media: partA = "media"; partB = media.ContentType.Alias; break; case IMember member: partA = "member"; partB = member.ContentType.Alias; break; case IContentType contentType: partA = "contentType"; partB = contentType?.Alias; break; case IDictionaryItem _: partA = "dictionary"; partB = "*"; // Not really a different type for dictionary items break; default: return(null); } ShowRule[] rules = _showRules ??= ShowRule.Parse(_definition.Show).ToArray(); var userGroupsList = userGroups.ToList(); var okRole = false; var hasRole = false; var okType = false; var hasType = false; foreach (ShowRule rule in rules) { if (rule.PartA?.InvariantEquals("role") ?? false) { // if roles have been ok-ed already, skip the rule if (okRole) { continue; } // remember we have role rules hasRole = true; foreach (IReadOnlyUserGroup group in userGroupsList) { // if the entry does not apply, skip if (!rule.Matches("role", group.Alias)) { continue; } // if the entry applies, // if it's an exclude entry, exit, do not display the content app if (!rule.Show) { return(null); } // else ok to display, remember roles are ok, break from userGroupsList okRole = rule.Show; break; } } // it is a type rule else { // if type has been ok-ed already, skip the rule if (okType) { continue; } // remember we have type rules hasType = true; // if the entry does not apply, skip it if (!rule.Matches(partA, partB)) { continue; } // if the entry applies, // if it's an exclude entry, exit, do not display the content app if (!rule.Show) { return(null); } // else ok to display, remember type rules are ok okType = true; } } // if roles rules are specified but not ok, // or if type roles are specified but not ok, // cannot display the content app if ((hasRole && !okRole) || (hasType && !okType)) { return(null); } // else // content app can be displayed return(_app ??= new ContentApp { Alias = _definition.Alias, Name = _definition.Name, Icon = _definition.Icon, View = _ioHelper.ResolveRelativeOrVirtualUrl(_definition.View), Weight = _definition.Weight, }); }