Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use route permissions on the registry #2388

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions imports/plugins/core/router/lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function hasRoutePermission(route) {

if (routeName === "index" || routeName === "not-found") {
return true;
} else if (Router.Reaction.hasPermission(routeName, Meteor.userId())) {
} else if (Router.Reaction.hasPermission(route.permissions, Meteor.userId())) {
return true;
}

Expand Down Expand Up @@ -370,13 +370,14 @@ export function ReactionLayout(options = {}) {
structure: layoutStructure,
component: (props) => { // eslint-disable-line react/no-multi-comp, react/display-name
const route = Router.current().route;
const permissions = options.permissions;
const structure = {
...layoutStructure
};

// If the current route is unauthorized, and is not the "not-found" route,
// then override the template to use the default unauthroized template
if (hasRoutePermission(route) === false && route.name !== "not-found") {
if (hasRoutePermission({ ...route, permissions }) === false && route.name !== "not-found") {
structure.template = "unauthorized";
}

Expand Down Expand Up @@ -462,6 +463,7 @@ Router.initPackageRoutes = (options) => {
const {
meta,
route,
permissions,
template,
layout,
workflow
Expand All @@ -472,7 +474,7 @@ Router.initPackageRoutes = (options) => {

// define new route
// we could allow the options to be passed in the registry if we need to be more flexible
const reactionLayout = ReactionLayout({ template, workflow, layout });
const reactionLayout = ReactionLayout({ template, workflow, layout, permissions });
const newRouteConfig = {
route,
name,
Expand Down