mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 12:08:01 +00:00
fix: Use role permissions from accounts instead of role attribute (#3445)
Use role permissions from accounts instead of the role attribute Fixes: #2557
This commit is contained in:
@@ -21,6 +21,11 @@ window.roleWiseRoutes = {
|
||||
administrator: [],
|
||||
};
|
||||
|
||||
const getUserRole = ({ accounts } = {}, accountId) => {
|
||||
const currentAccount = accounts.find(account => account.id === accountId);
|
||||
return currentAccount ? currentAccount.role : null;
|
||||
};
|
||||
|
||||
// generateRoleWiseRoute - updates window object with agent/admin route
|
||||
const generateRoleWiseRoute = route => {
|
||||
route.forEach(element => {
|
||||
@@ -57,7 +62,10 @@ const routeValidators = [
|
||||
{
|
||||
protected: false,
|
||||
loggedIn: true,
|
||||
handler: () => 'dashboard',
|
||||
handler: () => {
|
||||
const user = auth.getCurrentUser();
|
||||
return `accounts/${user.account_id}/dashboard`;
|
||||
},
|
||||
},
|
||||
{
|
||||
protected: true,
|
||||
@@ -69,8 +77,9 @@ const routeValidators = [
|
||||
loggedIn: true,
|
||||
handler: to => {
|
||||
const user = auth.getCurrentUser();
|
||||
const isAccessible = routeIsAccessibleFor(to, user.role);
|
||||
return isAccessible ? null : 'dashboard';
|
||||
const userRole = getUserRole(user, Number(to.params.accountId));
|
||||
const isAccessible = routeIsAccessibleFor(to.name, userRole);
|
||||
return isAccessible ? null : `accounts/${to.params.accountId}/dashboard`;
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -88,7 +97,7 @@ export const validateAuthenticateRoutePermission = (to, from, next) => {
|
||||
validator.protected === isProtectedRoute &&
|
||||
validator.loggedIn === isLoggedIn
|
||||
);
|
||||
const nextRoute = strategy.handler(to.name);
|
||||
const nextRoute = strategy.handler(to);
|
||||
return nextRoute ? next(frontendURL(nextRoute)) : next();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user