Skip to content
代码片段 群组 项目
未验证 提交 2b19907c 编辑于 作者: Gosia Ksionek's avatar Gosia Ksionek 提交者: GitLab
浏览文件

Merge branch '16564-snooze-many-unsnooze-many' into 'master'

Add new `SnoozeMany` and `UnsnoozeMany` mutations for todos

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/179870



Merged-by: default avatarGosia Ksionek <mksionek@gitlab.com>
Approved-by: default avatarNaman Jagdish Gala <ngala@gitlab.com>
Approved-by: default avatarGosia Ksionek <mksionek@gitlab.com>
Reviewed-by: default avatarGosia Ksionek <mksionek@gitlab.com>
Reviewed-by: default avatarThomas Hutterer <thutterer@gitlab.com>
Co-authored-by: default avatarThomas Hutterer <thutterer@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -16,11 +16,11 @@ class BaseMany < ::Mutations::BaseMutation # rubocop:disable GraphQL/GraphqlName
null: false,
description: 'Updated to-do items.'
def resolve(ids:)
def resolve(ids:, **kwargs)
check_update_limit!(amount: ids.size)
todos = authorized_find_all_pending_by_current_user(model_ids_of(ids))
updated_ids = process_todos(todos)
updated_ids = process_todos(todos, **kwargs)
{
updated_ids: updated_ids,
......
# frozen_string_literal: true
module Mutations
module Todos
class SnoozeMany < BaseMany
graphql_name 'TodoSnoozeMany'
argument :snooze_until,
::Types::TimeType,
required: true,
description: 'Time until which the todos should be snoozed.'
private
def process_todos(todos, snooze_until:)
::Todos::SnoozingService.new.snooze_todos(todos, snooze_until)
end
def todo_state_to_find
:pending
end
end
end
end
# frozen_string_literal: true
module Mutations
module Todos
class UnsnoozeMany < BaseMany
graphql_name 'TodoUnsnoozeMany'
private
def process_todos(todos)
::Todos::SnoozingService.new.unsnooze_todos(todos)
end
def todo_state_to_find
:pending
end
end
end
end
......@@ -149,6 +149,8 @@ class MutationType < BaseObject
mount_mutation Mutations::Todos::RestoreMany
mount_mutation Mutations::Todos::Snooze, experiment: { milestone: '17.4' }
mount_mutation Mutations::Todos::UnSnooze, experiment: { milestone: '17.4' }
mount_mutation Mutations::Todos::SnoozeMany, experiment: { milestone: '17.9' }
mount_mutation Mutations::Todos::UnsnoozeMany, experiment: { milestone: '17.9' }
mount_mutation Mutations::Snippets::Destroy
mount_mutation Mutations::Snippets::Update
mount_mutation Mutations::Snippets::Create
......
......@@ -5,7 +5,7 @@
# Used for snoozing/un-snoozing todos
#
# Ex.
# SnoozingService.new.snooze(todo, 1.day.from_now)
# Todos::SnoozingService.new.snooze_todo(todo, 1.day.from_now)
#
module Todos
class SnoozingService
......@@ -24,5 +24,13 @@ def un_snooze_todo(todo)
ServiceResponse.error(message: todo.errors.full_messages)
end
end
def snooze_todos(todos, snooze_until)
todos.batch_update(snoozed_until: snooze_until)
end
def unsnooze_todos(todos)
todos.batch_update(snoozed_until: nil)
end
end
end
......@@ -10520,6 +10520,30 @@ Input type: `TodoSnoozeInput`
| <a id="mutationtodosnoozeerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationtodosnoozetodo"></a>`todo` | [`Todo!`](#todo) | Requested to-do item. |
 
### `Mutation.todoSnoozeMany`
DETAILS:
**Introduced** in GitLab 17.9.
**Status**: Experiment.
Input type: `TodoSnoozeManyInput`
#### Arguments
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationtodosnoozemanyclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationtodosnoozemanyids"></a>`ids` | [`[TodoID!]!`](#todoid) | Global IDs of the to-do items to process (a maximum of 100 is supported at once). |
| <a id="mutationtodosnoozemanysnoozeuntil"></a>`snoozeUntil` | [`Time!`](#time) | Time until which the todos should be snoozed. |
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationtodosnoozemanyclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationtodosnoozemanyerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationtodosnoozemanytodos"></a>`todos` | [`[Todo!]!`](#todo) | Updated to-do items. |
### `Mutation.todoUnSnooze`
 
DETAILS:
......@@ -10543,6 +10567,29 @@ Input type: `TodoUnSnoozeInput`
| <a id="mutationtodounsnoozeerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationtodounsnoozetodo"></a>`todo` | [`Todo!`](#todo) | Requested to-do item. |
 
### `Mutation.todoUnsnoozeMany`
DETAILS:
**Introduced** in GitLab 17.9.
**Status**: Experiment.
Input type: `TodoUnsnoozeManyInput`
#### Arguments
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationtodounsnoozemanyclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationtodounsnoozemanyids"></a>`ids` | [`[TodoID!]!`](#todoid) | Global IDs of the to-do items to process (a maximum of 100 is supported at once). |
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationtodounsnoozemanyclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationtodounsnoozemanyerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationtodounsnoozemanytodos"></a>`todos` | [`[Todo!]!`](#todo) | Updated to-do items. |
### `Mutation.todosMarkAllDone`
 
Input type: `TodosMarkAllDoneInput`
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::Todos::SnoozeMany, feature_category: :notifications do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:other_user) { create(:user) }
let_it_be(:todo1) { create(:todo, user: user, author: other_user, state: :pending) }
let_it_be(:todo2) { create(:todo, user: user, author: other_user, state: :pending) }
let_it_be(:done_todo) { create(:todo, user: user, author: other_user, state: :done) }
let_it_be(:other_user_todo) { create(:todo, user: other_user, author: user, state: :pending) }
let(:snooze_until) { 1.day.from_now }
let(:current_user) { user }
describe '#process_todos' do
subject(:mutation) do
described_class
.new(object: nil, context: query_context, field: nil)
.resolve(ids: [
global_id_of(todo1),
global_id_of(done_todo),
global_id_of(other_user_todo)
], snooze_until: snooze_until)
end
it 'snoozes current user\'s todos matching given ids until given timestamp' do
expect { mutation }.to change { todo1.reload.snoozed_until }.to be_within(1.second).of(snooze_until)
end
it 'does not change other pending todos of the current user' do
expect { mutation }.not_to change { todo2.reload.snoozed_until }
end
it 'does not change done todos' do
expect { mutation }.not_to change { done_todo.reload.snoozed_until }
end
it 'does not change todos of other users' do
expect { mutation }.not_to change { other_user_todo.reload.snoozed_until }
end
it 'returns the ids of processed todos' do
expect(mutation[:updated_ids]).to contain_exactly(todo1.id)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::Todos::UnsnoozeMany, feature_category: :notifications do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:other_user) { create(:user) }
let_it_be(:snoozed_todo1) { create(:todo, user: user, author: other_user, snoozed_until: 8.hours.from_now) }
let_it_be(:snoozed_todo2) { create(:todo, user: user, author: other_user, snoozed_until: 5.days.from_now) }
let_it_be(:done_todo) { create(:todo, user: user, author: other_user, state: :done) }
let_it_be(:other_user_snoozed_todo) { create(:todo, user: other_user, author: user, snoozed_until: 1.hour.from_now) }
let(:current_user) { user }
describe '#process_todos' do
subject(:mutation) do
described_class
.new(object: nil, context: query_context, field: nil)
.resolve(ids: [
global_id_of(snoozed_todo1),
global_id_of(done_todo),
global_id_of(other_user_snoozed_todo)
])
end
it 'unsnoozes current user\'s todos matching given ids until given timestamp' do
expect { mutation }.to change { snoozed_todo1.reload.snoozed_until }.to be_nil
end
it 'does not change other snoozed todos of the current user' do
expect { mutation }.not_to change { snoozed_todo2.reload.snoozed_until }
end
it 'does not change done todos' do
expect { mutation }.not_to change { done_todo.reload.snoozed_until }
end
it 'does not change todos of other users' do
expect { mutation }.not_to change { other_user_snoozed_todo.reload.snoozed_until }
end
it 'returns the ids of processed todos' do
expect(mutation[:updated_ids]).to contain_exactly(snoozed_todo1.id)
end
end
end
......@@ -83,4 +83,43 @@
end
end
end
describe '#snooze_todos' do
let_it_be(:time) { 8.hours.from_now }
let_it_be(:todo1) { create(:todo, :pending, user: user) }
let_it_be(:todo2) { create(:todo, :pending, user: user, snoozed_until: 1.hour.ago) }
let(:todos) { Todo.where(id: [todo1.id, todo2.id]) }
it 'snoozes all todos until the provided time' do
service.snooze_todos(todos, time)
expect(todo1.reload.snoozed_until).to be_within(1.second).of(time)
expect(todo2.reload.snoozed_until).to be_within(1.second).of(time)
end
it 'responds with the updated todo ids' do
response = service.snooze_todos(todos, time)
expect(response).to match_array [todo1.id, todo2.id]
end
end
describe '#unsnooze_todos' do
let_it_be(:todo1) { create(:todo, :pending, user: user, snoozed_until: 1.day.from_now) }
let_it_be(:todo2) { create(:todo, :pending, user: user, snoozed_until: nil) }
let(:todos) { Todo.where(id: [todo1.id, todo2.id]) }
it 'unsnoozes all todos' do
service.unsnooze_todos(todos)
expect(todo1.reload.snoozed_until).to be_nil
expect(todo2.reload.snoozed_until).to be_nil
end
it 'responds with the updated todo ids' do
response = service.unsnooze_todos(todos)
expect(response).to match_array [todo1.id, todo2.id]
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册