This commit is contained in:
2019-07-24 15:09:00 +00:00
parent 604fe1dd72
commit 565a092251
10 changed files with 77 additions and 76 deletions

View File

@@ -1,10 +1,9 @@
/* xeslint-disable */ /* xeslint-disable */
import store from "../store"; import bizrolerights from "./biz-role-rights";
import rights from "./bizroles";
export default { export default {
ROLE_RIGHTS: rights, ROLE_RIGHTS: bizrolerights,
AUTHORIZATION_ROLES: { AUTHORIZATION_ROLES: {
///<summary>No role set</summary> ///<summary>No role set</summary>
NoRole: 0, NoRole: 0,
@@ -40,10 +39,10 @@ export default {
OpsAdminFull: 16384 OpsAdminFull: 16384
}, },
hasRole(desiredRole) { hasRole(desiredRole) {
if (!store.state.roles || store.state.roles === 0) { if (!window.$gz.store.state.roles || window.$gz.store.state.roles === 0) {
return false; return false;
} }
return (store.state.roles & desiredRole) != 0; return (window.$gz.store.state.roles & desiredRole) != 0;
}, },
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// Get a default empty rights object so that it can be present when a // Get a default empty rights object so that it can be present when a
@@ -59,7 +58,7 @@ export default {
///////////////////////////////// /////////////////////////////////
// oType is the name of the object type as defined in ayatype.js // oType is the name of the object type as defined in ayatype.js
// //
getRights(vm, oType) { getRights(oType) {
//from bizroles.cs: //from bizroles.cs:
//HOW THIS WORKS / WHATS EXPECTED //HOW THIS WORKS / WHATS EXPECTED
//Change = CREATE, RETRIEVE, UPDATE, DELETE - Full rights //Change = CREATE, RETRIEVE, UPDATE, DELETE - Full rights
@@ -80,7 +79,7 @@ export default {
var objectRoleRights = this.ROLE_RIGHTS[typeName]; var objectRoleRights = this.ROLE_RIGHTS[typeName];
//get the logged in user's role //get the logged in user's role
var userRole = vm.$store.state.roles; var userRole = window.$gz.store.state.roles;
//calculate the effective rights //calculate the effective rights
//a non zero result of the bitwise calculation means true and zero means false so using !! to force it into a boolean value (contrary to some style guides that say !! is obscure but I say it saves a lot of typing) //a non zero result of the bitwise calculation means true and zero means false so using !! to force it into a boolean value (contrary to some style guides that say !! is obscure but I say it saves a lot of typing)

View File

@@ -1,34 +1,29 @@
/* xeslint-disable */ /* xeslint-disable */
import decode from "jwt-decode"; import decode from "jwt-decode";
import store from "../store";
import initialize from "./initialize"; import initialize from "./initialize";
// var secondMethod = function(someStuff) {
// var promise = new Promise(function(resolve, reject) {
// setTimeout(function() {
// console.log("second method completed");
// resolve({ newData: someStuff.data + " some more data" });
// }, 2000);
// });
// return promise;
// };
export function processLogin(response) { export function processLogin(response) {
var promise = new Promise(function(resolve, reject) { var promise = new Promise(function(resolve, reject) {
//is token present? //is token present?
if (!response || !response.data || !response.data.token) { if (!response || !response.data || !response.data.token) {
store.commit("logItem", "auth::processLogin -> response empty"); window.$gz.store.commit(
"logItem",
"auth::processLogin -> response empty"
);
return reject(); return reject();
} }
const token = decode(response.data.token); const token = decode(response.data.token);
if (!token || !token.iss) { if (!token || !token.iss) {
store.commit("logItem", "auth::processLogin -> response token empty"); window.$gz.store.commit(
"logItem",
"auth::processLogin -> response token empty"
);
return reject(); return reject();
} }
if (token.iss != "ayanova.com") { if (token.iss != "ayanova.com") {
store.commit( window.$gz.store.commit(
"logItem", "logItem",
"auth::processLogin -> token invalid (iss): " + token.iss "auth::processLogin -> token invalid (iss): " + token.iss
); );
@@ -36,7 +31,7 @@ export function processLogin(response) {
} }
//Put app relevant items into vuex store so app can use them //Put app relevant items into vuex store so app can use them
store.commit("login", { window.$gz.store.commit("login", {
apiToken: response.data.token, apiToken: response.data.token,
authenticated: true, authenticated: true,
userId: Number(token.id), userId: Number(token.id),
@@ -46,7 +41,7 @@ export function processLogin(response) {
//Initialize the application //Initialize the application
initialize().then(() => { initialize().then(() => {
store.commit( window.$gz.store.commit(
"logItem", "logItem",
"auth::processLogin -> User " + token.id + " logged in" "auth::processLogin -> User " + token.id + " logged in"
); );
@@ -57,16 +52,22 @@ export function processLogin(response) {
} }
export function processLogout() { export function processLogout() {
if (store.state.authenticated) { if (window.$gz.store.state.authenticated) {
store.commit("logItem", "auth::processLogout -> User logged out"); window.$gz.store.commit(
"logItem",
"auth::processLogout -> User logged out"
);
} }
store.commit("logout"); window.$gz.store.commit("logout");
sessionStorage.clear(); //clear all temporary session storage data sessionStorage.clear(); //clear all temporary session storage data
} }
export function isLoggedIn() { export function isLoggedIn() {
//const token = getToken(); //const token = getToken();
return !!store.state.apiToken && !isTokenExpired(store.state.apiToken); return (
!!window.$gz.store.state.apiToken &&
!isTokenExpired(window.$gz.store.state.apiToken)
);
} }
function getTokenExpirationDate(encodedToken) { function getTokenExpirationDate(encodedToken) {

View File

@@ -1,7 +1,5 @@
/* Xeslint-disable */ /* Xeslint-disable */
import store from "../store";
import locale from "./locale";
import gzevent from "./eventbus";
var devModeShowErrors = false; var devModeShowErrors = false;
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
@@ -9,20 +7,20 @@ var devModeShowErrors = false;
// Localize, Log and optionally display errors // Localize, Log and optionally display errors
// return localized message in case caller needs it // return localized message in case caller needs it
function dealWithError(msg, vm) { function dealWithError(msg, vm) {
msg = locale.translateString(msg); msg = window.$gz.locale.translateString(msg);
//In some cases the error may not be localizable, if this is not a debug run then it should show without the ?? that localizing puts in keys not found //In some cases the error may not be localizable, if this is not a debug run then it should show without the ?? that localizing puts in keys not found
//so it's not as wierd looking to the user //so it's not as wierd looking to the user
if (!devModeShowErrors && msg.includes("??")) { if (!devModeShowErrors && msg.includes("??")) {
msg = msg.replace("??", ""); msg = msg.replace("??", "");
} }
store.commit("logItem", msg); window.$gz.store.commit("logItem", msg);
if (devModeShowErrors) { if (devModeShowErrors) {
var errMsg = var errMsg =
"DEV ERROR errorHandler::devShowUnknownError - unexpected error: \r\n" + "DEV ERROR errorHandler::devShowUnknownError - unexpected error: \r\n" +
msg; msg;
//eslint-disable-next-line //eslint-disable-next-line
console.log(errMsg); console.log(errMsg);
gzevent.$emit("notify-error", errMsg); window.$gz.eventbus.$emit("notify-error", errMsg);
} }
//If a form instance was provided (vue instance) //If a form instance was provided (vue instance)

View File

@@ -1,7 +1,4 @@
/*e slint-disable */ /*e slint-disable */
import store from "../store";
import gzapi from "./gzapi";
import _ from "../libs/lodash.min.js";
///Add data key names which make the custom fields control work more easily ///Add data key names which make the custom fields control work more easily
///Since the names can be inferred from the data that comes from the server it saves bandwidth to do it here at the client ///Since the names can be inferred from the data that comes from the server it saves bandwidth to do it here at the client
@@ -21,14 +18,16 @@ function addDataKeyNames(obj) {
export default { export default {
get(formKey) { get(formKey) {
return new Promise(function getFormTemplate(resolve) { return new Promise(function getFormTemplate(resolve) {
if (!_.has(store.state.formCustomTemplate, formKey)) { if (
!window.$gz._.has(window.$gz.store.state.formCustomTemplate, formKey)
) {
//fetch and populate the store //fetch and populate the store
gzapi.get("formcustom/" + formKey).then(res => { window.$gz.api.get("formcustom/" + formKey).then(res => {
if (res.error) { if (res.error) {
throw res.error; throw res.error;
} }
store.commit("addFormCustomTemplateItem", { window.$gz.store.commit("addFormCustomTemplateItem", {
formKey: formKey, formKey: formKey,
value: addDataKeyNames(JSON.parse(res.data.template)) value: addDataKeyNames(JSON.parse(res.data.template))
}); });

View File

@@ -1,11 +1,6 @@
/* Xeslint-disable */ /* Xeslint-disable */
import _ from "../libs/lodash.min.js";
import store from "../store";
import router from "../router"; import router from "../router";
import auth from "./auth"; import auth from "./auth";
import errorHandler from "./errorhandler";
import gzevent from "./eventbus";
import gzlocale from "./locale";
function stringifyPrimitive(v) { function stringifyPrimitive(v) {
switch (typeof v) { switch (typeof v) {
@@ -27,13 +22,13 @@ function stringifyPrimitive(v) {
// Show unexpected errors during development // Show unexpected errors during development
// //
function devShowUnknownError(error) { function devShowUnknownError(error) {
if (errorHandler.devMode) { if (window.$gz.errorHandler.devMode) {
// eslint-disable-next-line // eslint-disable-next-line
console.log("gzapi::devShowUnknownError, error is:"); console.log("gzapi::devShowUnknownError, error is:");
// eslint-disable-next-line // eslint-disable-next-line
console.log(error); console.log(error);
gzevent.$emit( window.$gz.eventBus.$emit(
"notify-warning", "notify-warning",
"DEV ERROR gzapi::devShowUnknownError - unexpected error during api operation see console " "DEV ERROR gzapi::devShowUnknownError - unexpected error during api operation see console "
); );
@@ -47,7 +42,7 @@ function devShowUnknownError(error) {
function handleError(action, error, route, reject) { function handleError(action, error, route, reject) {
var errorMessage = var errorMessage =
"API error: " + action + " route =" + route + ", message =" + error.message; "API error: " + action + " route =" + route + ", message =" + error.message;
store.commit("logItem", errorMessage); window.$gz.store.commit("logItem", errorMessage);
//Handle 403 not authorized //Handle 403 not authorized
//popup not authorized, log, then go to HOME //popup not authorized, log, then go to HOME
@@ -55,16 +50,25 @@ function handleError(action, error, route, reject) {
//reaction to directly entered or opened link, not application logic driving it, so home is safest choice //reaction to directly entered or opened link, not application logic driving it, so home is safest choice
// //
if (error.message && error.message.includes("NotAuthorized")) { if (error.message && error.message.includes("NotAuthorized")) {
store.commit("logItem", "Not authorized, redirecting to HOME"); window.$gz.store.commit("logItem", "Not authorized, redirecting to HOME");
gzevent.$emit("notify-warning", gzlocale.get("ErrorUserNotAuthorized")); window.$gz.eventBus.$emit(
"notify-warning",
window.$gz.locale.get("ErrorUserNotAuthorized")
);
router.push("/"); router.push("/");
return reject("[ErrorUserNotAuthorized]"); return reject("[ErrorUserNotAuthorized]");
} }
//Handle 401 not authenticated //Handle 401 not authenticated
if (error.message && error.message.includes("NotAuthenticated")) { if (error.message && error.message.includes("NotAuthenticated")) {
store.commit("logItem", "User is not authenticated, redirecting to LOGIN"); window.$gz.store.commit(
gzevent.$emit("notify-error", gzlocale.get("ErrorUserNotAuthenticated")); "logItem",
"User is not authenticated, redirecting to LOGIN"
);
window.$gz.eventBus.$emit(
"notify-error",
window.$gz.locale.get("ErrorUserNotAuthenticated")
);
auth.logout(); auth.logout();
router.push("/login"); router.push("/login");
return reject("[ErrorUserNotAuthenticated]"); return reject("[ErrorUserNotAuthenticated]");
@@ -78,7 +82,7 @@ function handleError(action, error, route, reject) {
error.message.includes("NetworkError") || error.message.includes("NetworkError") ||
error.message.includes("Network request failed") error.message.includes("Network request failed")
) { ) {
store.commit("logItem", "Network error"); window.$gz.store.commit("logItem", "Network error");
//note: using locale key in square brackets //note: using locale key in square brackets
return reject("[ErrorServerUnresponsive]"); return reject("[ErrorServerUnresponsive]");
//throw "Error: unable to contact server"; //throw "Error: unable to contact server";
@@ -105,7 +109,7 @@ export default {
return Promise.resolve(response); return Promise.resolve(response);
} else { } else {
//log unhandled api error //log unhandled api error
store.commit( window.$gz.store.commit(
"logItem", "logItem",
"API error: status=" + "API error: status=" +
response.status + response.status +
@@ -134,14 +138,14 @@ export default {
//Accept: "application/json, text/plain, */*", //Accept: "application/json, text/plain, */*",
Accept: "application/json", Accept: "application/json",
"Content-Type": "application/json-patch+json", "Content-Type": "application/json-patch+json",
Authorization: "Bearer " + store.state.apiToken Authorization: "Bearer " + window.$gz.store.state.apiToken
}; };
}, },
postAuthorizedHeaders() { postAuthorizedHeaders() {
return { return {
Accept: "application/json", Accept: "application/json",
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: "Bearer " + store.state.apiToken Authorization: "Bearer " + window.$gz.store.state.apiToken
}; };
}, },
postUnAuthorizedHeaders() { postUnAuthorizedHeaders() {
@@ -191,7 +195,7 @@ export default {
}; };
}, },
APIUrl(apiPath) { APIUrl(apiPath) {
if ("" == store.state.apiUrl) { if ("" == window.$gz.store.state.apiUrl) {
//construct the api url and store it //construct the api url and store it
//development location? //development location?
if ( if (
@@ -199,29 +203,30 @@ export default {
window.location.hostname == "192.168.1.56") && window.location.hostname == "192.168.1.56") &&
window.location.port == "8080" window.location.port == "8080"
) { ) {
store.commit("setAPIURL", "http://localhost:7575/api/v8.0/"); window.$gz.store.commit("setAPIURL", "http://localhost:7575/api/v8.0/");
store.commit("setHelpURL", "http://localhost:7575/docs/"); window.$gz.store.commit("setHelpURL", "http://localhost:7575/docs/");
store.commit( window.$gz.store.commit(
"logItem", "logItem",
"gzapi::APIUrl -> setting to dev. mode: " + store.state.apiUrl "gzapi::APIUrl -> setting to dev. mode: " +
window.$gz.store.state.apiUrl
); );
} else { } else {
//production location <protocol>//<hostname>:<port>/ //production location <protocol>//<hostname>:<port>/
store.commit( window.$gz.store.commit(
"setHelpURL", "setHelpURL",
window.location.protocol + "//" + window.location.host + "/docs/" window.location.protocol + "//" + window.location.host + "/docs/"
); );
store.commit( window.$gz.store.commit(
"setAPIURL", "setAPIURL",
window.location.protocol + "//" + window.location.host + "/api/v8.0/" window.location.protocol + "//" + window.location.host + "/api/v8.0/"
); );
store.commit( window.$gz.store.commit(
"logItem", "logItem",
"gzapi::APIUrl -> setting to: " + store.state.apiUrl "gzapi::APIUrl -> setting to: " + window.$gz.store.state.apiUrl
); );
} }
} }
return store.state.apiUrl + apiPath; return window.$gz.store.state.apiUrl + apiPath;
}, },
///////////////////////////// /////////////////////////////
// REPLACE END OF URL // REPLACE END OF URL
@@ -297,7 +302,7 @@ export default {
//Does not have a concurrency token so this is a POST as it's posting a new record without a concurrency token //Does not have a concurrency token so this is a POST as it's posting a new record without a concurrency token
fetchOptions = that.fetchPostOptions(data); fetchOptions = that.fetchPostOptions(data);
//ensure the route doesn't end in /0 which will happen if it's a new record since the edit forms just send the url here with the ID regardless //ensure the route doesn't end in /0 which will happen if it's a new record since the edit forms just send the url here with the ID regardless
if (_.endsWith(route, "/0")) { if (window.$gz._.endsWith(route, "/0")) {
route = route.slice(0, -2); route = route.slice(0, -2);
} }
} }

View File

@@ -10,8 +10,6 @@
// All locale keys for validation *MUST* be fetched prior to this being used as it assumes all keys are fetched first // All locale keys for validation *MUST* be fetched prior to this being used as it assumes all keys are fetched first
// Add any new keys used to the block in locale.js=>commonKeysEditForm // Add any new keys used to the block in locale.js=>commonKeysEditForm
import Vue from "vue"; import Vue from "vue";
import errorHandler from "./errorhandler";
import store from "../store";
var triggeringChange = false; var triggeringChange = false;
@@ -65,7 +63,7 @@ function getControlValue(ctrl) {
// Get field name from control // Get field name from control
// //
function getControlLabel(ctrl) { function getControlLabel(ctrl) {
if (errorHandler.developmentModeShowErrorsImmediately) { if (window.$gz.errorHandler.developmentModeShowErrorsImmediately) {
if (!ctrl.label) { if (!ctrl.label) {
throw "gzform:getControlLabel - the control has no label " + ctrl; throw "gzform:getControlLabel - the control has no label " + ctrl;
} }
@@ -322,7 +320,7 @@ export default {
// //
serverErrors(vm, ref) { serverErrors(vm, ref) {
//CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDED DATA ATTRIBUTES ETC //CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDED DATA ATTRIBUTES ETC
if (window.$gz.errorHandler.devMode()) { if (window.$gz.window.$gz.errorHandler.devMode()) {
//make sure formState.serverErrors is defined on data //make sure formState.serverErrors is defined on data
if (!window.$gz._.has(vm, "formState.serverError")) { if (!window.$gz._.has(vm, "formState.serverError")) {
throw "DEV ERROR gzform::formState.serverErrors -> formState.serverError seems to be missing from form's vue data object"; throw "DEV ERROR gzform::formState.serverErrors -> formState.serverError seems to be missing from form's vue data object";
@@ -517,7 +515,7 @@ export default {
getFormSettings(formKey) { getFormSettings(formKey) {
return { return {
temp: JSON.parse(sessionStorage.getItem(formKey)), temp: JSON.parse(sessionStorage.getItem(formKey)),
saved: store.state.formSettings[formKey] saved: window.$gz.store.state.formSettings[formKey]
}; };
}, },
//////////////////////////////////// ////////////////////////////////////
@@ -526,14 +524,14 @@ export default {
// requires object with one or both keys {temp:{...tempformsettings...},saved:{...persistedformsettings...}} // requires object with one or both keys {temp:{...tempformsettings...},saved:{...persistedformsettings...}}
// //
setFormSettings(formKey, formSettings) { setFormSettings(formKey, formSettings) {
if (errorHandler.devMode()) { if (window.$gz.errorHandler.devMode()) {
if (!formSettings.saved && !formSettings.temp) { if (!formSettings.saved && !formSettings.temp) {
throw "gzform:setFormSettings - saved AND temp keys are both missing from form data!"; throw "gzform:setFormSettings - saved AND temp keys are both missing from form data!";
} }
} }
if (formSettings.saved) { if (formSettings.saved) {
store.commit("setFormSettings", { window.$gz.store.commit("setFormSettings", {
formKey: formKey, formKey: formKey,
formSettings: formSettings.saved formSettings: formSettings.saved
}); });

View File

@@ -114,7 +114,7 @@ export default {
}) })
.then(() => { .then(() => {
//don't have access to local data object until here //don't have access to local data object until here
that.rights = window.$gz.role.getRights(this, window.$gz.type.Widget); that.rights = window.$gz.role.getRights(window.$gz.type.Widget);
var formSettings = window.$gz.form.getFormSettings(FORM_KEY); var formSettings = window.$gz.form.getFormSettings(FORM_KEY);
/** /**
* { * {

View File

@@ -57,7 +57,8 @@ window.$gz = {
api: gzapi, api: gzapi,
form: gzform, form: gzform,
report: gzreport, report: gzreport,
errorHandler: errorhandler errorHandler: errorhandler,
store: store
}; };
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////

View File

@@ -258,7 +258,7 @@ export default {
}); });
}, },
created() { created() {
this.rights = window.$gz.role.getRights(this, window.$gz.type.Widget); this.rights = window.$gz.role.getRights(window.$gz.type.Widget);
window.$gz.eventbus.$on("menu-click", clickHandler); window.$gz.eventbus.$on("menu-click", clickHandler);
//id 0 means create a new record don't load one //id 0 means create a new record don't load one