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

Start preparing for multi-tenancy #119

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions api/src/db/neo4jDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const driver = neo4j.driver(
),
);

// TODO: run migrations here maybe? store "version" in a node with a specific
// label, if that number is too low then run upgrade migrations

// TODO: Run driver.close() when node app exits.

export default driver;
10 changes: 10 additions & 0 deletions api/src/graphql/authorization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ export const isAdmin = combineResolvers(
return (user && user.role === 'admin') ? skip : new Error('Not authorized');
},
);

export const isAuthorized = combineResolvers(
isAuthenticated,
(obj, args, { user }) => {
if (user.tenantId === 'placeholder') {
return skip;
}
return new Error('Unauthorized access');
},
);
4 changes: 2 additions & 2 deletions api/src/graphql/resolvers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
searchRealities,
getEmailData,
} from '../connectors';
import { isAuthenticated } from '../authorization';
import { isAuthenticated, isAuthorized } from '../authorization';
import { sendUpdateMail } from '../../email/mailService';

const notify = (process.env.EMAIL_NOTIFICATIONS === 'enabled');
Expand Down Expand Up @@ -169,7 +169,7 @@ const resolvers = {
},
),
updateResponsibility: combineResolvers(
isAuthenticated,
isAuthorized,
async (obj, args, { driver, user }) => {
const emailData = await getEmailData(driver, args);
const responsibility = await updateReality(driver, args);
Expand Down
1 change: 1 addition & 0 deletions api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function getUser(user) {
{
email: user['https://realities.platoproject.org/email'],
role: user['https://realities.platoproject.org/role'],
tenantId: 'placeholder',
},
);
}
Expand Down