Skip to content

Commit

Permalink
Hide unavailable page links to non-admin users in settings and header (
Browse files Browse the repository at this point in the history
…#4524)

* Filter unavailable menu items in SettingsWrapper

* Don't show Alert Destination in header to users
  • Loading branch information
gabrieldutra authored and arikfr committed Jan 8, 2020
1 parent 76f0dcb commit 465dbc0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions client/app/components/SettingsWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ function wrapSettingsTab(options, WrappedComponent) {
<PageHeader title="Settings" />
<div className="bg-white tiled">
<Menu selectedKeys={[activeItem && activeItem.title]} selectable={false} mode="horizontal">
{settingsMenu.items.map(item => (
<Menu.Item key={item.title}>
<a href={item.path}>{item.title}</a>
</Menu.Item>
))}
{settingsMenu.items
.filter(item => item.isAvailable())
.map(item => (
<Menu.Item key={item.title}>
<a href={item.path}>{item.title}</a>
</Menu.Item>
))}
</Menu>
<div className="p-15">
<div>
Expand Down
2 changes: 1 addition & 1 deletion client/app/components/app-header/AppHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function DesktopNavbar() {
<a href="query_snippets">Query Snippets</a>
</Menu.Item>
)}
{currentUser.hasPermission("list_users") && (
{currentUser.isAdmin && (
<Menu.Item key="destinations">
<a href="destinations">Alert Destinations</a>
</Menu.Item>
Expand Down
5 changes: 5 additions & 0 deletions client/app/services/settingsMenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isFunction, extend, omit, sortBy, find } from "lodash";
import { currentUser } from "@/services/auth";

class SettingsMenuItem {
constructor(menuItem) {
Expand All @@ -11,6 +12,10 @@ class SettingsMenuItem {
isActive(path) {
return path.startsWith(this.pathPrefix);
}

isAvailable() {
return this.permission === undefined || currentUser.hasPermission(this.permission);
}
}

class SettingsMenu {
Expand Down

0 comments on commit 465dbc0

Please sign in to comment.