mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
Nav bar: Tabs render by role (#845)
* Nav tabs render based on permissionUtils global role Co-authored by: @gillespi314
This commit is contained in:
parent
15b81824f5
commit
daa244ee00
@ -23,11 +23,9 @@ class SiteNavSidePanel extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
const {
|
||||
user: { global_role },
|
||||
} = this.props;
|
||||
const { user: currentUser } = this.props;
|
||||
|
||||
this.userNavItems = navItems(global_role === "admin");
|
||||
this.userNavItems = navItems(currentUser);
|
||||
}
|
||||
|
||||
renderNavItem = (navItem) => {
|
||||
|
@ -1,7 +1,8 @@
|
||||
import PATHS from "router/paths";
|
||||
import URL_PREFIX from "router/url_prefix";
|
||||
import permissionUtils from "utilities/permissions";
|
||||
|
||||
export default (admin) => {
|
||||
export default (currentUser) => {
|
||||
const adminNavItems = [
|
||||
{
|
||||
icon: "settings",
|
||||
@ -33,6 +34,9 @@ export default (admin) => {
|
||||
pathname: PATHS.MANAGE_QUERIES,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const globalMaintainerNavItems = [
|
||||
{
|
||||
icon: "packs",
|
||||
name: "Packs",
|
||||
@ -44,8 +48,12 @@ export default (admin) => {
|
||||
},
|
||||
];
|
||||
|
||||
if (admin) {
|
||||
return [...userNavItems, ...adminNavItems];
|
||||
if (permissionUtils.isGlobalAdmin(currentUser)) {
|
||||
return [...userNavItems, ...globalMaintainerNavItems, ...adminNavItems];
|
||||
}
|
||||
|
||||
if (permissionUtils.isGlobalMaintainer(currentUser)) {
|
||||
return [...userNavItems, ...globalMaintainerNavItems];
|
||||
}
|
||||
|
||||
return userNavItems;
|
||||
|
@ -17,26 +17,55 @@ const isGlobalMaintainer = (user: IUser): boolean => {
|
||||
return user.global_role === "maintainer";
|
||||
};
|
||||
|
||||
const isGlobalObserver = (user: IUser): boolean => {
|
||||
return user.global_role === "observer";
|
||||
};
|
||||
|
||||
const isOnGlobalTeam = (user: IUser): boolean => {
|
||||
return user.global_role !== null;
|
||||
};
|
||||
|
||||
const isTeamObserver = (user: IUser, teamId: number) => {
|
||||
const isTeamObserver = (user: IUser, teamId: number): boolean => {
|
||||
const userTeamRole = user.teams.find((team) => team.id === teamId)?.role;
|
||||
return userTeamRole === "observer";
|
||||
};
|
||||
|
||||
const isTeamMaintainer = (user: IUser, teamId: number) => {
|
||||
// This checks against a specific team
|
||||
const isTeamMaintainer = (user: IUser, teamId: number): boolean => {
|
||||
const userTeamRole = user.teams.find((team) => team.id === teamId)?.role;
|
||||
return userTeamRole === "maintainer";
|
||||
};
|
||||
|
||||
// This checks against all teams
|
||||
const isAnyTeamMaintainer = (user: IUser): boolean => {
|
||||
if (!isOnGlobalTeam(user)) {
|
||||
return user.teams.some((team) => team?.role === "maintainer");
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const isOnlyObserver = (user: IUser): boolean => {
|
||||
if (isGlobalObserver(user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isOnGlobalTeam(user)) {
|
||||
return !user.teams.some((team) => team?.role === "maintainer");
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
export default {
|
||||
isCoreTier,
|
||||
isBasicTier,
|
||||
isGlobalAdmin,
|
||||
isGlobalMaintainer,
|
||||
isGlobalObserver,
|
||||
isOnGlobalTeam,
|
||||
isTeamObserver,
|
||||
isTeamMaintainer,
|
||||
isAnyTeamMaintainer,
|
||||
isOnlyObserver,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user