Commit fb43c8ce8fd36069583e422d99024b3d8c96c121

Authored by ww
1 parent df08498c

feat: implement not has permission user can not save content

1 1 class ConfigurationNodeApi {
  2 +
  3 + /**
  4 + * @description 获取用户权限
  5 + */
  6 + static getUserPermissions(){
  7 + return defHttp.get('/yt/role/me/permissions')
  8 + }
  9 +
2 10 /**
3 11 * @description 获取组态信息
4 12 * @param {'CONFIGURE' | 'CONTENT' | 'NODE'} levelType - 组态资源类型
... ...
... ... @@ -18,6 +18,16 @@ const GLOBAL_TOKEN = (() => {
18 18 }
19 19 })()
20 20
  21 +const CAN_WRITE = 'api:yt:admin:designConfiguration1'
  22 +
  23 +const USER_PERMISSION = {
  24 + permission: []
  25 +}
  26 +
  27 +const hasSavePermission = () => {
  28 + return USER_PERMISSION.permission.includes(CAN_WRITE)
  29 +}
  30 +
21 31 const GLOBAL_WS_URL = () => {
22 32 const { host, href } = location
23 33 const reg = /^https/
... ...
... ... @@ -5037,7 +5037,23 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) {
5037 5037
5038 5038 getToken()
5039 5039
5040   - //调用API,获取保存的内容
  5040 + var updateButtonContainer = this.updateButtonContainer
  5041 + // var lockUnlock = this.actions.actions.lockUnlock.funct
  5042 + // var selectAll = this.actions.actions.selectAll.funct
  5043 + function getUserPermission() {
  5044 + defHttp.get('/yt/role/me/permissions')
  5045 + .then(res => {
  5046 + USER_PERMISSION.permission = res
  5047 + updateButtonContainer()
  5048 + // var flag = hasSavePermission()
  5049 + // if (!flag) {
  5050 + // selectAll()
  5051 + // lockUnlock()
  5052 + // }
  5053 + })
  5054 + }
  5055 +
  5056 + // 调用API,获取保存的内容
5041 5057 function getSaveContent() {
5042 5058 defHttp.get('/yt/configuration/center/getConfigurationInfo/'+Editor.configurationId)
5043 5059 .then(function (response) {
... ... @@ -5085,6 +5101,8 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) {
5085 5101 } else {
5086 5102 fn();
5087 5103 }
  5104 +
  5105 + getUserPermission()
5088 5106 })
5089 5107 .catch(function (error) {
5090 5108 console.log(error);
... ... @@ -5960,27 +5978,31 @@ App.prototype.updateButtonContainer = function()
5960 5978 this.buttonContainer.appendChild(this.shareButton);
5961 5979
5962 5980 // TODO thingsKit 保存按钮
5963   - this.saveButton = document.createElement('div');
5964   - this.saveButton.className = 'geBtn gePrimaryBtn';
5965   - this.saveButton.style.display = 'inline-block';
5966   - this.saveButton.style.backgroundColor = '#F2931E';
5967   - this.saveButton.style.borderColor = '#F08705';
5968   - this.saveButton.style.backgroundImage = 'none';
5969   - this.saveButton.style.marginTop = '-10px';
5970   - this.saveButton.style.lineHeight = '28px';
5971   - this.saveButton.style.minWidth = '0px';
5972   - this.saveButton.style.cssFloat = 'right';
5973   - this.saveButton.setAttribute('title', '保存');
5974   - mxUtils.write(this.saveButton, '保存');
5975   - mxEvent.addListener(this.saveButton, 'click', mxUtils.bind(this, function()
5976   - {
5977   - this.currentFile.ui.actions.get(
5978   - (this.currentFile.mode == null || !this.currentFile.isEditable())
5979   - ? 'saveAs'
5980   - : 'save')
5981   - .funct();
5982   - }));
5983   - this.buttonContainer.appendChild(this.saveButton);
  5981 + var flag = hasSavePermission()
  5982 + if (flag) {
  5983 + this.saveButton = document.createElement('div');
  5984 + this.saveButton.className = 'geBtn gePrimaryBtn';
  5985 + this.saveButton.style.display = 'inline-block';
  5986 + this.saveButton.style.backgroundColor = '#F2931E';
  5987 + this.saveButton.style.borderColor = '#F08705';
  5988 + this.saveButton.style.backgroundImage = 'none';
  5989 + this.saveButton.style.marginTop = '-10px';
  5990 + this.saveButton.style.lineHeight = '28px';
  5991 + this.saveButton.style.minWidth = '0px';
  5992 + this.saveButton.style.cssFloat = 'right';
  5993 + this.saveButton.setAttribute('title', '保存');
  5994 + mxUtils.write(this.saveButton, '保存');
  5995 + mxEvent.addListener(this.saveButton, 'click', mxUtils.bind(this, function()
  5996 + {
  5997 + this.currentFile.ui.actions.get(
  5998 + (this.currentFile.mode == null || !this.currentFile.isEditable())
  5999 + ? 'saveAs'
  6000 + : 'save')
  6001 + .funct();
  6002 + }));
  6003 + this.buttonContainer.appendChild(this.saveButton);
  6004 + }
  6005 +
5984 6006
5985 6007
5986 6008 // this.shareButton = document.createElement('div');
... ...
... ... @@ -134,6 +134,9 @@ LocalFile.prototype.getLatestVersion = function (success, error) {
134 134 * @param {number} dy Y-coordinate of the translation.
135 135 */
136 136 LocalFile.prototype.saveFile = function (title, revision, success, error, useCurrentData) {
  137 + // TODO thingskit 保存权限
  138 + var flag = hasSavePermission()
  139 + if (!flag) return error({error: '没有权限'})
137 140 if (title != this.title) {
138 141 this.fileHandle = null;
139 142 this.desc = null;
... ...