From 34dfae8face3d457fb111780fce3d2f39f49b412 Mon Sep 17 00:00:00 2001 From: James Chang Date: Sun, 7 Mar 2021 13:18:01 -0500 Subject: [PATCH] frontend updates, backend bug fixes --- .../src/schema/helpers/permissions.ts | 21 +- frontend/components/input/genericInput.vue | 492 ++++++++++++++++++ .../interface/crud/deleteRecordInterface.vue | 2 +- .../interface/crud/editRecordInterface.vue | 168 +----- .../interface/crud/shareRecordInterface.vue | 2 +- .../components/navigation/adminNavRoutes.vue | 60 +++ frontend/components/page/viewRecordPage.vue | 14 +- .../table/common/createdByColumn.vue | 25 - .../components/table/common/userColumn.vue | 17 +- frontend/layouts/default.vue | 109 +--- frontend/middleware/router-auth.js | 6 +- frontend/mixins/crud.js | 26 +- frontend/mixins/editRecordInterface.js | 64 +-- frontend/models/personalBest.ts | 6 +- frontend/models/special/index.ts | 1 + frontend/models/special/myProfile.ts | 8 + frontend/models/user.ts | 6 +- frontend/package-lock.json | 13 + frontend/package.json | 3 +- frontend/pages/admin/_type/index.vue | 25 + frontend/pages/admin/events.vue | 20 - frontend/pages/admin/personalBestClasses.vue | 20 - frontend/pages/admin/personalBests.vue | 20 - frontend/pages/admin/products.vue | 20 - frontend/pages/admin/users.vue | 20 - frontend/pages/my-profile.vue | 36 ++ frontend/types/index.ts | 11 +- 27 files changed, 734 insertions(+), 481 deletions(-) create mode 100644 frontend/components/input/genericInput.vue create mode 100644 frontend/components/navigation/adminNavRoutes.vue delete mode 100644 frontend/components/table/common/createdByColumn.vue create mode 100644 frontend/models/special/myProfile.ts create mode 100644 frontend/pages/admin/_type/index.vue delete mode 100644 frontend/pages/admin/events.vue delete mode 100644 frontend/pages/admin/personalBestClasses.vue delete mode 100644 frontend/pages/admin/personalBests.vue delete mode 100644 frontend/pages/admin/products.vue delete mode 100644 frontend/pages/admin/users.vue create mode 100644 frontend/pages/my-profile.vue diff --git a/backend/functions/src/schema/helpers/permissions.ts b/backend/functions/src/schema/helpers/permissions.ts index be71c3b..db23e2c 100644 --- a/backend/functions/src/schema/helpers/permissions.ts +++ b/backend/functions/src/schema/helpers/permissions.ts @@ -1,6 +1,5 @@ -import * as sqlHelper from "./sql"; import { userRoleKenum, userPermissionEnum } from "../enums"; -import { BaseService } from "../core/services"; +import { BaseService, NormalService } from "../core/services"; import * as errorHelper from "./error"; import { ServiceFunctionInputs, AccessControlFunction } from "../../types"; import { StringKeyObject } from "jomql"; @@ -11,24 +10,22 @@ export const userRoleToPermissionsMap = { }; export function generateItemCreatedByUserGuard( - service: BaseService + service: NormalService ): AccessControlFunction { - return async function ({ req, args }) { + return async function ({ req, args, fieldPath }) { // args should be validated already const validatedArgs = args; //check if logged in if (!req.user) return false; try { - const results = await sqlHelper.fetchTableRows({ - select: [{ field: "created_by" }], - from: service.typename, - where: { - fields: [{ field: "id", value: validatedArgs.id }], - }, - }); + const itemRecord = await service.lookupRecord( + [{ field: "created_by" }], + validatedArgs.item ?? validatedArgs, + fieldPath + ); - return results[0]?.created_by === req.user.id; + return itemRecord?.created_by === req.user.id; } catch (err) { return false; } diff --git a/frontend/components/input/genericInput.vue b/frontend/components/input/genericInput.vue new file mode 100644 index 0000000..fd7654e --- /dev/null +++ b/frontend/components/input/genericInput.vue @@ -0,0 +1,492 @@ + + + diff --git a/frontend/components/interface/crud/deleteRecordInterface.vue b/frontend/components/interface/crud/deleteRecordInterface.vue index e48e54f..042a6ac 100644 --- a/frontend/components/interface/crud/deleteRecordInterface.vue +++ b/frontend/components/interface/crud/deleteRecordInterface.vue @@ -47,7 +47,7 @@ export default { itemIdentifier() { return this.recordInfo.renderItem ? this.recordInfo.renderItem(this.selectedItem) - : this.selectedItem + : JSON.stringify(this.selectedItem, null, 2) }, capitalizedTypename() { diff --git a/frontend/components/interface/crud/editRecordInterface.vue b/frontend/components/interface/crud/editRecordInterface.vue index 4a55f4f..7e140b9 100644 --- a/frontend/components/interface/crud/editRecordInterface.vue +++ b/frontend/components/interface/crud/editRecordInterface.vue @@ -19,173 +19,7 @@ cols="12" class="py-0" > -
- - - -
- - - - - - - - - - - - + diff --git a/frontend/components/interface/crud/shareRecordInterface.vue b/frontend/components/interface/crud/shareRecordInterface.vue index 9f3792c..9bbb17d 100644 --- a/frontend/components/interface/crud/shareRecordInterface.vue +++ b/frontend/components/interface/crud/shareRecordInterface.vue @@ -59,7 +59,7 @@ export default { itemIdentifier() { return this.recordInfo.renderItem ? this.recordInfo.renderItem(this.selectedItem) - : this.selectedItem + : JSON.stringify(this.selectedItem, null, 2) }, }, diff --git a/frontend/components/navigation/adminNavRoutes.vue b/frontend/components/navigation/adminNavRoutes.vue new file mode 100644 index 0000000..6e3024a --- /dev/null +++ b/frontend/components/navigation/adminNavRoutes.vue @@ -0,0 +1,60 @@ + + + diff --git a/frontend/components/page/viewRecordPage.vue b/frontend/components/page/viewRecordPage.vue index 6684e10..8e3fbec 100644 --- a/frontend/components/page/viewRecordPage.vue +++ b/frontend/components/page/viewRecordPage.vue @@ -56,7 +56,10 @@ mdi-delete @@ -124,6 +127,7 @@ diff --git a/frontend/components/table/common/userColumn.vue b/frontend/components/table/common/userColumn.vue index 6a9c48e..219220a 100644 --- a/frontend/components/table/common/userColumn.vue +++ b/frontend/components/table/common/userColumn.vue @@ -1,19 +1,30 @@ diff --git a/frontend/layouts/default.vue b/frontend/layouts/default.vue index e3f4c04..69be8d6 100644 --- a/frontend/layouts/default.vue +++ b/frontend/layouts/default.vue @@ -7,10 +7,6 @@ fixed app > - - - - - - - mdi-card-account-details - - - My Profile - - - - - - - - + - + + +