diff --git a/app/gitlab/lib/common.js b/app/gitlab/lib/common.js index 14410b4723f6..0160d04a2aea 100644 --- a/app/gitlab/lib/common.js +++ b/app/gitlab/lib/common.js @@ -1,13 +1,15 @@ import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; +import _ from 'underscore'; import { settings } from '../../settings'; import { CustomOAuth } from '../../custom-oauth'; const config = { serverURL: 'https://gitlab.com', - identityPath: '/api/v3/user', + identityPath: '/api/v4/user', scope: 'read_user', + mergeUsers: false, addAutopublishFields: { forLoggedInUser: ['services.gitlab'], forOtherUsers: ['services.gitlab.username'], @@ -19,16 +21,37 @@ const Gitlab = new CustomOAuth('gitlab', config); if (Meteor.isServer) { Meteor.startup(function() { - settings.get('API_Gitlab_URL', function(key, value) { - config.serverURL = value.trim().replace(/\/*$/, ''); + const updateConfig = _.debounce(() => { + config.serverURL = settings.get('API_Gitlab_URL').trim().replace(/\/*$/, '') || config.serverURL; + config.identityPath = settings.get('Accounts_OAuth_Gitlab_identity_path') || config.identityPath; + config.mergeUsers = Boolean(settings.get('Accounts_OAuth_Gitlab_merge_users')); Gitlab.configure(config); - }); + }, 300); + + settings.get('API_Gitlab_URL', updateConfig); + settings.get('Accounts_OAuth_Gitlab_identity_path', updateConfig); + settings.get('Accounts_OAuth_Gitlab_merge_users', updateConfig); }); } else { Meteor.startup(function() { Tracker.autorun(function() { + let anyChange = false; if (settings.get('API_Gitlab_URL')) { config.serverURL = settings.get('API_Gitlab_URL').trim().replace(/\/*$/, ''); + anyChange = true; + } + + if (settings.get('Accounts_OAuth_Gitlab_identity_path')) { + config.identityPath = settings.get('Accounts_OAuth_Gitlab_identity_path').trim() || config.identityPath; + anyChange = true; + } + + if (settings.get('Accounts_OAuth_Gitlab_merge_users')) { + config.mergeUsers = true; + anyChange = true; + } + + if (anyChange) { Gitlab.configure(config); } }); diff --git a/app/gitlab/server/startup.js b/app/gitlab/server/startup.js index 70fc5d615618..2c98e63db7cb 100644 --- a/app/gitlab/server/startup.js +++ b/app/gitlab/server/startup.js @@ -11,6 +11,8 @@ settings.addGroup('OAuth', function() { this.add('API_Gitlab_URL', '', { type: 'string', enableQuery, public: true, secret: true }); this.add('Accounts_OAuth_Gitlab_id', '', { type: 'string', enableQuery }); this.add('Accounts_OAuth_Gitlab_secret', '', { type: 'string', enableQuery, secret: true }); + this.add('Accounts_OAuth_Gitlab_identity_path', '/api/v4/user', { type: 'string', public: true, enableQuery }); + this.add('Accounts_OAuth_Gitlab_merge_users', false, { type: 'boolean', public: true, enableQuery }); this.add('Accounts_OAuth_Gitlab_callback_url', '_oauth/gitlab', { type: 'relativeUrl', readonly: true, force: true, enableQuery }); }); }); diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 85f2b1bc5c75..3b38fc6aa75e 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -117,6 +117,8 @@ "Accounts_OAuth_Gitlab": "OAuth Enabled", "Accounts_OAuth_Gitlab_callback_url": "GitLab Callback URL", "Accounts_OAuth_Gitlab_id": "GitLab Id", + "Accounts_OAuth_Gitlab_identity_path": "Identity Path", + "Accounts_OAuth_Gitlab_merge_users": "Merge Users", "Accounts_OAuth_Gitlab_secret": "Client Secret", "Accounts_OAuth_Google": "Google Login", "Accounts_OAuth_Google_callback_url": "Google Callback URL", diff --git a/server/startup/migrations/index.js b/server/startup/migrations/index.js index 1f1aa93ec6b2..5e51d9d51f39 100644 --- a/server/startup/migrations/index.js +++ b/server/startup/migrations/index.js @@ -146,4 +146,5 @@ import './v145'; import './v146'; import './v147'; import './v148'; +import './v149'; import './xrun'; diff --git a/server/startup/migrations/v149.js b/server/startup/migrations/v149.js new file mode 100644 index 000000000000..c324f5fe063f --- /dev/null +++ b/server/startup/migrations/v149.js @@ -0,0 +1,22 @@ +import { Migrations } from '../../../app/migrations/server'; +import { settings } from '../../../app/settings/server'; +import { Settings } from '../../../app/models/server'; + +Migrations.add({ + version: 149, + up() { + if (settings.get('Accounts_OAuth_Gitlab')) { + const setting = Settings.findById('Accounts_OAuth_Gitlab_identity_path'); + const newValue = '/api/v3/user'; + + if (setting) { + Settings.updateValueById('Accounts_OAuth_Gitlab_identity_path', newValue); + } else { + Settings.createWithIdAndValue('Accounts_OAuth_Gitlab_identity_path', newValue); + } + } + }, + down() { + // Down migration does not apply in this case + }, +}); diff --git a/tests/end-to-end/ui/11-admin.js b/tests/end-to-end/ui/11-admin.js index 5256e27436d1..76c3cbcd7c21 100644 --- a/tests/end-to-end/ui/11-admin.js +++ b/tests/end-to-end/ui/11-admin.js @@ -32,7 +32,7 @@ describe('[Administration]', () => { before(() => { admin.infoLink.waitForVisible(5000); admin.infoLink.click(); - admin.infoRocketChatTable.waitForVisible(5000); + admin.infoRocketChatTable.waitForVisible(10000); }); it('the first title should be Rocket.Chat', () => { admin.infoRocketChatTableTitle.getText().should.equal('Rocket.Chat');