| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- import { Container } from 'unstated';
- import loggerFactory from '@alias/logger';
- import { toastError } from '../util/apiNotification';
- const logger = loggerFactory('growi:appSettings');
- /**
- * Service container for admin app setting page (AppSettings.jsx)
- * @extends {Container} unstated Container
- */
- export default class AdminAppContainer extends Container {
- constructor(appContainer) {
- super();
- this.appContainer = appContainer;
- this.state = {
- retrieveError: null,
- title: '',
- confidential: '',
- globalLang: '',
- fileUpload: '',
- siteUrl: '',
- envSiteUrl: '',
- isSetSiteUrl: true,
- fromAddress: '',
- smtpHost: '',
- smtpPort: '',
- smtpUser: '',
- smtpPassword: '',
- region: '',
- customEndpoint: '',
- bucket: '',
- accessKeyId: '',
- secretAccessKey: '',
- isEnabledPlugins: true,
- };
- this.changeTitle = this.changeTitle.bind(this);
- this.changeConfidential = this.changeConfidential.bind(this);
- this.changeGlobalLang = this.changeGlobalLang.bind(this);
- this.changeFileUpload = this.changeFileUpload.bind(this);
- this.changeSiteUrl = this.changeSiteUrl.bind(this);
- this.changeFromAddress = this.changeFromAddress.bind(this);
- this.changeSmtpHost = this.changeSmtpHost.bind(this);
- this.changeSmtpPort = this.changeSmtpPort.bind(this);
- this.changeSmtpUser = this.changeSmtpUser.bind(this);
- this.changeSmtpPassword = this.changeSmtpPassword.bind(this);
- this.changeRegion = this.changeRegion.bind(this);
- this.changeCustomEndpoint = this.changeCustomEndpoint.bind(this);
- this.changeBucket = this.changeBucket.bind(this);
- this.changeAccessKeyId = this.changeAccessKeyId.bind(this);
- this.changeSecretAccessKey = this.changeSecretAccessKey.bind(this);
- this.changeIsEnabledPlugins = this.changeIsEnabledPlugins.bind(this);
- this.updateAppSettingHandler = this.updateAppSettingHandler.bind(this);
- this.updateSiteUrlSettingHandler = this.updateSiteUrlSettingHandler.bind(this);
- this.updateMailSettingHandler = this.updateMailSettingHandler.bind(this);
- this.updateAwsSettingHandler = this.updateAwsSettingHandler.bind(this);
- this.updatePluginSettingHandler = this.updatePluginSettingHandler.bind(this);
- }
- /**
- * Workaround for the mangling in production build to break constructor.name
- */
- static getClassName() {
- return 'AdminAppContainer';
- }
- /**
- * retrieve app sttings data
- */
- async retrieveAppSettingsData() {
- try {
- const response = await this.appContainer.apiv3.get('/app-settings/');
- const { appSettingsParams } = response.data;
- this.setState({
- title: appSettingsParams.title,
- confidential: appSettingsParams.confidential,
- globalLang: appSettingsParams.globalLang,
- fileUpload: appSettingsParams.fileUpload,
- siteUrl: appSettingsParams.siteUrl,
- envSiteUrl: appSettingsParams.envSiteUrl,
- isSetSiteUrl: !!appSettingsParams.siteUrl,
- fromAddress: appSettingsParams.fromAddress,
- smtpHost: appSettingsParams.smtpHost,
- smtpPort: appSettingsParams.smtpPort,
- smtpUser: appSettingsParams.smtpUser,
- smtpPassword: appSettingsParams.smtpPassword,
- region: appSettingsParams.region,
- customEndpoint: appSettingsParams.customEndpoint,
- bucket: appSettingsParams.bucket,
- accessKeyId: appSettingsParams.accessKeyId,
- secretAccessKey: appSettingsParams.secretAccessKey,
- isEnabledPlugins: appSettingsParams.isEnabledPlugins,
- });
- }
- catch (err) {
- logger.error(err);
- toastError(new Error('Failed to fetch data'));
- }
- }
- /**
- * Change title
- */
- changeTitle(title) {
- this.setState({ title });
- }
- /**
- * Change confidential
- */
- changeConfidential(confidential) {
- this.setState({ confidential });
- }
- /**
- * Change globalLang
- */
- changeGlobalLang(globalLang) {
- this.setState({ globalLang });
- }
- /**
- * Change fileUpload
- */
- changeFileUpload(fileUpload) {
- this.setState({ fileUpload });
- }
- /**
- * Change site url
- */
- changeSiteUrl(siteUrl) {
- this.setState({ siteUrl });
- }
- /**
- * Change from address
- */
- changeFromAddress(fromAddress) {
- this.setState({ fromAddress });
- }
- /**
- * Change smtp host
- */
- changeSmtpHost(smtpHost) {
- this.setState({ smtpHost });
- }
- /**
- * Change smtp port
- */
- changeSmtpPort(smtpPort) {
- this.setState({ smtpPort });
- }
- /**
- * Change smtp user
- */
- changeSmtpUser(smtpUser) {
- this.setState({ smtpUser });
- }
- /**
- * Change smtp password
- */
- changeSmtpPassword(smtpPassword) {
- this.setState({ smtpPassword });
- }
- /**
- * Change region
- */
- changeRegion(region) {
- this.setState({ region });
- }
- /**
- * Change custom endpoint
- */
- changeCustomEndpoint(customEndpoint) {
- this.setState({ customEndpoint });
- }
- /**
- * Change bucket name
- */
- changeBucket(bucket) {
- this.setState({ bucket });
- }
- /**
- * Change access key id
- */
- changeAccessKeyId(accessKeyId) {
- this.setState({ accessKeyId });
- }
- /**
- * Change secret access key
- */
- changeSecretAccessKey(secretAccessKey) {
- this.setState({ secretAccessKey });
- }
- /**
- * Change secret key
- */
- changeIsEnabledPlugins(isEnabledPlugins) {
- this.setState({ isEnabledPlugins });
- }
- /**
- * Update app setting
- * @memberOf AdminAppContainer
- * @return {Array} Appearance
- */
- async updateAppSettingHandler() {
- const response = await this.appContainer.apiv3.put('/app-settings/app-setting', {
- title: this.state.title,
- confidential: this.state.confidential,
- globalLang: this.state.globalLang,
- fileUpload: this.state.fileUpload,
- });
- const { appSettingParams } = response.data;
- return appSettingParams;
- }
- /**
- * Update site url setting
- * @memberOf AdminAppContainer
- * @return {Array} Appearance
- */
- async updateSiteUrlSettingHandler() {
- const response = await this.appContainer.apiv3.put('/app-settings/site-url-setting', {
- siteUrl: this.state.siteUrl,
- });
- const { siteUrlSettingParams } = response.data;
- return siteUrlSettingParams;
- }
- /**
- * Update mail setting
- * @memberOf AdminAppContainer
- * @return {Array} Appearance
- */
- async updateMailSettingHandler() {
- const response = await this.appContainer.apiv3.put('/app-settings/mail-setting', {
- fromAddress: this.state.fromAddress,
- smtpHost: this.state.smtpHost,
- smtpPort: this.state.smtpPort,
- smtpUser: this.state.smtpUser,
- smtpPassword: this.state.smtpPassword,
- });
- const { mailSettingParams } = response.data;
- return mailSettingParams;
- }
- /**
- * Update AWS setting
- * @memberOf AdminAppContainer
- * @return {Array} Appearance
- */
- async updateAwsSettingHandler() {
- const response = await this.appContainer.apiv3.put('/app-settings/aws-setting', {
- region: this.state.region,
- customEndpoint: this.state.customEndpoint,
- bucket: this.state.bucket,
- accessKeyId: this.state.accessKeyId,
- secretAccessKey: this.state.secretAccessKey,
- });
- const { awsSettingParams } = response.data;
- return awsSettingParams;
- }
- /**
- * Update plugin setting
- * @memberOf AdminAppContainer
- * @return {Array} Appearance
- */
- async updatePluginSettingHandler() {
- const response = await this.appContainer.apiv3.put('/app-settings/plugin-setting', {
- isEnabledPlugins: this.state.isEnabledPlugins,
- });
- const { pluginSettingParams } = response.data;
- return pluginSettingParams;
- }
- }
|