Commit 6764faa1 authored by Maxime Buquet's avatar Maxime Buquet Committed by Jordi Mallach

OAuth phab: Update with 5.0 changes

Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <pep@collabora.com>
parent 64efe431
......@@ -20,14 +20,10 @@ import DatabaseSettings from 'components/admin_console/database_settings.jsx';
import ElasticsearchSettings from 'components/admin_console/elasticsearch_settings.jsx';
import EmailSettings from 'components/admin_console/email_settings.jsx';
import GitLabSettings from 'components/admin_console/gitlab_settings.jsx';
import PhabricatorSettings from 'components/admin_console/phabricator_settings.jsx';
import MessageExportSettings from 'components/admin_console/message_export_settings';
import OAuthSettings from 'components/admin_console/oauth_settings.jsx';
import PasswordSettings from 'components/admin_console/password_settings.jsx';
<<<<<<< HEAD
=======
import PhabricatorSettings from 'components/admin_console/phabricator_settings.jsx';
import PluginSettings from 'components/admin_console/plugin_settings.jsx';
>>>>>>> 95ba0b2c... Add Phabricator OAuth2 support.
import PluginManagement from 'components/admin_console/plugin_management';
import CustomPluginSettings from 'components/admin_console/custom_plugin_settings';
import CustomIntegrationSettings from 'components/admin_console/custom_integrations_settings';
......@@ -289,6 +285,11 @@ export default class AdminConsole extends React.Component {
component={GitLabSettings}
extraProps={extraProps}
/>
<SCRoute
path={`${props.match.url}/phabricator`}
component={PhabricatorSettings}
extraProps={extraProps}
/>
<SCRoute
path={`${props.match.url}/oauth`}
component={OAuthSettings}
......
......@@ -97,6 +97,7 @@ export default class OAuthSettings extends AdminSettings {
id: settings.Id,
secret: settings.Secret,
gitLabUrl: config.GitLabSettings.UserApiEndpoint.replace('/api/v4/user', ''),
phabricatorUrl: config.PhabricatorSettings.UserApiEndpoint.replace('/api/v4/user', ''),
userApiEndpoint: settings.UserApiEndpoint,
authEndpoint: settings.AuthEndpoint,
tokenEndpoint: settings.TokenEndpoint,
......@@ -111,6 +112,7 @@ export default class OAuthSettings extends AdminSettings {
gitLabUrl = settings.UserApiEndpoint.replace('/api/v4/user', '');
} else if (value === Constants.PHABRICATOR_SERVICE) {
settings = this.config.PhabricatorSettings;
phabricatorUrl = settings.UserApiEndpoint.replace('/api/v4/user', '');
} else if (value === Constants.GOOGLE_SERVICE) {
settings = this.config.GoogleSettings;
} else if (value === Constants.OFFICE365_SERVICE) {
......@@ -152,6 +154,29 @@ export default class OAuthSettings extends AdminSettings {
this.isSetByEnv('GitLabSettings.UserApiEndpoint');
};
updatePhabricatorUrl = (id, value) => {
let trimmedValue = value;
if (value.endsWith('/')) {
trimmedValue = value.slice(0, -1);
}
this.setState({
saveNeeded: true,
phabricatorUrl: value,
userApiEndpoint: trimmedValue + '/api/user.whoami',
authEndpoint: trimmedValue + '/oauthserver/auth/',
tokenEndpoint: trimmedValue + '/oauthserver/token/'
});
}
isPhabricatorURLSetByEnv = () => {
// Assume that if one of these has been set using an environment variable,
// all of them have been set that way
return this.isSetByEnv('PhabricatorSettings.AuthEndpoint') ||
this.isSetByEnv('PhabricatorSettings.TokenEndpoint') ||
this.isSetByEnv('PhabricatorSettings.UserApiEndpoint');
};
renderTitle() {
return (
<FormattedMessage
......@@ -437,15 +462,16 @@ export default class OAuthSettings extends AdminSettings {
defaultMessage='Application ID:'
/>
}
placeholder={Utils.localizeMessage('admin.phabricator.clientIdExample', 'Ex "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
placeholder={Utils.localizeMessage('admin.phabricator.clientIdExample', 'E.g.: "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
helpText={
<FormattedMessage
id='admin.phabriator.clientIdDescription'
id='admin.phabricator.clientIdDescription'
defaultMessage='Obtain this value via the instructions above for logging into Phabricator'
/>
}
value={this.state.id}
onChange={this.handleChange}
setByEnv={this.isSetByEnv('PhabricatorSettings.Id')}
/>
<TextSetting
id='secret'
......@@ -455,7 +481,7 @@ export default class OAuthSettings extends AdminSettings {
defaultMessage='Application Secret Key:'
/>
}
placeholder={Utils.localizeMessage('admin.phabricator.clientSecretExample', 'Ex "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
placeholder={Utils.localizeMessage('admin.phabricator.clientSecretExample', 'E.g.: "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
helpText={
<FormattedMessage
id='admin.phabricator.clientSecretDescription'
......@@ -464,6 +490,7 @@ export default class OAuthSettings extends AdminSettings {
}
value={this.state.secret}
onChange={this.handleChange}
setByEnv={this.isSetByEnv('PhabricatorSettings.Secret')}
/>
<TextSetting
id='phabricatorUrl'
......@@ -477,11 +504,12 @@ export default class OAuthSettings extends AdminSettings {
helpText={
<FormattedMessage
id='admin.phabricator.siteUrlDescription'
defaultMessage='Enter the URL of your Phabricator instance, e.g. https://phabricator.example.com. If your Phabricator instance is not set up with SSL, start the URL with http:// instead of https://.'
defaultMessage='Enter the URL of your Phabricator instance, e.g. https://example.com:3000. If your Phabricator instance is not set up with SSL, start the URL with http:// instead of https://.'
/>
}
value={this.state.gitLabUrl}
onChange={this.updateGitLabUrl}
onChange={this.updatePhabricatorUrl}
setByEnv={this.isPhabricatorURLSetByEnv()}
/>
<TextSetting
id='userApiEndpoint'
......@@ -494,6 +522,7 @@ export default class OAuthSettings extends AdminSettings {
placeholder={''}
value={this.state.userApiEndpoint}
disabled={true}
setByEnv={false}
/>
<TextSetting
id='authEndpoint'
......@@ -506,6 +535,7 @@ export default class OAuthSettings extends AdminSettings {
placeholder={''}
value={this.state.authEndpoint}
disabled={true}
setByEnv={false}
/>
<TextSetting
id='tokenEndpoint'
......@@ -518,6 +548,7 @@ export default class OAuthSettings extends AdminSettings {
placeholder={''}
value={this.state.tokenEndpoint}
disabled={true}
setByEnv={false}
/>
</div>
);
......
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
// See LICENSE.txt for license information.
import React from 'react';
import {FormattedHTMLMessage, FormattedMessage} from 'react-intl';
......@@ -36,10 +36,10 @@ export default class PhabricatorSettings extends AdminSettings {
enable: config.PhabricatorSettings.Enable,
id: config.PhabricatorSettings.Id,
secret: config.PhabricatorSettings.Secret,
phabricatorUrl: config.PhabricatorSettings.UserApiEndpoint.replace('/api/v4/user', ''),
phabricatorUrl: config.PhabricatorSettings.UserApiEndpoint.replace('/api/user.whoami', ''),
userApiEndpoint: config.PhabricatorSettings.UserApiEndpoint,
authEndpoint: config.PhabricatorSettings.AuthEndpoint,
tokenEndpoint: config.PhabricatorSettings.TokenEndpoint
tokenEndpoint: config.PhabricatorSettings.TokenEndpoint,
};
}
......@@ -54,10 +54,18 @@ export default class PhabricatorSettings extends AdminSettings {
phabricatorUrl: value,
userApiEndpoint: trimmedValue + '/api/user.whoami',
authEndpoint: trimmedValue + '/oauthserver/auth/',
tokenEndpoint: trimmedValue + '/oauthserver/token/'
tokenEndpoint: trimmedValue + '/oauthserver/token/',
});
}
isPhabricatorURLSetByEnv = () => {
// Assume that if one of these has been set using an environment variable,
// all of them have been set that way
return this.isSetByEnv('PhabricatorSettings.AuthEndpoint') ||
this.isSetByEnv('PhabricatorSettings.TokenEndpoint') ||
this.isSetByEnv('PhabricatorSettings.UserApiEndpoint');
};
renderTitle() {
return (
<FormattedMessage
......@@ -93,6 +101,7 @@ export default class PhabricatorSettings extends AdminSettings {
}
value={this.state.enable}
onChange={this.handleChange}
setByEnv={this.isSetByEnv('PhabricatorSettings.Enable')}
/>
<TextSetting
id='id'
......@@ -102,7 +111,7 @@ export default class PhabricatorSettings extends AdminSettings {
defaultMessage='Application ID:'
/>
}
placeholder={Utils.localizeMessage('admin.phabricator.clientIdExample', 'Ex "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
placeholder={Utils.localizeMessage('admin.phabricator.clientIdExample', 'E.g.: "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
helpText={
<FormattedMessage
id='admin.phabricator.clientIdDescription'
......@@ -112,6 +121,7 @@ export default class PhabricatorSettings extends AdminSettings {
value={this.state.id}
onChange={this.handleChange}
disabled={!this.state.enable}
setByEnv={this.isSetByEnv('PhabricatorSettings.Id')}
/>
<TextSetting
id='secret'
......@@ -121,7 +131,7 @@ export default class PhabricatorSettings extends AdminSettings {
defaultMessage='Application Secret Key:'
/>
}
placeholder={Utils.localizeMessage('admin.phabricator.clientSecretExample', 'Ex "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
placeholder={Utils.localizeMessage('admin.phabricator.clientSecretExample', 'E.g.: "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
helpText={
<FormattedMessage
id='admin.phabricator.clientSecretDescription'
......@@ -131,6 +141,7 @@ export default class PhabricatorSettings extends AdminSettings {
value={this.state.secret}
onChange={this.handleChange}
disabled={!this.state.enable}
setByEnv={this.isSetByEnv('PhabricatorSettings.Secret')}
/>
<TextSetting
id='phabricatorUrl'
......@@ -144,12 +155,13 @@ export default class PhabricatorSettings extends AdminSettings {
helpText={
<FormattedMessage
id='admin.phabricator.siteUrlDescription'
defaultMessage='Enter the URL of your Phabricator instance, e.g. https://phabricator.example.com/. If your Phabricator instance is not set up with SSL, start the URL with http:// instead of https://.'
defaultMessage='Enter the URL of your Phabricator instance, e.g. https://example.com:3000. If your Phabricator instance is not set up with SSL, start the URL with http:// instead of https://.'
/>
}
value={this.state.PhabricatorUrl}
value={this.state.phabricatorUrl}
onChange={this.updatePhabricatorUrl}
disabled={!this.state.enable}
setByEnv={this.isPhabricatorURLSetByEnv()}
/>
<TextSetting
id='userApiEndpoint'
......@@ -162,6 +174,7 @@ export default class PhabricatorSettings extends AdminSettings {
placeholder={''}
value={this.state.userApiEndpoint}
disabled={true}
setByEnv={false}
/>
<TextSetting
id='authEndpoint'
......@@ -174,6 +187,7 @@ export default class PhabricatorSettings extends AdminSettings {
placeholder={''}
value={this.state.authEndpoint}
disabled={true}
setByEnv={false}
/>
<TextSetting
id='tokenEndpoint'
......@@ -186,6 +200,7 @@ export default class PhabricatorSettings extends AdminSettings {
placeholder={''}
value={this.state.tokenEndpoint}
disabled={true}
setByEnv={false}
/>
</SettingsGroup>
);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment