Skip to content

Commit

Permalink
Merge branch 'release/v1.24.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
appsol committed Oct 3, 2023
2 parents 84c2901 + f4530d5 commit 3f8ba02
Show file tree
Hide file tree
Showing 30 changed files with 931 additions and 206 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ VUE_APP_BUGSNAG_API_KEY=
VUE_APP_CONTACT_EMAIL=
VUE_APP_CQC_LOCATION_ACTIVE=
VUE_APP_SERVICE_TAGS=
VUE_APP_S3D_REGION=eu-west-2
VUE_APP_S3D_BUCKET=
VUE_APP_S3D_ACL=private
VUE_APP_S3D_CLOUDFRONT_ID=
20 changes: 10 additions & 10 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,52 +61,52 @@ export default {
{
text: "Services",
to: { name: "services-index" },
hide: Auth.isOnlyContentAdmin,
hide: !Auth.canView("services"),
},
{
text: "Locations",
to: { name: "locations-index" },
hide: Auth.isOnlyContentAdmin,
hide: !Auth.canView("locations"),
},
{
text: "Referrals",
to: { name: "referrals-index" },
hide: Auth.isOnlyContentAdmin,
hide: !Auth.canView("referrals"),
},
{
text: "Organisations",
to: { name: "organisations-index" },
hide: !Auth.isOrganisationAdmin(),
hide: !Auth.canView("organisations"),
},
{
text: "Events",
to: { name: "events-index" },
hide: Auth.isOnlyContentAdmin,
hide: !Auth.canView("events"),
},
{
text: "Pages",
to: { name: "pages-index" },
hide: !Auth.isContentAdmin,
hide: !Auth.canView("pages"),
},
{
text: "Users",
to: { name: "users-index" },
hide: Auth.isOnlyContentAdmin,
hide: !Auth.canView("users"),
},
{
text: "Reports",
to: { name: "reports-index" },
hide: !Auth.isGlobalAdmin,
hide: !Auth.canView("reports"),
},
{
text: "Admin",
to: { name: "admin-index" },
hide: !Auth.isGlobalAdmin,
hide: !Auth.canView("admin"),
},
{
text: "Update requests",
to: { name: "update-requests-index" },
hide: !Auth.isGlobalAdmin,
hide: !Auth.canView("update requests"),
},
{
text: "Help",
Expand Down
173 changes: 160 additions & 13 deletions src/classes/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,21 @@ class Auth {
* @returns {boolean}
*/
get isGlobalAdmin() {
return this.hasRole("Global Admin") || this.isSuperAdmin;
return this.hasRole("Global Admin");
}

/**
* @returns {boolean}
*/
get isOnlyGlobalAdmin() {
return this.hasRole("Global Admin") && !this.isSuperAdmin;
}

/**
* @returns {boolean}
*/
get isContentAdmin() {
return this.hasRole("Content Admin") || this.isSuperAdmin;
return this.hasRole("Content Admin");
}

/**
Expand All @@ -259,29 +266,169 @@ class Auth {
* @returns {boolean}
*/
isOrganisationAdmin(organisation = null) {
return (
this.hasRole("Organisation Admin", null, organisation) ||
this.isGlobalAdmin
);
return this.hasRole("Organisation Admin", null, organisation);
}

/**
* @returns {boolean}
*/
isServiceAdmin(service = null) {
return (
this.hasRole("Service Admin", service) ||
this.isOrganisationAdmin(service !== null ? service.organisation : null)
);
return this.hasRole("Service Admin", service);
}

/**
* @returns {boolean}
*/
isServiceWorker(service = null) {
return (
this.hasRole("Service Worker", service) || this.isServiceAdmin(service)
);
return this.hasRole("Service Worker", service);
}

/**
* @returns {boolean}
*/
get isOnlyServiceWorker() {
return this.hasRole("Service Worker") && this.user.roles.length === 1;
}

/**
* Can the user view a content type
* @param {string} type
* @returns {boolean}
*/
canView(type) {
if (this.isSuperAdmin) {
return true;
}
if (type === "events") {
return this.isOrganisationAdmin();
}
if (type === "services") {
return !this.isOnlyContentAdmin;
}
if (type === "organisations") {
return !this.isOnlyContentAdmin && !this.isOnlyServiceWorker;
}
if (type === "locations") {
return !this.isOnlyContentAdmin;
}
if (type === "referrals") {
return !this.isOnlyContentAdmin && !this.isOnlyGlobalAdmin;
}
if (type === "pages") {
return this.isContentAdmin;
}
if (type === "users") {
return (
!this.isOnlyContentAdmin &&
!this.isOnlyGlobalAdmin &&
!this.isOnlyServiceWorker
);
}
}

/**
* Can the user add a content type
* @param {string} type
* @returns {boolean}
*/
canAdd(type) {
if (this.isSuperAdmin) {
return true;
}
if (type === "event") {
return this.isOrganisationAdmin();
}
if (type === "service") {
return this.isOrganisationAdmin();
}
if (type === "organisation") {
return this.isGlobalAdmin;
}
if (type === "location") {
return this.isServiceAdmin();
}
if (type === "page") {
return this.isContentAdmin;
}
if (type === "user") {
return (
!this.isOnlyContentAdmin &&
!this.isOnlyGlobalAdmin &&
!this.isOnlyServiceWorker
);
}
return false;
}

/**
* Can the user update a content type
* @param {string} type
* @returns {boolean}
*/
canEdit(type, model = null) {
if (this.isSuperAdmin) {
return true;
}
if (type === "event") {
return this.isOrganisationAdmin(model);
}
if (type === "service") {
return this.isServiceAdmin(model);
}
if (type === "organisation") {
return this.isOrganisationAdmin(model);
}
if (type === "location") {
return this.isServiceAdmin(model);
}
if (type === "page") {
return this.isContentAdmin;
}
if (type === "referral") {
return this.isServiceWorker() && !this.isOnlyGlobalAdmin;
}
if (type === "user") {
return (
!this.isOnlyContentAdmin &&
!this.isOnlyGlobalAdmin &&
!this.isOnlyServiceWorker
);
}
return false;
}

/**
* Can the user bulk import a content type
* @param {string} type
* @returns {boolean}
*/
canImport() {
if (this.isSuperAdmin) {
return true;
}
return false;
}

/**
* Can the user delete a content type
* @param {string} type
* @returns {boolean}
*/
canDelete(type) {
if (this.isSuperAdmin) {
return true;
}
if (type === "page") {
return this.isContentAdmin;
}
if (type === "user") {
return (
!this.isOnlyContentAdmin &&
!this.isOnlyGlobalAdmin &&
!this.isOnlyServiceWorker
);
}
return false;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ let router = new Router({
name: "pages-edit",
component: () => import("@/views/pages/Edit"),
},
{
path: ":page/updated",
name: "pages-updated",
component: () => import("@/views/pages/Updated"),
meta: { auth: true },
},
{
path: "",
name: "pages-index",
Expand Down
23 changes: 13 additions & 10 deletions src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<gov-section-break size="l" />

<gov-grid-row>
<gov-grid-column width="one-half" v-if="!auth.isOnlyContentAdmin">
<gov-grid-column width="one-half" v-if="auth.canView('services')">
<gov-heading size="l">Services</gov-heading>
<gov-body>Add or edit your pages on {{ appName }}.</gov-body>
<gov-button start :to="{ name: 'services-index' }">
Expand All @@ -33,7 +33,7 @@
<gov-section-break size="m" />
</gov-grid-column>

<gov-grid-column width="one-half" v-if="!auth.isOnlyContentAdmin">
<gov-grid-column width="one-half" v-if="auth.canView('locations')">
<gov-heading size="l">Locations</gov-heading>
<gov-body>View and edit service locations in the Borough.</gov-body>
<gov-button start :to="{ name: 'locations-index' }">
Expand All @@ -42,7 +42,7 @@
<gov-section-break size="m" />
</gov-grid-column>

<gov-grid-column width="one-half" v-if="!auth.isOnlyContentAdmin">
<gov-grid-column width="one-half" v-if="auth.canView('referrals')">
<gov-heading size="l">Referrals</gov-heading>
<gov-body>View and respond to referrals to your service(s).</gov-body>
<gov-button start :to="{ name: 'referrals-index' }">
Expand All @@ -51,7 +51,7 @@
<gov-section-break size="m" />
</gov-grid-column>

<gov-grid-column width="one-half" v-if="auth.isGlobalAdmin">
<gov-grid-column width="one-half" v-if="auth.canView('organisations')">
<gov-heading size="l">Organisations</gov-heading>
<gov-body>Add or edit organisations on {{ appName }}.</gov-body>
<gov-button start :to="{ name: 'organisations-index' }">
Expand All @@ -60,7 +60,7 @@
<gov-section-break size="m" />
</gov-grid-column>

<gov-grid-column width="one-half" v-if="auth.isOrganisationAdmin()">
<gov-grid-column width="one-half" v-if="auth.canView('events')">
<gov-heading size="l">Events</gov-heading>
<gov-body>Add or edit events on {{ appName }}.</gov-body>
<gov-button start :to="{ name: 'events-index' }">
Expand All @@ -69,7 +69,7 @@
<gov-section-break size="m" />
</gov-grid-column>

<gov-grid-column width="one-half" v-if="!auth.isOnlyContentAdmin">
<gov-grid-column width="one-half" v-if="auth.canView('users')">
<gov-heading size="l">Users</gov-heading>
<gov-body>View, add and edit users in your organisation.</gov-body>
<gov-button start :to="{ name: 'users-index' }">
Expand All @@ -78,7 +78,7 @@
<gov-section-break size="m" />
</gov-grid-column>

<gov-grid-column width="one-half" v-if="auth.isGlobalAdmin">
<gov-grid-column width="one-half" v-if="auth.canView('reports')">
<gov-heading size="l">Reports</gov-heading>
<gov-body> Download reports of activity on {{ appName }}. </gov-body>
<gov-button start :to="{ name: 'reports-index' }">
Expand All @@ -87,23 +87,26 @@
<gov-section-break size="m" />
</gov-grid-column>

<gov-grid-column width="one-half" v-if="auth.isContentAdmin">
<gov-grid-column width="one-half" v-if="auth.canView('pages')">
<gov-heading size="l">Pages</gov-heading>
<gov-body>Manage pages on the platform.</gov-body>
<gov-button start :to="{ name: 'pages-index' }">
Go to pages
</gov-button>
</gov-grid-column>

<gov-grid-column width="one-half" v-if="auth.isGlobalAdmin">
<gov-grid-column width="one-half" v-if="auth.canView('admin')">
<gov-heading size="l">Admin</gov-heading>
<gov-body>Admin tools for maintaining the site.</gov-body>
<gov-button start :to="{ name: 'admin-index' }">
Go to admin
</gov-button>
</gov-grid-column>

<gov-grid-column width="one-half" v-if="auth.isGlobalAdmin">
<gov-grid-column
width="one-half"
v-if="auth.canView('update requests')"
>
<gov-heading size="l">Update Requests</gov-heading>
<gov-body>View, approve and reject update requests.</gov-body>
<gov-button start :to="{ name: 'update-requests-index' }">
Expand Down
Loading

0 comments on commit 3f8ba02

Please sign in to comment.