diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..2473414 Binary files /dev/null and b/.DS_Store differ diff --git a/lib/Controller/AgencyController.php b/lib/Controller/AgencyController.php index 094168d..5ee8052 100644 --- a/lib/Controller/AgencyController.php +++ b/lib/Controller/AgencyController.php @@ -79,7 +79,14 @@ class AgencyController extends Controller { */ public function update(int $id, string $name, string $inhaber, string $street, string $plz, string $city, string $agencymail, string $phone) { return $this->handleNotFound(function () use ($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone) { - return $this->service->update($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone); + # TODO: ABfrage machen! + if($this->agencyuserservice->checkAgencyIdUserId($this->userSession->getUser()->getUid(), $id)){ + return $this->service->update($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone); + } + else { + return false; + } + }); } diff --git a/lib/Service/AgencyUserService.php b/lib/Service/AgencyUserService.php index 8746c40..260d301 100644 --- a/lib/Service/AgencyUserService.php +++ b/lib/Service/AgencyUserService.php @@ -27,7 +27,7 @@ class AgencyUserService { } } - //Find an Agency + //Find an Agency-User public function find(int $id) { try { return $this->mapper->find($id); @@ -36,13 +36,18 @@ class AgencyUserService { } } - //Find an Agency + //Find an Agency-User public function getAgencyIdByUserUid(string $useruid) { - return $this->mapper->getAgencyIdByUserUid($useruid); - //try { - // return $this->mapper->getAgencyIdByUserUid($useruid); - //} catch(Exception $e) { - // $this->handleException($e); - //} + try { + return $this->mapper->getAgencyIdByUserUid($useruid); + } catch(Exception $e) { + $this->handleException($e); + } + } + + //Checks, if a given User is in given Agency. Use for secure reason to make save, that agencydata is only changed by user which belongs to that agency. + public function checkAgencyIdUserId(string $useruid, int $agencyid){ + # TODO: Hier einmal prüfen, dass der eingeloggte Nutzer auch zur angefragten Agentur passt! + return false; } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 52a865c..26f0d4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10174,6 +10174,11 @@ "date-format-parse": "0.2.6" } }, + "vuex": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/vuex/-/vuex-3.6.2.tgz", + "integrity": "sha512-ETW44IqCgBpVomy520DT5jf8n0zoCac+sxWnn+hMe/CzaSejb/eVw2YToiXYX+Ex/AuHHia28vWTq4goAexFbw==" + }, "watchpack": { "version": "1.7.5", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.7.5.tgz", diff --git a/package.json b/package.json index 10e2d90..a51c7b8 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "bootstrap": "^5.0.1", "bootstrap-vue": "^2.21.2", "vue": "^2.6.12", - "vue-router": "^3.5.1" + "vue-router": "^3.5.1", + "vuex": "^3.6.2" }, "browserslist": [ "extends @nextcloud/browserslist-config" diff --git a/src/main.js b/src/main.js index 32411b4..b32f1b8 100644 --- a/src/main.js +++ b/src/main.js @@ -7,6 +7,7 @@ import { de } from '@braid/vue-formulate-i18n' import { BootstrapVue, IconsPlugin } from 'bootstrap-vue' import 'bootstrap/dist/css/bootstrap.css' import 'bootstrap-vue/dist/bootstrap-vue.css' +import store from './store' Vue.use(VueRouter) Vue.use(VueFormulate, { @@ -24,5 +25,6 @@ const router = new VueRouter({ export default new Vue({ el: '#content', router, + store, render: h => h(App), }) diff --git a/src/store.js b/src/store.js new file mode 100644 index 0000000..6f36ce8 --- /dev/null +++ b/src/store.js @@ -0,0 +1,40 @@ +import Vue from 'vue' +import Vuex from 'vuex' +import { generateUrl } from '@nextcloud/router' +const axios = require('axios').default + +Vue.use(Vuex) + +export default new Vuex.Store({ + state: { + agencyId: null, + agency: null, + }, + mutations: { + getAgencyId(state) { + return state.agencyId + }, + setAgencyId(state, id) { + state.agencyId = id + }, + getAgency(state) { + return state.agency + }, + setAgency(state, agency) { + state.agency = agency + }, + }, + actions: { + loadAgencyData({ commit }) { + // axios.get(generateUrl('/apps/agency/getagencyidbyuser')).then(response => { + // console.log('Here we load...') + // this.agencyId = response.data.agency + // }) + this.$store.state.agencyId + const agencydata = axios.get(generateUrl('/apps/agency/agencys/4')).then(function() { + commit('setAgency', agencydata.data) + return true + }) + return false + }, + }, +}) diff --git a/src/views/AgencyData.vue b/src/views/AgencyData.vue index d9d2153..c8b2058 100644 --- a/src/views/AgencyData.vue +++ b/src/views/AgencyData.vue @@ -69,7 +69,7 @@ - + @@ -77,7 +77,6 @@