Skip to content

Commit

Permalink
SAK-43138 Display visible status in tool menu (sakaiproject#8900)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored Dec 11, 2020
1 parent b02fb7e commit de7aeda
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 264 deletions.
6 changes: 6 additions & 0 deletions kernel/api/src/main/java/org/sakaiproject/site/api/Site.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public interface Site extends Edit, Comparable, Serializable, AuthzGroup
* property name for custom overview
*/
public final static String PROP_CUSTOM_OVERVIEW = "custom_overview";

/**
* Permission for updating a site
*/
public final static String SITE_UPD = "site.upd";

/**
* @return the user who created this.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Set;

import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SitePage;
import org.sakaiproject.site.api.ToolConfiguration;
import org.w3c.dom.Document;

Expand Down Expand Up @@ -119,6 +120,16 @@ public interface ToolManager
*/
public List<Set<String>> getRequiredPermissions(ToolConfiguration config);

/**
* Tests whether the first tool in the supplied page is visible to ANY
* non-maintainer role. By non-maintainer, we mean a role without
* Site.SITE_UPD.
*
* @param page The site page in which to test the first tool
* @return true, if any role in the site fulfils the required functions of the first tool. false otherwise.
*/
public boolean isFirstToolVisibleToAnyNonMaintainerRole(SitePage page);

/**
* Check whether a tool is visible to the current user in this site,
* depending on permissions required to view the tool.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -48,8 +49,10 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import org.sakaiproject.authz.api.Role;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SitePage;
import org.sakaiproject.site.api.ToolConfiguration;
import org.sakaiproject.thread_local.api.ThreadLocalManager;
import org.sakaiproject.tool.api.Placement;
Expand Down Expand Up @@ -571,6 +574,33 @@ public List<Set<String>> getRequiredPermissions(ToolConfiguration config) {
return sets;
}

public boolean isFirstToolVisibleToAnyNonMaintainerRole(SitePage page) {

List<ToolConfiguration> tools = page.getTools();
List<Set<String>> required
= tools.size() == 1 ? getRequiredPermissions(tools.get(0)) : Collections.EMPTY_LIST;

if (required.isEmpty()) {
return true;
}

// Get the non maintainer roles
final Set<Role> roles = page.getContainingSite().getRoles().stream()
.filter(r -> !r.isAllowed(Site.SITE_UPD)).collect(Collectors.toSet());

// Now check to see if these roles have the permission listed
// in the functions require for the tool.
for (Set<String> permissionSet : required) {
for (Role role : roles) {
if (role.getAllowedFunctions().containsAll(permissionSet)) {
return true; // If any one of the permissions is allows for any role.
}
}
}

return false;
}

public boolean isVisible(Site site, ToolConfiguration config) {

List<Set<String>> permissionSets = getRequiredPermissions(config);
Expand Down
49 changes: 14 additions & 35 deletions library/src/morpheus-master/sass/modules/_toolmenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ body.is-logged-out{
margin: 0;
}
}
.#{$namespace}toolsNav__menuitem--status-block {
display: none;
}
&.is-invisible {
&:after {
display: none;
}
&:hover, &:focus {
.#{$namespace}toolsNav__menuitem--title{
background: var(--tool-menu-item-hidden-hover-background-color);
Expand Down Expand Up @@ -500,7 +500,6 @@ nav#subSites{
color: var(--tool-menu-item-icon-color);

@if $tool-menu-icon-on-left {
display: inline-block;
height: 100%;
font-size: 16px;
} @else {
Expand All @@ -513,23 +512,26 @@ nav#subSites{

.#{$namespace}toolsNav__menuitem--title{
@if $tool-menu-icon-on-left {
display: inline-block;
width: calc(#{$tool-menu-width} - #{$tool-menu-width-collapsed} - #{$standard-spacing});
vertical-align: middle;
margin-left: $standard-spacing;
@media #{$phone}{
width: 90%;
}
} @else {
display: block;
width: 100%;
}
text-overflow: ellipsis;
white-space: pre;
overflow: hidden;
}
.#{$namespace}toolsNav__menuitem--status-block {
margin-right: 10px;
margin-left: 4px;
display: flex;
div {
margin-right: 10px;
&.tool-status-icon {
font-size: 16px;
}
}
}
&.is-invisible {
position: relative;
font-style: italic;
color: var(--tool-menu-item-hidden-text-color);
background: var(--tool-menu-item-hidden-background-color);
Expand All @@ -538,20 +540,6 @@ nav#subSites{
border-left: $tool-menu-item-hidden-border-left;
}

&:after {
@extend .fa-lg;
@extend .fa;
content: '\f070';
@if $tool-menu-icon-on-left {
margin-right: $standard-spacing;
}
@else {
position: absolute;
top: 4px;
right: 4px;
}
}

&:hover{
color: var(--tool-menu-item-hidden-hover-text-color);
background: var(--tool-menu-item-hidden-hover-background-color);
Expand Down Expand Up @@ -934,15 +922,6 @@ body {
color: var(--tool-menu-item-hidden-hover-icon-color) !important;
}
}

&:after {
@extend .fa-lg;
@extend .fa;
content: '\f070';
position: absolute;
top: 8px;
right: 4px;
}
}
&.has-prerequisite {
color: var(--tool-menu-item-hidden-text-color) !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ public interface PortalSiteHelper
* @param resetTools
* @param includeSummary
*/
Map pageListToMap(HttpServletRequest req, boolean loggedIn, Site site,
Map<String, Object> pageListToMap(HttpServletRequest req, boolean loggedIn, Site site,
SitePage page, String toolContextPath, String portalPrefix, boolean doPages,
boolean resetTools, boolean includeSummary);

Map convertSiteToMap(HttpServletRequest req, Site s, String prefix,
Map<String, Object> convertSiteToMap(HttpServletRequest req, Site s, String prefix,
String currentSiteId, String myWorkspaceSiteId, boolean includeSummary,
boolean expandSite, boolean resetTools, boolean doPages,
String toolContextPath, boolean loggedIn, List<String> siteProviders);
Expand Down
2 changes: 2 additions & 0 deletions portal/portal-impl/impl/src/bundle/sitenav.properties
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ sit_no_favorites_selected=You do not have any favorite sites. Star sites in the
sit_autofav_description=Automatically add new sites to your favorites bar:
sit_favorite_limit_reached=Only the first {0} sites (above) will display in your favorites bar.
sit_open_menu=Open attached menu for {0} to access its tools
site_tool_locked_tooltip=This tool is not available to non admin users
site_tool_hidden_tooltip=This tool is not visible for non admin users
site_fav_toggle=Toggle {0} as a favorite site

sit_manover = Manage Overview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,6 @@ public PortalRenderContext includePortal(HttpServletRequest req,
}
}

//List l = siteHelper.convertSitesToMaps(req, mySites, prefix, siteId, myWorkspaceSiteId,
// includeSummary, expandSite, resetTools, doPages, toolContextPath,
// loggedIn);

SiteView siteView = siteHelper.getSitesView(SiteView.View.ALL_SITES_VIEW, req, session, siteId );
siteView.setPrefix(prefix);
siteView.setResetTools(resetTools);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public void includeWorksite(PortalRenderContext rcontext, HttpServletResponse re
{
if (rcontext.uses(INCLUDE_PAGE_NAV))
{
boolean loggedIn = session.getUserId() != null;
Map pageMap = portal.getSiteHelper().pageListToMap(req, loggedIn, site, page, toolContextPath,
boolean loggedIn = session.getUserId() != null;
Map<String, Object> pageMap = portal.getSiteHelper().pageListToMap(req, loggedIn, site, page, toolContextPath,
portalPrefix,
/* doPages */true,
/* resetTools */"true".equalsIgnoreCase(ServerConfigurationService
Expand Down
Loading

0 comments on commit de7aeda

Please sign in to comment.