diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-31 18:06:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-31 18:06:53 +0000 |
commit | 996f700997805b3590da8d8afdd19d193989078a (patch) | |
tree | fb555d6012ea1a6f018694b62bba5c68c8c623e1 | |
parent | 083d64c6468a070ae7b0b406ead8d87da27d1d22 (diff) | |
download | gitlab-ce-996f700997805b3590da8d8afdd19d193989078a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | app/models/concerns/subscribable.rb | 8 | ||||
-rw-r--r-- | changelogs/unreleased/34132-graphql-epic-subscribtions.yml | 5 | ||||
-rw-r--r-- | doc/api/graphql/reference/index.md | 8 | ||||
-rw-r--r-- | lib/gitlab/regex.rb | 4 | ||||
-rw-r--r-- | locale/gitlab.pot | 9 | ||||
-rw-r--r-- | spec/frontend/environment.js | 6 | ||||
-rw-r--r-- | spec/javascripts/u2f/mock_u2f_device.js | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/regex_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/concerns/subscribable_spec.rb | 56 |
9 files changed, 113 insertions, 11 deletions
diff --git a/app/models/concerns/subscribable.rb b/app/models/concerns/subscribable.rb index 92a5c1112af..33e9e0e38fb 100644 --- a/app/models/concerns/subscribable.rb +++ b/app/models/concerns/subscribable.rb @@ -59,6 +59,14 @@ module Subscribable .update(subscribed: false) end + def set_subscription(user, desired_state, project = nil) + if desired_state + subscribe(user, project) + else + unsubscribe(user, project) + end + end + private def unsubscribe_from_other_levels(user, project) diff --git a/changelogs/unreleased/34132-graphql-epic-subscribtions.yml b/changelogs/unreleased/34132-graphql-epic-subscribtions.yml new file mode 100644 index 00000000000..a35da2e5212 --- /dev/null +++ b/changelogs/unreleased/34132-graphql-epic-subscribtions.yml @@ -0,0 +1,5 @@ +--- +title: Graphql mutation for (un)subscribing to an epic +merge_request: 19083 +author: +type: added diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md index a8c4e966099..1b663acd5fb 100644 --- a/doc/api/graphql/reference/index.md +++ b/doc/api/graphql/reference/index.md @@ -271,6 +271,14 @@ The API can be explored interactively using the [GraphiQL IDE](../index.md#graph | `createNote` | Boolean! | Whether or not a user can perform `create_note` on this resource | | `awardEmoji` | Boolean! | Whether or not a user can perform `award_emoji` on this resource | +### EpicSetSubscriptionPayload + +| Name | Type | Description | +| --- | ---- | ---------- | +| `clientMutationId` | String | A unique identifier for the client performing the mutation. | +| `errors` | String! => Array | Reasons why the mutation failed. | +| `epic` | Epic | The epic after mutation | + ### EpicTreeReorderPayload | Name | Type | Description | diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 3d1f15c72ae..607f5321856 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -128,6 +128,10 @@ module Gitlab def aws_arn_regex_message "must be a valid Amazon Resource Name" end + + def utc_date_regex + @utc_date_regex ||= /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/.freeze + end end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 6ed098d1842..193eddc191d 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -4801,6 +4801,12 @@ msgstr "" msgid "Created a branch and a merge request to resolve this issue." msgstr "" +msgid "Created after" +msgstr "" + +msgid "Created before" +msgstr "" + msgid "Created branch '%{branch_name}' and a merge request to resolve this issue." msgstr "" @@ -9153,6 +9159,9 @@ msgstr "" msgid "Invalid date" msgstr "" +msgid "Invalid date format. Please use UTC format as YYYY-MM-DD" +msgstr "" + msgid "Invalid feature" msgstr "" diff --git a/spec/frontend/environment.js b/spec/frontend/environment.js index 290c0e797cb..3c6553f3547 100644 --- a/spec/frontend/environment.js +++ b/spec/frontend/environment.js @@ -41,6 +41,12 @@ class CustomEnvironment extends JSDOMEnvironment { this.global.fixturesBasePath = `${ROOT_PATH}/tmp/tests/frontend/fixtures${IS_EE ? '-ee' : ''}`; this.global.staticFixturesBasePath = `${ROOT_PATH}/spec/frontend/fixtures`; + /** + * window.fetch() is required by the apollo-upload-client library otherwise + * a ReferenceError is generated: https://github.com/jaydenseric/apollo-upload-client/issues/100 + */ + this.global.fetch = () => {}; + // Not yet supported by JSDOM: https://github.com/jsdom/jsdom/issues/317 this.global.document.createRange = () => ({ setStart: () => {}, diff --git a/spec/javascripts/u2f/mock_u2f_device.js b/spec/javascripts/u2f/mock_u2f_device.js index 26ddd8ade61..ec8425a4e3e 100644 --- a/spec/javascripts/u2f/mock_u2f_device.js +++ b/spec/javascripts/u2f/mock_u2f_device.js @@ -1,20 +1,16 @@ -/* eslint-disable no-unused-expressions, no-return-assign, no-param-reassign */ +/* eslint-disable no-unused-expressions */ export default class MockU2FDevice { constructor() { this.respondToAuthenticateRequest = this.respondToAuthenticateRequest.bind(this); this.respondToRegisterRequest = this.respondToRegisterRequest.bind(this); window.u2f || (window.u2f = {}); - window.u2f.register = (function(_this) { - return function(appId, registerRequests, signRequests, callback) { - return (_this.registerCallback = callback); - }; - })(this); - window.u2f.sign = (function(_this) { - return function(appId, challenges, signRequests, callback) { - return (_this.authenticateCallback = callback); - }; - })(this); + window.u2f.register = (appId, registerRequests, signRequests, callback) => { + this.registerCallback = callback; + }; + window.u2f.sign = (appId, challenges, signRequests, callback) => { + this.authenticateCallback = callback; + }; } respondToRegisterRequest(params) { diff --git a/spec/lib/gitlab/regex_spec.rb b/spec/lib/gitlab/regex_spec.rb index b557baed258..4678adcd85f 100644 --- a/spec/lib/gitlab/regex_spec.rb +++ b/spec/lib/gitlab/regex_spec.rb @@ -75,4 +75,14 @@ describe Gitlab::Regex do it { is_expected.not_to match('123456789012') } it { is_expected.not_to match('role/role-name') } end + + describe '.utc_date_regex' do + subject { described_class.utc_date_regex } + + it { is_expected.to match('2019-10-20') } + it { is_expected.to match('1990-01-01') } + it { is_expected.not_to match('11-1234-90') } + it { is_expected.not_to match('aa-1234-cc') } + it { is_expected.not_to match('9/9/2018') } + end end diff --git a/spec/models/concerns/subscribable_spec.rb b/spec/models/concerns/subscribable_spec.rb index 2f88adf08dd..f189cd7633c 100644 --- a/spec/models/concerns/subscribable_spec.rb +++ b/spec/models/concerns/subscribable_spec.rb @@ -133,4 +133,60 @@ describe Subscribable, 'Subscribable' do end end end + + describe '#set_subscription' do + shared_examples 'setting subscriptions' do + context 'when desired_state is set to true' do + context 'when a user is subscribed to the resource' do + it 'keeps the user subscribed' do + resource.subscriptions.create(user: user_1, subscribed: true, project: resource_project) + + resource.set_subscription(user_1, true, resource_project) + + expect(resource.subscribed?(user_1, resource_project)).to be_truthy + end + end + + context 'when a user is not subscribed to the resource' do + it 'subscribes the user to the resource' do + expect { resource.set_subscription(user_1, true, resource_project) } + .to change { resource.subscribed?(user_1, resource_project) } + .from(false).to(true) + end + end + end + + context 'when desired_state is set to false' do + context 'when a user is subscribed to the resource' do + it 'unsubscribes the user from the resource' do + resource.subscriptions.create(user: user_1, subscribed: true, project: resource_project) + + expect { resource.set_subscription(user_1, false, resource_project) } + .to change { resource.subscribed?(user_1, resource_project) } + .from(true).to(false) + end + end + + context 'when a user is not subscribed to the resource' do + it 'keeps the user unsubscribed' do + resource.set_subscription(user_1, false, resource_project) + + expect(resource.subscribed?(user_1, resource_project)).to be_falsey + end + end + end + end + + context 'without project' do + let(:resource_project) { nil } + + it_behaves_like 'setting subscriptions' + end + + context 'with project' do + let(:resource_project) { project } + + it_behaves_like 'setting subscriptions' + end + end end |