Chore: Scope URLs with account_id (#601)

* Chore: Enable Users to create multiple accounts

Addresses: #402
- migrations to split roles and other attributes from users table
- make changes in code to accommodate this change

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-03-09 23:27:10 +05:30
committed by GitHub
parent 2a6670f0da
commit 19ab0fe108
105 changed files with 480 additions and 402 deletions

View File

@@ -22,9 +22,9 @@ export default {
Auth.verifyPasswordToken({
confirmationToken: this.confirmationToken
}).then(res => {
window.location = res.data.redirect_url;
window.location = '/';
}).catch(res => {
window.location = res.data.redirect_url;
window.location = '/';
});
}
}

View File

@@ -118,7 +118,7 @@ export default {
Auth.setNewPassword(credentials)
.then(res => {
if (res.status === 200) {
window.location = res.data.redirect_url;
window.location = '/';
}
})
.catch(() => {

View File

@@ -63,7 +63,7 @@
</form>
<div class="column text-center sigin--footer">
<span>Already have an account?</span>
<router-link to="auth/login">
<router-link to="/app/login">
{{ $t('LOGIN.TITLE') }}
</router-link>
</div>
@@ -77,7 +77,6 @@
import { required, minLength, email } from 'vuelidate/lib/validators';
import Auth from '../../api/auth';
import { frontendURL } from '../../helper/URLHelper';
export default {
data() {
@@ -118,7 +117,7 @@ export default {
Auth.register(this.credentials)
.then(res => {
if (res.status === 200) {
window.location = frontendURL('dashboard');
window.location = '/';
}
})
.catch(error => {

View File

@@ -5,7 +5,7 @@ import { frontendURL } from '../../../helper/URLHelper';
export default {
routes: [
{
path: frontendURL('dashboard'),
path: frontendURL('accounts/:accountId/dashboard'),
name: 'home',
roles: ['administrator', 'agent'],
component: ConversationView,
@@ -14,7 +14,7 @@ export default {
},
},
{
path: frontendURL('inbox/:inbox_id'),
path: frontendURL('accounts/:accountId/inbox/:inbox_id'),
name: 'inbox_dashboard',
roles: ['administrator', 'agent'],
component: ConversationView,
@@ -23,7 +23,7 @@ export default {
},
},
{
path: frontendURL('conversations/:conversation_id'),
path: frontendURL('accounts/:accountId/conversations/:conversation_id'),
name: 'inbox_conversation',
roles: ['administrator', 'agent'],
component: ConversationView,
@@ -32,7 +32,9 @@ export default {
},
},
{
path: frontendURL('inbox/:inbox_id/conversations/:conversation_id'),
path: frontendURL(
'accounts/:accountId/inbox/:inbox_id/conversations/:conversation_id'
),
name: 'conversation_through_inbox',
roles: ['administrator', 'agent'],
component: ConversationView,

View File

@@ -6,7 +6,7 @@ import { frontendURL } from '../../helper/URLHelper';
export default {
routes: [
{
path: frontendURL(''),
path: frontendURL('accounts/:account_id'),
component: AppContainer,
children: [...conversation.routes, ...settings.routes],
},

View File

@@ -5,7 +5,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
export default {
routes: [
{
path: frontendURL('settings/agents'),
path: frontendURL('accounts/:accountId/settings/agents'),
component: SettingsContent,
props: {
headerTitle: 'AGENT_MGMT.HEADER',

View File

@@ -6,7 +6,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
export default {
routes: [
{
path: frontendURL('settings/billing'),
path: frontendURL('accounts/:accountId/settings/billing'),
component: SettingsContent,
props: {
headerTitle: 'BILLING.HEADER',

View File

@@ -5,7 +5,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
export default {
routes: [
{
path: frontendURL('settings/canned-response'),
path: frontendURL('accounts/:accountId/settings/canned-response'),
component: SettingsContent,
props: {
headerTitle: 'CANNED_MGMT.HEADER',

View File

@@ -47,7 +47,11 @@
<!-- Action Buttons -->
<td>
<div class="button-wrapper">
<router-link :to="`/app/settings/inboxes/${item.id}`">
<router-link
:to="
`/app/accounts/${accountId}/settings/inboxes/${item.id}`
"
>
<woot-submit-button
v-if="isAdmin()"
:button-text="$t('INBOX_MGMT.SETTINGS')"
@@ -101,6 +105,7 @@ import Settings from './Settings';
import DeleteInbox from './DeleteInbox';
import adminMixin from '../../../../mixins/isAdmin';
import { frontendURL } from '../../../../helper/URLHelper';
import auth from '../../../../api/auth';
export default {
components: {
@@ -136,6 +141,9 @@ export default {
this.selectedInbox.name
} ?`;
},
accountId() {
return auth.getCurrentUser().account_id;
},
},
methods: {
openSettings(inbox) {

View File

@@ -12,7 +12,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
export default {
routes: [
{
path: frontendURL('settings/inboxes'),
path: frontendURL('accounts/:accountId/settings/inboxes'),
component: SettingsContent,
props: params => {
const showBackButton = params.name !== 'settings_inbox_list';

View File

@@ -17,7 +17,13 @@
</p>
</div>
<div class="small-2 column button-wrap">
<router-link :to="frontendURL('settings/integrations/webhook')">
<router-link
:to="
frontendURL(
`accounts/${accountId}/settings/integrations/webhook`
)
"
>
<button class="button success nice">
{{ $t('INTEGRATION_SETTINGS.WEBHOOK.CONFIGURE') }}
</button>
@@ -34,9 +40,18 @@
</div>
</template>
<script>
import { mapGetters } from 'vuex';
import { frontendURL } from '../../../../helper/URLHelper';
export default {
computed: {
...mapGetters({
currentUser: 'getCurrentUser',
}),
accountId() {
return this.currentUser.account_id;
},
},
methods: {
frontendURL,
},

View File

@@ -6,7 +6,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
export default {
routes: [
{
path: frontendURL('settings/integrations'),
path: frontendURL('accounts/:accountId/settings/integrations'),
component: SettingsContent,
props: params => {
const showBackButton = params.name !== 'settings_integrations';

View File

@@ -5,7 +5,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
export default {
routes: [
{
path: frontendURL('profile'),
path: frontendURL('accounts/:accountId/profile'),
name: 'profile_settings',
roles: ['administrator', 'agent'],
component: SettingsContent,

View File

@@ -5,7 +5,7 @@ import { frontendURL } from '../../../../helper/URLHelper';
export default {
routes: [
{
path: frontendURL('reports'),
path: frontendURL('accounts/:accountId/reports'),
component: SettingsContent,
props: {
headerTitle: 'REPORT.HEADER',

View File

@@ -11,14 +11,14 @@ import integrations from './integrations/integrations.routes';
export default {
routes: [
{
path: frontendURL('settings'),
path: frontendURL('accounts/:accountId/settings'),
name: 'settings_home',
roles: ['administrator', 'agent'],
redirect: () => {
if (Auth.isAdmin()) {
return frontendURL('settings/agents');
return frontendURL('accounts/:accountId/settings/agents');
}
return frontendURL('settings/canned-response');
return frontendURL('accounts/:accountId/settings/canned-response');
},
},
...agent.routes,

View File

@@ -7,13 +7,14 @@ import dashboard from './dashboard/dashboard.routes';
import authRoute from './auth/auth.routes';
import { frontendURL } from '../helper/URLHelper';
const loggedInUser = auth.getCurrentUser() || {};
const routes = [
...login.routes,
...dashboard.routes,
...authRoute.routes,
{
path: '/',
redirect: frontendURL('dashboard'),
redirect: frontendURL(`accounts/${loggedInUser.account_id}/dashboard`),
},
];
@@ -102,7 +103,8 @@ const validateRouteAccess = (to, from, next) => {
to.meta &&
to.meta.requireSignupEnabled
) {
next(frontendURL('dashboard'));
const user = auth.getCurrentUser();
next(frontendURL(`accounts/${user.account_id}/dashboard`));
}
if (authIgnoreRoutes.includes(to.name)) {
@@ -114,7 +116,8 @@ const validateRouteAccess = (to, from, next) => {
// protecting routes
router.beforeEach((to, from, next) => {
if (!to.name) {
return next(frontendURL('dashboard'));
const user = auth.getCurrentUser();
return next(frontendURL(`accounts/${user.account_id}/dashboard`));
}
return validateRouteAccess(to, from, next);