diff --git a/src/api/ADempiere/data.js b/src/api/ADempiere/data.js index 331c145f..a1d9f99e 100644 --- a/src/api/ADempiere/data.js +++ b/src/api/ADempiere/data.js @@ -319,6 +319,18 @@ export function getContextInfoValueFromServer({ uuid, query }) { return Instance.call(this).getContextInfoValue({ uuid: uuid, query: query }) } +export function getPrivateAccessFromServer({ tableName: tableName, recordId: recordId, userUuid: userUuid }) { + return Instance.call(this).getPrivateAccess({ tableName: tableName, recordId: recordId, userUuid: userUuid }) +} + +export function lockPrivateAccessFromServer({ tableName: tableName, recordId: recordId, userUuid: userUuid }) { + return Instance.call(this).lockPrivateAccess({ tableName: tableName, recordId: recordId, userUuid: userUuid }) +} + +export function unlockPrivateAccessFromServer({ tableName: tableName, recordId: recordId, userUuid: userUuid }) { + return Instance.call(this).unlockPrivateAccess({ tableName: tableName, recordId: recordId, userUuid: userUuid }) +} + export function getFavoritesFromServer(userUuid) { return Instance.call(this).requestFavorites(userUuid) } diff --git a/src/api/user.js b/src/api/user.js index d58ec48c..cc11de27 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -51,6 +51,8 @@ export function getInfo(token) { const user = session.getUserinfo() const response = { + id: user.getId(), + uuid: user.getUuid(), name: user.getName(), comments: user.getComments(), description: user.getDescription(), diff --git a/src/components/ADempiere/ContextMenu/contextMenuDesktop.vue b/src/components/ADempiere/ContextMenu/contextMenuDesktop.vue index ef57cde4..bc27b83d 100644 --- a/src/components/ADempiere/ContextMenu/contextMenuDesktop.vue +++ b/src/components/ADempiere/ContextMenu/contextMenuDesktop.vue @@ -26,7 +26,7 @@ {{ child.name }} - + {{ action.name }} diff --git a/src/components/ADempiere/ContextMenu/contextMenuMixin.js b/src/components/ADempiere/ContextMenu/contextMenuMixin.js index 1b661bc6..2dee48fe 100644 --- a/src/components/ADempiere/ContextMenu/contextMenuMixin.js +++ b/src/components/ADempiere/ContextMenu/contextMenuMixin.js @@ -275,6 +275,15 @@ export const contextMixin = { }, generateContextMenu() { this.metadataMenu = this.getterContextMenu + this.$store.dispatch('getPrivateAccessFromServer', { + tableName: this.$route.params.tableName, + recordId: this.$route.params.recordId + }) + .then(response => { + this.$nextTick(() => { + this.validatePrivateAccess(response) + }) + }) this.actions = this.metadataMenu.actions if (this.actions && this.actions.length) { @@ -401,8 +410,15 @@ export const contextMixin = { containerUuid: this.containerUuid, recordUuid: this.recordUuid, panelType: this.panelType, - isNewRecord: action.action === 'resetPanelToNew' + isNewRecord: action.action === 'resetPanelToNew', + tableName: action.tableName, + recordId: action.recordId }) + .then(response => { + if (response && response.isPrivateAccess) { + this.validatePrivateAccess(response) + } + }) } } else if (action.type === 'reference') { this.$store.dispatch('getWindowByUuid', { routes: this.permissionRoutes, windowUuid: action.windowUuid }) @@ -483,6 +499,19 @@ export const contextMixin = { type: 'success', duration: 1500 }) + }, + validatePrivateAccess(response) { + if (response.isLocked) { + this.actions.find(item => item.action === 'unlockRecord').hidden = false + this.actions.find(item => item.action === 'unlockRecord').tableName = response.tableName + this.actions.find(item => item.action === 'unlockRecord').recordId = response.recordId + this.actions.find(item => item.action === 'lockRecord').hidden = true + } else { + this.actions.find(item => item.action === 'lockRecord').hidden = false + this.actions.find(item => item.action === 'lockRecord').tableName = response.tableName + this.actions.find(item => item.action === 'lockRecord').recordId = response.recordId + this.actions.find(item => item.action === 'unlockRecord').hidden = true + } } } } diff --git a/src/components/ADempiere/DataTable/index.vue b/src/components/ADempiere/DataTable/index.vue index 29cd1a9f..54ed99d5 100644 --- a/src/components/ADempiere/DataTable/index.vue +++ b/src/components/ADempiere/DataTable/index.vue @@ -903,6 +903,10 @@ export default { query: { ...this.$route.query, action: row.UUID + }, + params: { + tableName: this.getterPanel.tableName, + recordId: row[`${this.getterPanel.tableName}_ID`] } }) } else { diff --git a/src/components/ADempiere/Panel/index.vue b/src/components/ADempiere/Panel/index.vue index a298fce1..595226c6 100644 --- a/src/components/ADempiere/Panel/index.vue +++ b/src/components/ADempiere/Panel/index.vue @@ -488,6 +488,10 @@ export default { name: this.$route.name, query: { ...this.$route.query + }, + params: { + tableName: this.metadata.tableName, + recordId: this.dataRecords[`${this.metadata.tableName}_ID`] } }) this.$store.dispatch('notifyPanelChange', { @@ -501,12 +505,13 @@ export default { }) } else { this.$router.push({ - name: this.$route.name, query: { ...this.$route.query, action: this.dataRecords.UUID } }) + this.$route.params['tableName'] = this.metadata.tableName + this.$route.params['recordId'] = this.dataRecords[`${this.metadata.tableName}_ID`] this.$store.dispatch('notifyPanelChange', { parentUuid: this.parentUuid, containerUuid: this.containerUuid, diff --git a/src/lang/ADempiere/en.js b/src/lang/ADempiere/en.js index 85444562..1b90767b 100644 --- a/src/lang/ADempiere/en.js +++ b/src/lang/ADempiere/en.js @@ -38,7 +38,9 @@ export default { copyUnsuccessful: 'Error, unable to copy', mandatoryFieldMissing: 'Missing fill in the fields ', updateFields: 'The record is updated with the field ', - invalidEmailFormat: 'Invalid email format' + invalidEmailFormat: 'Invalid email format', + recordLocked: 'This record has been locked', + recordUnlocked: 'This record has been unlocked' }, navbar: { badge: { @@ -269,6 +271,8 @@ export default { deleteRecordSuccessful: 'Record deleted successfully', deleteRecordError: 'Error deleting record', selectionRequired: 'You must select a record', - undo: 'Undo' + undo: 'Undo', + lockRecord: 'Lock Record', + unlockRecord: 'Unlock Record' } } diff --git a/src/lang/ADempiere/es.js b/src/lang/ADempiere/es.js index ed21beaf..40169fac 100644 --- a/src/lang/ADempiere/es.js +++ b/src/lang/ADempiere/es.js @@ -38,7 +38,9 @@ export default { copyUnsuccessful: 'Error, no se puede copiar', mandatoryFieldMissing: 'Falta completar los campos ', updateFields: 'Se actualiza el registro con el campo ', - invalidEmailFormat: 'Formato de correo electronico invalido' + invalidEmailFormat: 'Formato de correo electronico invalido', + recordLocked: 'Este registro ha sido bloqueado', + recordUnlocked: 'Este registro ha sido desbloqueado' }, navbar: { badge: { @@ -244,6 +246,8 @@ export default { deleteRecordSuccessful: 'Registro eliminado exitosamente', deleteRecordError: 'Error al eliminar el regitro', selectionRequired: 'Debe seleccionar un registro', - undo: 'Deshacer' + undo: 'Deshacer', + lockRecord: 'Bloquear Registro', + unlockRecord: 'Desbloquear Registro' } } diff --git a/src/store/modules/ADempiere/data.js b/src/store/modules/ADempiere/data.js index 9e586001..51a543c3 100644 --- a/src/store/modules/ADempiere/data.js +++ b/src/store/modules/ADempiere/data.js @@ -6,6 +6,9 @@ import { getDefaultValueFromServer, convertValueFromGRPC, getContextInfoValueFromServer, + getPrivateAccessFromServer, + lockPrivateAccessFromServer, + unlockPrivateAccessFromServer, getFavoritesFromServer, getPendingDocumentsFromServer, requestPrintFormats @@ -22,6 +25,7 @@ const data = { pendingDocuments: [], inGetting: [], contextInfoField: [], + recordPrivateAccess: {}, printFormatList: [] }, mutations: { @@ -102,6 +106,9 @@ const data = { setContextInfoField(state, payload) { state.contextInfoField.push(payload) }, + setPrivateAccess(state, payload) { + state.recordPrivateAccess = payload + }, setPrintFormatList(state, payload) { state.printFormatList.push(payload) } @@ -836,6 +843,92 @@ const data = { console.warn(`Error ${error.code} getting context info value for field ${error.message}`) }) }, + getPrivateAccessFromServer({ commit, rootGetters }, parameters) { + const { tableName, recordId } = parameters + const userUuid = rootGetters['user/getUserUuid'] + return getPrivateAccessFromServer({ tableName: tableName, recordId: recordId, userUuid: userUuid }) + .then(privateAccess => { + if (privateAccess.getRecordid()) { + var recordPrivateAccess = { + isLocked: true, + tableName: privateAccess.getTablename(), + recordId: privateAccess.getRecordid(), + userUuid: privateAccess.getUseruuid() + } + } else { + recordPrivateAccess = { + isLocked: false, + tableName: parameters.tableName, + recordId: parameters.recordId, + userUuid: rootGetters['user/getUserUuid'] + } + } + return recordPrivateAccess + }) + .catch(error => { + console.error(error) + }) + }, + lockRecord({ commit, rootGetters }, parameters) { + const { tableName, recordId } = parameters + const userUuid = rootGetters['user/getUserUuid'] + return lockPrivateAccessFromServer({ tableName: tableName, recordId: recordId, userUuid: userUuid }) + .then(response => { + if (response.getRecordid()) { + const recordLocked = { + isPrivateAccess: true, + isLocked: true, + tableName: response.getTablename(), + recordId: response.getRecordid(), + userUuid: response.getUseruuid() + } + showMessage({ + title: language.t('notifications.succesful'), + message: language.t('notifications.recordLocked'), + type: 'success' + }) + return recordLocked + } + }) + .catch(error => { + showMessage({ + title: language.t('notifications.error'), + message: language.t('login.unexpectedError'), + type: 'error' + }) + console.error(error) + }) + }, + unlockRecord({ commit, rootGetters, state }, parameters) { + const { tableName, recordId } = parameters + const userUuid = rootGetters['user/getUserUuid'] + return unlockPrivateAccessFromServer({ tableName: tableName, recordId: recordId, userUuid: userUuid }) + .then(response => { + if (response.getRecordid()) { + const recordUnlocked = { + isPrivateAccess: true, + isLocked: false, + tableName: response.getTablename(), + recordId: response.getRecordid(), + userUuid: response.getUseruuid() + } + showMessage({ + title: language.t('notifications.succesful'), + message: language.t('notifications.recordUnlocked'), + type: 'success' + }) + return recordUnlocked + } + }) + .catch(error => { + showMessage({ + title: language.t('notifications.error'), + message: language.t('login.unexpectedError'), + type: 'error' + }) + console.error(error) + }) + }, requestPrintFormats({ commit }, parameters) { return requestPrintFormats({ processUuid: parameters.processUuid }) .then(response => { @@ -988,6 +1081,14 @@ const data = { info.sqlStatement === sqlStatement ) }, + getRecordPrivateAccess: (state) => (tableName, recordId) => { + if (!isEmptyValue(tableName) && !isEmptyValue(recordId)) { + if (state.recordPrivateAccess.tableName === tableName && state.recordPrivateAccess.recordId === recordId) { + return state.recordPrivateAccess + } + return undefined + } + }, getPrintFormatList: (state) => (containerUuid) => { var printFormatList = state.printFormatList.find(list => list.containerUuid === containerUuid) if (printFormatList) { diff --git a/src/store/modules/ADempiere/panel.js b/src/store/modules/ADempiere/panel.js index ad019a08..6fdf1537 100644 --- a/src/store/modules/ADempiere/panel.js +++ b/src/store/modules/ADempiere/panel.js @@ -322,7 +322,8 @@ const panel = { newValues: defaultAttributes, isSendToServer: false, // if isNewRecord active callouts, if window is closed no send callout - isSendCallout: isNewRecord + isSendCallout: isNewRecord, + isPrivateAccess: false }) }, /** @@ -333,7 +334,7 @@ const panel = { * @param {object} newValues, values to set in panel * @param {boolean} isSendToServer, indicate if changes send to server */ - notifyPanelChange({ dispatch, getters }, parameters) { + notifyPanelChange({ dispatch, getters, rootGetters }, parameters) { const { parentUuid, containerUuid, @@ -343,7 +344,8 @@ const panel = { panelType = 'window', withOutColumnNames = [], isSendCallout = true, - isAdvancedQuery = false + isAdvancedQuery = false, + isPrivateAccess = true } = parameters var { fieldList = [] } = parameters @@ -394,6 +396,14 @@ const panel = { dispatch('setIsloadContext', { containerUuid: containerUuid }) + if (isPrivateAccess) { + var tableName = rootGetters.getTableNameFromTab(parentUuid, containerUuid) + dispatch('getPrivateAccessFromServer', { + tableName: tableName, + recordId: newValues[`${tableName}_ID`], + userUuid: rootGetters['user/getUserUuid'] + }) + } } }, /** diff --git a/src/store/modules/ADempiere/processControl.js b/src/store/modules/ADempiere/processControl.js index 389717a8..bb054bf7 100644 --- a/src/store/modules/ADempiere/processControl.js +++ b/src/store/modules/ADempiere/processControl.js @@ -243,6 +243,7 @@ const processControl = { if (reportType !== 'pdf' && reportType !== 'html') { link.click() } + // Report views List to context menu var reportViewList = { name: language.t('views.reportView'), diff --git a/src/store/modules/ADempiere/window.js b/src/store/modules/ADempiere/window.js index a61a0a96..646b06d3 100644 --- a/src/store/modules/ADempiere/window.js +++ b/src/store/modules/ADempiere/window.js @@ -134,6 +134,26 @@ const window = { action: 'undoModifyData', uuidParent: newWindow.uuid, disabled: false + }, + { + name: language.t('data.lockRecord'), + processName: language.t('data.lockRecord'), + type: 'dataAction', + action: 'lockRecord', + disabled: false, + hidden: true, + tableName: '', + recordId: null + }, + { + name: language.t('data.unlockRecord'), + processName: language.t('data.unlockRecord'), + type: 'dataAction', + action: 'unlockRecord', + disabled: false, + hidden: true, + tableName: '', + recordId: null }) const processList = tabItem.getProcessesList().map(processItem => { return { diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 8165888b..647c65a9 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -7,6 +7,7 @@ import { showMessage, convertMapToArrayPairs } from '@/utils/ADempiere' const state = { token: getToken(), name: '', + userUuid: '', avatar: '', introduction: '', rol: {}, // info current rol @@ -38,6 +39,9 @@ const mutations = { SET_ROL: (state, rol) => { state.rol = rol }, + SET_USER_UUID: (state, payload) => { + state.userUuid = payload + }, setIsSession(state, payload) { state.isSession = payload }, @@ -91,6 +95,7 @@ const actions = { const userInfo = response.getUserinfo() commit('SET_NAME', userInfo.getName()) commit('SET_INTRODUCTION', userInfo.getDescription()) + commit('SET_USER_UUID', userInfo.getUuid()) var defaultContext = convertMapToArrayPairs({ toConvert: response.getDefaultcontextMap() @@ -267,6 +272,9 @@ const getters = { }, getIsSession: (state) => { return state.isSession + }, + getUserUuid: (state) => { + return state.userUuid } } diff --git a/src/views/ADempiere/Window/index.vue b/src/views/ADempiere/Window/index.vue index 5b6c2f8c..73025333 100644 --- a/src/views/ADempiere/Window/index.vue +++ b/src/views/ADempiere/Window/index.vue @@ -280,6 +280,13 @@ export default { return false } }, + watch: { + 'this.$route.params'(newValue, oldValue) { + if (!this.isEmptyValue(newValue)) { + this.getIsRecordLocked() + } + } + }, created() { this.getWindow() }, @@ -353,6 +360,12 @@ export default { containerUuid: this.windowUuid, // act as parentUuid isShowedDetail: this.isShowedTabChildren }) + }, + getIsRecordLocked() { + if (this.$store.getters.getRecordPrivateAccess(this.$route.params.tableName, this.$route.params.recordId)) { + return true + } + return false } } }