[PE mobile] Add app options (config, permissions)

This commit is contained in:
JuliaSvinareva 2020-12-15 20:10:27 +03:00
parent fb2a28df5b
commit 3bc9c039d4
3 changed files with 80 additions and 13 deletions

View file

@ -4,7 +4,7 @@ import { inject } from "mobx-react";
import { withTranslation } from 'react-i18next';
import CollaborationController from '../../../../common/mobile/lib/controller/Collaboration.jsx'
@inject("storeFocusObjects")
@inject("storeFocusObjects", "storeAppOptions")
class MainController extends Component {
constructor(props) {
super(props)
@ -36,11 +36,13 @@ class MainController extends Component {
};
const loadConfig = data => {
let me = this;
console.log('load config');
me.editorConfig = Object.assign({}, this.editorConfig, data.config);
me.appOptions.user = Common.Utils.fillUserInfo(me.editorConfig.user, me.editorConfig.lang, "Local.User"/*me.textAnonymous*/);
this.editorConfig = Object.assign({}, this.editorConfig, data.config);
this.props.storeAppOptions.setConfigOptions(this.editorConfig);
this.editorConfig.lang && this.api.asc_setLocale(this.editorConfig.lang);
};
const loadDocument = data => {
@ -52,10 +54,11 @@ class MainController extends Component {
if (data.doc) {
this.permissions = Object.assign(this.permissions, data.doc.permissions);
let _permissions = Object.assign({}, data.doc.permissions),
_user = new Asc.asc_CUserInfo();
_user.put_Id(this.appOptions.user.id);
_user.put_FullName(this.appOptions.user.fullname);
const _permissions = Object.assign({}, data.doc.permissions);
const _user = new Asc.asc_CUserInfo();
const _userOptions = this.props.storeAppOptions.user;
_user.put_Id(_userOptions.id);
_user.put_FullName(_userOptions.fullname);
docInfo = new Asc.asc_CDocInfo();
docInfo.put_Id(data.doc.key);
@ -98,11 +101,8 @@ class MainController extends Component {
const licType = params.asc_getLicenseType();
me.appOptions.canLicense = (licType === Asc.c_oLicenseResult.Success || licType === Asc.c_oLicenseResult.SuccessLimit);
// me.appOptions.canEdit = (me.permissions.edit !== false || me.permissions.review === true) && // can edit or review
// (me.editorConfig.canRequestEditRights || me.editorConfig.mode !== 'view') && // if mode=="view" -> canRequestEditRights must be defined
// (!me.appOptions.isReviewOnly || me.appOptions.canLicense) && // if isReviewOnly==true -> canLicense must be true
// me.isSupportEditFeature();
// me.appOptions.isEdit = me.appOptions.canLicense && me.appOptions.canEdit && me.editorConfig.mode !== 'view';
this.props.storeAppOptions.setPermissionOptions(this.document, licType, params, this.permissions);
// me.api.asc_setViewMode(!me.appOptions.isEdit);
me.api.asc_setViewMode(false);

View file

@ -0,0 +1,65 @@
import {action, observable} from 'mobx';
export class storeAppOptions {
config = {};
@action setConfigOptions (config) {
this.config = config;
this.user = Common.Utils.fillUserInfo(config.user, config.lang, "Local.User"/*me.textAnonymous*/);
this.isDesktopApp = config.targetApp == 'desktop';
this.canCreateNew = !!config.createUrl && !this.isDesktopApp;
this.canOpenRecent = config.recent !== undefined && !this.isDesktopApp;
this.templates = config.templates;
this.recent = config.recent;
this.createUrl = config.createUrl;
this.lang = config.lang;
this.location = (typeof (config.location) == 'string') ? config.location.toLowerCase() : '';
this.sharingSettingsUrl = config.sharingSettingsUrl;
this.fileChoiceUrl = config.fileChoiceUrl;
this.mergeFolderUrl = config.mergeFolderUrl;
this.canAnalytics = false;
this.canRequestClose = config.canRequestClose;
this.customization = config.customization;
this.canBackToFolder = (config.canBackToFolder!==false) && (typeof (config.customization) == 'object') && (typeof (config.customization.goback) == 'object')
&& (!!(config.customization.goback.url) || config.customization.goback.requestClose && this.canRequestClose);
this.canBack = this.canBackToFolder === true;
this.canPlugins = false;
}
@action setPermissionOptions (document, licType, params, permissions) {
this.review = (permissions.review === undefined) ? (permissions.edit !== false) : permissions.review;
this.canAnalytics = params.asc_getIsAnalyticsEnable();
this.canLicense = (licType === Asc.c_oLicenseResult.Success || licType === Asc.c_oLicenseResult.SuccessLimit);
this.isLightVersion = params.asc_getIsLight();
this.canCoAuthoring = !this.isLightVersion;
this.isOffline = Common.EditorApi.get().asc_isOffline();
this.isReviewOnly = (permissions.review === true) && (permissions.edit === false);
this.canRequestEditRights = this.config.canRequestEditRights;
this.canEdit = (permissions.edit !== false || permissions.review === true) && // can edit or review
(this.config.canRequestEditRights || this.config.mode !== 'view') && // if mode=="view" -> canRequestEditRights must be defined
(!this.isReviewOnly || this.canLicense) && // if isReviewOnly==true -> canLicense must be true
true/*isSupportEditFeature*/;
this.isEdit = this.canLicense && this.canEdit && this.config.mode !== 'view';
this.canReview = this.canLicense && this.isEdit && (permissions.review===true);
this.canUseHistory = this.canLicense && !this.isLightVersion && this.config.canUseHistory && this.canCoAuthoring && !this.isDesktopApp;
this.canHistoryClose = this.config.canHistoryClose;
this.canUseMailMerge = this.canLicense && this.canEdit && !this.isDesktopApp;
this.canSendEmailAddresses = this.canLicense && this.config.canSendEmailAddresses && this.canEdit && this.canCoAuthoring;
this.canComments = this.canLicense && (permissions.comment === undefined ? this.isEdit : permissions.comment) && (this.config.mode !== 'view');
this.canComments = this.canComments && !((typeof (this.customization) == 'object') && this.customization.comments===false);
this.canViewComments = this.canComments || !((typeof (this.customization) == 'object') && this.customization.comments===false);
this.canEditComments = this.isOffline || !(typeof (this.customization) == 'object' && this.customization.commentAuthorOnly);
this.canChat = this.canLicense && !this.isOffline && !((typeof (this.customization) == 'object') && this.customization.chat === false);
this.canEditStyles = this.canLicense && this.canEdit;
this.canPrint = (permissions.print !== false);
this.isRestrictedEdit = !this.isEdit && this.canComments;
this.trialMode = params.asc_getLicenseMode();
const type = /^(?:(pdf|djvu|xps))$/.exec(document.fileType);
this.canDownloadOrigin = permissions.download !== false && (type && typeof type[1] === 'string');
this.canDownload = permissions.download !== false && (!type || typeof type[1] !== 'string');
this.canBranding = params.asc_getCustomization();
this.canBrandingExt = params.asc_getCanBranding() && (typeof this.customization == 'object');
this.canUseReviewPermissions = this.canLicense && this.customization && this.customization.reviewPermissions && (typeof (this.customization.reviewPermissions) == 'object');
}
}

View file

@ -1,4 +1,5 @@
import {storeAppOptions} from './appOptions';
// import {storeDocumentSettings} from './documentSettings';
import {storeFocusObjects} from "./focusObjects";
import {storeUsers} from '../../../../common/mobile/lib/store/users';
@ -11,6 +12,7 @@ import {storeApplicationSettings} from './applicationSettings';
// import {storeChartSettings} from "./chartSettings";
export const stores = {
storeAppOptions: new storeAppOptions(),
storeFocusObjects: new storeFocusObjects(),
// storeDocumentSettings: new storeDocumentSettings(),
users: new storeUsers(),