OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
addressed feedback from @akabiru
Jonas Jabari267dd6f4851e
diff --git a/app/components/work_packages/reminder/modal_body_component.html.erb b/app/components/work_packages/reminder/modal_body_component.html.erbindex 35a8f23fce6..38d6e3daa51 100644--- a/app/components/work_packages/reminder/modal_body_component.html.erb+++ b/app/components/work_packages/reminder/modal_body_component.html.erb@@ -14,22 +14,6 @@<%= form_flex_container.with_row do %><%= render(WorkPackages::Reminder::Note.new(f)) %><% end %>- <% if errors.present? %>- <%= form_flex_container.with_row(flex_layout: true) do |errors_container| %>- <% errors.full_messages.each do |error_message| %>- <%= errors_container.with_row(flex_layout: true) do |errors_row| %>- <%= errors_row.with_column(mr: 2) do %>- <%= render(Primer::Beta::Octicon.new(icon: :'alert-fill', color: :danger)) %>- <% end %>- <%= errors_row.with_column do %>- <%= render(Primer::Beta::Text.new(color: :danger)) do %>- <%= error_message %>- <% end %>- <% end %>- <% end %>- <% end %>- <% end %>- <% end %><% if reminder.persisted? %><%= form_flex_container.with_row(flex_layout: true,justify_content: :space_between) do |actions_row| %>@@ -39,19 +23,27 @@type: :submit,formaction: work_package_reminder_path(remindable, reminder),formmethod: :delete- )) { I18n.t(:button_delete_reminder) } %>- <% end %>- <%= actions_row.with_column do %>- <%= render(Primer::Beta::Button.new(scheme: :primary,- type: :submit)) { I18n.t(:button_save) } %>+ )) { I18n.t(:button_remove_reminder) } %><% end %>+ <%= actions_row.with_column(flex_layout: true) do |actions_sub_row| %>+ <%= actions_sub_row.with_column(mr: 2) do %>+ <%= render(Primer::Beta::Button.new(**cancel_button_props)) { I18n.t(:button_cancel) } %>+ <% end %>+ <%= actions_sub_row.with_column do %>+ <%= render(Primer::Beta::Button.new(scheme: :primary,+ type: :submit)) { I18n.t(:button_save) } %>+ <% end %>+ <% end%><% end %><% else%><%= form_flex_container.with_row(flex_layout: true,justify_content: :flex_end) do |actions_row| %>+ <%= actions_row.with_column(mr: 2) do %>+ <%= render(Primer::Beta::Button.new(**cancel_button_props)) { I18n.t(:button_cancel) } %>+ <% end %><%= actions_row.with_column do %><%= render(Primer::Beta::Button.new(scheme: :primary,- type: :submit)) { I18n.t(:button_set_reminder) } %>+ type: :submit)) { I18n.t(:button_schedule) } %><% end %><% end %><% end%>diff --git a/app/components/work_packages/reminder/modal_body_component.rb b/app/components/work_packages/reminder/modal_body_component.rbindex e8115ea2a53..b723e462197 100644--- a/app/components/work_packages/reminder/modal_body_component.rb+++ b/app/components/work_packages/reminder/modal_body_component.rb@@ -69,6 +69,18 @@ module WorkPackagesendend+ def cancel_button_props+ {+ scheme: :secondary,+ data: {+ controller: "primer-to-angular-modal",+ application_target: "dynamic",+ action: "click->primer-to-angular-modal#close",+ test_selector: "op-reminder-modal-close-button"+ }+ }+ end+def remind_at_date_initial_valueformat_time_as_date(@reminder.remind_at, format: "%Y-%m-%d")enddiff --git a/app/controllers/work_packages/reminders_controller.rb b/app/controllers/work_packages/reminders_controller.rbindex 7708416a535..7866147aea1 100644--- a/app/controllers/work_packages/reminders_controller.rb+++ b/app/controllers/work_packages/reminders_controller.rb@@ -175,6 +175,13 @@ class WorkPackages::RemindersController < ApplicationController@reminder = @work_package.reminders.upcoming_and_visible_to(User.current).find(params[:id])+ rescue ActiveRecord::RecordNotFound+ update_flash_message_via_turbo_stream(+ message: I18n.t(:error_reminder_not_found),+ scheme: :danger+ )+ respond_with_turbo_streams(status: :not_found)+ falseenddef reminder_paramsdiff --git a/app/models/reminder.rb b/app/models/reminder.rbindex 56cef70a4b1..9b6213dd2a1 100644--- a/app/models/reminder.rb+++ b/app/models/reminder.rb@@ -40,12 +40,9 @@ class Reminder < ApplicationRecordenddef self.upcoming_and_visible_to(user)- visible_reminders = visible(user)- reminder_notifications_for_reminders = ReminderNotification.where(reminder: visible_reminders)-- visible_reminders+ visible(user).where(completed_at: nil)- .where.not(id: reminder_notifications_for_reminders.select(:reminder_id))+ .where.missing(:reminder_notifications)enddef unread_notifications?diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 5e700adfec4..d5aa73fc335 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1606,7 +1606,6 @@ en:button_create: "Create"button_create_and_continue: "Create and continue"button_delete: "Delete"- button_delete_reminder: "Delete reminder"button_decline: "Decline"button_delete_watcher: "Delete watcher %{name}"button_download: "Download"@@ -1626,6 +1625,7 @@ en:button_print: "Print"button_quote: "Quote"button_remove: Remove+ button_remove_reminder: "Remove reminder"button_rename: "Rename"button_replace: "Replace"button_revoke: "Revoke"@@ -1636,6 +1636,7 @@ en:button_save_as: "Save as"button_apply_changes: "Apply changes"button_save_back: "Save and back"+ button_schedule: "Schedule"button_set_reminder: "Set reminder"button_show: "Show"button_sort: "Sort"@@ -1893,6 +1894,7 @@ en:error_pdf_export_too_many_columns: "Too many columns selected for the PDF export. Please reduce the number of columns."error_pdf_failed_to_export: "The PDF export could not be saved: %{error}"error_token_authenticity: "Unable to verify Cross-Site Request Forgery token. Did you try to submit data on multiple browsers or tabs? Please close all tabs and try again."+ error_reminder_not_found: "The reminder was not found or was already notified about."error_work_package_not_found_in_project: "The work package was not found or does not belong to this project"error_work_package_id_not_found: "The work package was not found."error_must_be_project_member: "must be project member"diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex b7a4e8038a4..c5f781fb7d3 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -1128,6 +1128,7 @@ en:duplicate_query_title: "Name of this view already exists. Change anyway?"text_no_results: "No matching views were found."reminders:+ button_label: "Set reminder"title:new: "Set reminder"edit: "Edit reminder"diff --git a/docs/api/apiv3/components/schemas/reminder_model.yml b/docs/api/apiv3/components/schemas/reminder_model.ymlnew file mode 100644index 00000000000..5306d646985--- /dev/null+++ b/docs/api/apiv3/components/schemas/reminder_model.yml@@ -0,0 +1,28 @@+# Schema: ReminderModel+---+type: object+properties:+ id:+ type: integer+ description: Reminder id+ readOnly: true+ minimum: 1+ note:+ type: string+ description: The note of the reminder+ remindAt:+ type: string+ format: date-time+ description: The date and time when the reminder is due+_links:+ required:+ - creator+ type: object+ properties:+ creator:+ allOf:+ - $ref: "./link.yml"+ - description: |-+ The person that created the reminder++ **Resource**: Userdiff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.ymlindex e3afad89a8f..53c78bf3b7a 100644--- a/docs/api/apiv3/openapi-spec.yml+++ b/docs/api/apiv3/openapi-spec.yml@@ -478,6 +478,8 @@ paths:"$ref": "./paths/work_package_revisions.yml""/api/v3/work_packages/{id}/relations":"$ref": "./paths/work_package_relations.yml"+ "/api/v3/work_packages/{id}/reminders":+ "$ref": "./paths/work_package_reminders.yml""/api/v3/work_packages/{id}/watchers":"$ref": "./paths/work_package_watchers.yml""/api/v3/work_packages/{id}/watchers/{user_id}":@@ -795,6 +797,8 @@ components:"$ref": "./components/schemas/relation_read_model.yml"RelationWriteModel:"$ref": "./components/schemas/relation_write_model.yml"+ ReminderModel:+ "$ref": "./components/schemas/reminder_model.yml"RevisionModel:"$ref": "./components/schemas/revision_model.yml"RevisionsModel:diff --git a/docs/api/apiv3/paths/work_package_reminders.yml b/docs/api/apiv3/paths/work_package_reminders.ymlnew file mode 100644index 00000000000..4f7027a5339--- /dev/null+++ b/docs/api/apiv3/paths/work_package_reminders.yml@@ -0,0 +1,61 @@+# /api/v3/work_packages/{id}/reminders+---+get:+ parameters:+ - description: Work package id+ example: '1'+ in: path+ name: id+ required: true+ schema:+ type: integer+ responses:+ '200':+ description: OK+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/reminder_model.yml'+ headers: {}+ '403':+ content:+ application/hal+json:+ schema:+ $ref: "../components/schemas/error_response.yml"+ examples:+ response:+ value:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission+ message: You are not allowed to see linked reminders for this work+ package.+ description: |-+ Returned if the client does not have sufficient permissions.++ **Required permission:** view work packages for the project the work package is contained in.+ **Required permission:** manage own reminders for the work package.++ *Note that you will only receive this error, if you are at least allowed to see the corresponding work package.*+ headers: {}+ '404':+ content:+ application/hal+json:+ schema:+ $ref: "../components/schemas/error_response.yml"+ examples:+ response:+ value:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:NotFound+ message: The specified work package does not exist.+ description: |-+ Returned if the work package does not exist or the client does not have sufficient permissions to see it.++ **Required permission:** view work package+ headers: {}+ tags:+ - Work Packages+ description: |-+ Gets a list of your upcoming reminders for this work package.+ operationId: Reminders+ summary: Remindersdiff --git a/frontend/src/app/features/work-packages/components/wp-buttons/wp-reminder-button/wp-reminder-button.component.ts b/frontend/src/app/features/work-packages/components/wp-buttons/wp-reminder-button/wp-reminder-button.component.tsindex 8a469179e5a..b7f7e50da1c 100644--- a/frontend/src/app/features/work-packages/components/wp-buttons/wp-reminder-button/wp-reminder-button.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-buttons/wp-reminder-button/wp-reminder-button.component.ts@@ -34,14 +34,12 @@ import { OpModalService } from 'core-app/shared/components/modal/modal.service';import {WorkPackageReminderModalComponent,} from 'core-app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal';-import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { filter, map, startWith, switchMap } from 'rxjs/operators';-import { merge, Observable, of } from 'rxjs';+import { merge, Observable } from 'rxjs';import { ActionsService } from 'core-app/core/state/actions/actions.service';import { reminderModalUpdated } from 'core-app/features/work-packages/components/wp-reminder-modal/reminder.actions';import { CollectionResource } from 'core-app/features/hal/resources/collection-resource';-import { notificationCountChanged } from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';import { IanBellService } from 'core-app/features/in-app-notifications/bell/state/ian-bell.service';@Component({@@ -55,6 +53,8 @@ export class WorkPackageReminderButtonComponent extends UntilDestroyedMixin implreminderCount$:Observable<number>;+ public buttonTitle = this.I18n.t('js.work_packages.reminders.button_label');+constructor(readonly I18n:I18nService,readonly opModalService:OpModalService,diff --git a/frontend/src/app/features/work-packages/components/wp-buttons/wp-reminder-button/wp-reminder-button.html b/frontend/src/app/features/work-packages/components/wp-buttons/wp-reminder-button/wp-reminder-button.htmlindex 9fe2f3eda79..555002f5da0 100644--- a/frontend/src/app/features/work-packages/components/wp-buttons/wp-reminder-button/wp-reminder-button.html+++ b/frontend/src/app/features/work-packages/components/wp-buttons/wp-reminder-button/wp-reminder-button.html@@ -1,6 +1,7 @@<button- class="button toolbar-icon"+ class="button toolbar-icon d-flex flex-items-center"data-test-selector="op-wp-reminder-button"+ [attr.title]="buttonTitle"(click)="openModal()"><svg@@ -8,11 +9,8 @@class="button--icon"size="small"></svg>- <span class="button--text">- <span *ngIf="(reminderCount$ | async) as reminderCount"- class="badge -secondary"- [textContent]="reminderCount">- </span>+ <span *ngIf="(reminderCount$ | async) as reminderCount"+ class="button--text text-small badge -secondary"+ [textContent]="reminderCount"></span>-</button>diff --git a/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.html b/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.htmlindex 17eee0ce970..021be9da9bd 100644--- a/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.html+++ b/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.html@@ -36,10 +36,17 @@<op-content-loaderviewBox="0 0 180 80">- <svg:rect height="10" rx="2" ry="2" width="110" x="0" y="0"/>- <svg:rect height="10" rx="2" ry="2" width="25" x="120" y="0"/>- <svg:rect height="10" rx="2" ry="2" width="25" x="155" y="0"/>- <svg:rect height="25%" rx="2" ry="2" width="180" x="0" y="16"/>+ <svg:rect height="8" rx="2" ry="2" width="30" x="0" y="0"/>+ <svg:rect height="10" rx="2" ry="2" width="180" x="0" y="10"/>++ <svg:rect height="8" rx="2" ry="2" width="30" x="0" y="24"/>+ <svg:rect height="10" rx="2" ry="2" width="180" x="0" y="34"/>++ <svg:rect height="8" rx="2" ry="2" width="30" x="0" y="48"/>+ <svg:rect height="10" rx="2" ry="2" width="180" x="0" y="58"/>++ <svg:rect height="8" rx="2" ry="2" width="50" x="0" y="72"/>+ <svg:rect height="8" rx="2" ry="2" width="50" x="130" y="72"/></op-content-loader></turbo-frame></div>diff --git a/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.ts b/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.tsindex f00fd8bcf57..b0a946d02b7 100644--- a/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.ts+++ b/frontend/src/app/features/work-packages/components/wp-reminder-modal/wp-reminder.modal.ts@@ -15,7 +15,7 @@ import { WorkPackageResource } from 'core-app/features/hal/resources/work-packagimport { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { ActionsService } from 'core-app/core/state/actions/actions.service';import { reminderModalUpdated } from 'core-app/features/work-packages/components/wp-reminder-modal/reminder.actions';-import { Observable, of } from 'rxjs';+import { Observable } from 'rxjs';import { map } from 'rxjs/operators';import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { CollectionResource } from 'core-app/features/hal/resources/collection-resource';diff --git a/frontend/src/stimulus/controllers/dynamic/primer-to-angular-modal.controller.ts b/frontend/src/stimulus/controllers/dynamic/primer-to-angular-modal.controller.tsnew file mode 100644index 00000000000..a1856650d49--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/primer-to-angular-modal.controller.ts@@ -0,0 +1,45 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) the OpenProject GmbH+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License version 3.+ *+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+ * Copyright (C) 2006-2013 Jean-Philippe Lang+ * Copyright (C) 2010-2013 the ChiliProject Team+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License+ * as published by the Free Software Foundation; either version 2+ * of the License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+ *+ * See COPYRIGHT and LICENSE files for more details.+ * +++ */++import { Controller } from '@hotwired/stimulus';+import { from, filter, take } from 'rxjs';++export default class PrimerToAngularModalController extends Controller {+ close(event:CustomEvent):void {+ from(window.OpenProject.getPluginContext())+ .pipe(+ take(1),+ filter((context) => context.services.opModalService?.activeModalInstance$ !== null),+ )+ .subscribe((context) => {+ context.services.opModalService.activeModalInstance$.value?.closeMe(event);+ });+ }+}diff --git a/lib/api/v3/reminders/reminder_representer.rb b/lib/api/v3/reminders/reminder_representer.rbindex e72c98a5b9f..88e78173cd5 100644--- a/lib/api/v3/reminders/reminder_representer.rb+++ b/lib/api/v3/reminders/reminder_representer.rb@@ -31,10 +31,17 @@ module APImodule Remindersclass ReminderRepresenter < ::API::Decorators::Singleinclude API::Decorators::DateProperty+ include API::Decorators::LinkedResourceproperty :iddate_time_property :remind_at++ property :note++ associated_resource :creator,+ v3_path: :user,+ representer: ::API::V3::Users::UserRepresenterendendenddiff --git a/spec/contracts/reminders/base_contract_spec.rb b/spec/contracts/reminders/base_contract_spec.rbindex 1dc9fcd654d..b8e57fe7964 100644--- a/spec/contracts/reminders/base_contract_spec.rb+++ b/spec/contracts/reminders/base_contract_spec.rb@@ -105,6 +105,20 @@ RSpec.describe Reminders::BaseContract doendend+ describe "validate remind at is present" do+ context "when remind at is blank" do+ before { reminder.remind_at = nil }++ it_behaves_like "contract is invalid", remind_at: :blank+ end++ context "when remind at is present" do+ before { reminder.remind_at = 1.day.from_now }++ it_behaves_like "contract is valid"+ end+ end+describe "validate remind at is in future" docontext "when remind at is in the past" dobefore { reminder.remind_at = 1.day.ago }diff --git a/spec/features/work_packages/reminders_spec.rb b/spec/features/work_packages/reminders_spec.rbindex a135d841290..73e24e90fb1 100644--- a/spec/features/work_packages/reminders_spec.rb+++ b/spec/features/work_packages/reminders_spec.rb@@ -68,7 +68,7 @@ RSpec.describe "Work package reminder modal",specify "can create a reminder, subsequently update it and delete it" dodate = Date.current + 2.weeks- time = "05:00".to_time+ time = Time.zone.parse("05:00")work_package_page.visit!work_package_page.click_reminder_button@@ -83,7 +83,7 @@ RSpec.describe "Work package reminder modal",fill_in "Time", with: timefill_in "Note", with: "Never forget!"- click_link_or_button "Set reminder"+ click_link_or_button "Schedule"endwork_package_page.expect_and_dismiss_flash(type: :success,@@ -107,7 +107,7 @@ RSpec.describe "Work package reminder modal",.to have_css(".spot-modal--subheader",text: "You will receive a notification for this work package at the chosen time.")expect(page).to have_field("Date", with: date)- expect(page).to have_field("Time", with: "05:00")+ expect(page).to have_field("Time", with: time.in_time_zone(current_user.time_zone).strftime("%H:%M"))expect(page).to have_field("Note", with: "Never forget!")expect(page).to have_button("Save")@@ -128,7 +128,7 @@ RSpec.describe "Work package reminder modal",work_package_page.click_reminder_buttonwait_for_network_idlewithin ".spot-modal" do- click_link_or_button "Delete reminder"+ click_link_or_button "Remove reminder"endwork_package_page.expect_and_dismiss_flash(type: :success,@@ -137,9 +137,59 @@ RSpec.describe "Work package reminder modal",expect(Reminder.upcoming_and_visible_to(user_with_permissions).count).to eq(0)end+ it "renders an error flash when the reminder modal is opened in edit mode" \+ "and the notification for it is fired and subsequently clicking save",+ with_settings: { notifications_polling_interval: 1_000 } do+ Reminders::CreateService.new(user: current_user).call(+ remindable: work_package,+ remind_at: 1.minute.from_now,+ creator: current_user,+ note: "Will fire soon"+ )++ work_package_page.visit!+ work_package_page.expect_reminder_button_with_count(1)+ work_package_page.click_reminder_button+ wait_for_network_idle++ within ".spot-modal" do+ expect(page)+ .to have_css(".spot-modal--header-title", text: "Edit reminder")+ expect(page)+ .to have_css(".spot-modal--subheader",+ text: "You will receive a notification for this work package at the chosen time.")+ end++ perform_enqueued_jobs+ center.expect_bell_count(1)++ within ".spot-modal" do+ fill_in "Note", with: "I'm changing this"+ click_link_or_button "Save"+ wait_for_network_idle+ end++ work_package_page.expect_flash(type: :danger,+ message: I18n.t(:error_reminder_not_found))++ within ".spot-modal" do+ find_test_selector("op-reminder-dialog-modal--close-icon").click+ end++ work_package_page.dismiss_flash!+ work_package_page.expect_reminder_button_without_count+ work_package_page.click_reminder_button+ wait_for_network_idle++ within ".spot-modal" do+ # Now it should be the create reminder modal+ expect(page).to have_css(".spot-modal--header-title", text: "Set reminder")+ end+ end+describe "validations" doit "renders errors on the date field or time field when the reminder is in the past" do- two_am = "02:00".to_time+ two_am = Time.zone.parse("02:00")thirty_minutes_ago = 30.minutes.ago.in_time_zone(current_user.time_zone).strftime("%H:%M")@@ -165,7 +215,7 @@ RSpec.describe "Work package reminder modal",fill_in "Date", with: yesterdayfill_in "Time", with: two_amfill_in "Note", with: "Never forget!"- click_link_or_button "Set reminder"+ click_link_or_button "Schedule"wait_for_network_idleexpect(page).to have_css(".FormControl-inlineValidation", text: "Date must be in the future.")@@ -174,7 +224,7 @@ RSpec.describe "Work package reminder modal",# 30 minutes agofill_in "Date", with: todayfill_in "Time", with: thirty_minutes_ago- click_link_or_button "Set reminder"+ click_link_or_button "Schedule"wait_for_network_idleexpect(page).to have_css(".FormControl-inlineValidation", text: "Time must be in the future.")@@ -183,7 +233,7 @@ RSpec.describe "Work package reminder modal",# 30 minutes from nowfill_in "Date", with: todayfill_in "Time", with: thirty_minutes_from_now- click_link_or_button "Set reminder"+ click_link_or_button "Schedule"wait_for_network_idleend@@ -205,8 +255,8 @@ RSpec.describe "Work package reminder modal",.to have_css(".spot-modal--subheader",text: "You will receive a notification for this work package at the chosen time.")- # Click the Set reminder button without filling in the date or time- click_link_or_button "Set reminder"+ # Click the Schedule button without filling in the date or time+ click_link_or_button "Schedule"wait_for_network_idleexpect(page).to have_css(".FormControl-inlineValidation", text: "Date can't be blank")@@ -214,7 +264,7 @@ RSpec.describe "Work package reminder modal",# Fill in the date but not the timefill_in "Date", with: 1.week.from_now.to_date- click_link_or_button "Set reminder"+ click_link_or_button "Schedule"wait_for_network_idle# The error message is only on the time field@@ -223,8 +273,8 @@ RSpec.describe "Work package reminder modal",# Fill in the time but not the datefill_in "Date", with: ""- fill_in "Time", with: "05:00".to_time- click_link_or_button "Set reminder"+ fill_in "Time", with: Time.zone.parse("05:00")+ click_link_or_button "Schedule"wait_for_network_idleexpect(page).to have_css(".FormControl-inlineValidation", text: "Date can't be blank.")@@ -305,10 +355,23 @@ RSpec.describe "Work package reminder modal",expect(page).to have_field("Date")expect(page).to have_field("Time")expect(page).to have_field("Note")- expect(page).to have_button("Set reminder")+ expect(page).to have_button("Schedule")endendend++ it "has a Primer close button that closes the Angular spot modal" do+ work_package_page.visit!+ work_package_page.click_reminder_button+ wait_for_network_idle+ within ".spot-modal" do+ expect(page)+ .to have_css(".spot-modal--header-title", text: "Set reminder")+ find_test_selector("op-reminder-modal-close-button").click+ end++ expect(page).to have_no_css(".spot-modal", wait: 0)+ endendcontext "without permissions to manage own reminders" dodiff --git a/spec/models/reminder_spec.rb b/spec/models/reminder_spec.rbindex 3c3a9c675a7..759aa91296a 100644--- a/spec/models/reminder_spec.rb+++ b/spec/models/reminder_spec.rb@@ -36,6 +36,37 @@ RSpec.describe Reminder doit { is_expected.to have_many(:notifications).through(:reminder_notifications) }end+ describe "Scopes" do+ describe ".visible" do+ it "returns reminders where the creator is the given user" do+ user = create(:user)+ other_user = create(:user)+ reminder = create(:reminder, creator: user)+ _other_reminder = create(:reminder, creator: other_user)++ expect(described_class.visible(user)).to contain_exactly(reminder)+ end+ end++ describe ".upcoming_and_visible_to" do+ it "returns reminders where the creator is the given user" \+ "and there are no reminder_notifications for it yet" do+ user = create(:user)+ other_user = create(:user)+ reminder = create(:reminder, creator: user)+ _another_reminder_with_notification = create(:reminder, creator: user) do |r|+ create(:reminder_notification, reminder: r)+ end+ _other_users_reminder_with_notification = create(:reminder, creator: other_user) do |r|+ create(:reminder_notification, reminder: r)+ end+ _other_users_reminder = create(:reminder, creator: other_user)++ expect(described_class.upcoming_and_visible_to(user)).to contain_exactly(reminder)+ end+ end+ end+describe "#unread_notifications?" docontext "with an unread notification" dosubject { create(:reminder, :with_unread_notifications) }diff --git a/spec/requests/api/v3/reminders/reminders_api_spec.rb b/spec/requests/api/v3/reminders/reminders_api_spec.rbnew file mode 100644index 00000000000..6160bde64a1--- /dev/null+++ b/spec/requests/api/v3/reminders/reminders_api_spec.rb@@ -0,0 +1,124 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "spec_helper"++RSpec.describe API::V3::Reminders::RemindersAPI do+ let!(:project) { create(:project) }++ let!(:role_with_permissions) { create(:project_role, permissions: %i[view_work_packages manage_own_reminders]) }+ let!(:role_without_permissions) { create(:project_role, permissions: %i[view_work_packages]) }++ let!(:user_with_permissions) do+ create(:user, member_with_roles: { project => role_with_permissions })+ end+ let!(:other_user_without_permissions) do+ create(:user, member_with_roles: { project => role_without_permissions })+ end++ let!(:work_package) { create(:work_package, project:) }+ let!(:other_work_package) { create(:work_package, project:) }++ let!(:user_with_permissions_past_reminder) do+ Reminders::CreateService.new(user: user_with_permissions, contract_class: nil)+ .call(remindable: work_package,+ remind_at: 1.day.ago,+ creator: user_with_permissions,+ note: "I'm the user with permissions and my reminder is in the past")+ .result+ end+ let!(:user_with_permissions_future_reminder) do+ Reminders::CreateService.new(user: user_with_permissions, contract_class: nil)+ .call(remindable: work_package,+ remind_at: 1.day.from_now,+ creator: user_with_permissions,+ note: "I'm the user with permissions and my reminder is in the future")+ .result+ end+ let!(:user_with_permissions_future_reminder_in_other_work_package) do+ Reminders::CreateService.new(user: user_with_permissions, contract_class: nil)+ .call(remindable: other_work_package,+ remind_at: 1.day.from_now,+ creator: user_with_permissions,+ note: "I'm the user with permissions and my reminder is in the future in another work package")+ .result+ end+ let!(:other_user_without_permissions_reminder) do+ Reminders::CreateService.new(user: other_user_without_permissions, contract_class: nil)+ .call(remindable: other_work_package,+ remind_at: 1.day.from_now,+ creator: other_user_without_permissions,+ note: "I'm the other user without permissions and my reminder is in the future")+ .result+ end+ let!(:other_user_without_permissions_reminder_past) do+ Reminders::CreateService.new(user: other_user_without_permissions, contract_class: nil)+ .call(remindable: other_work_package,+ remind_at: 1.day.ago,+ creator: other_user_without_permissions,+ note: "I'm the other user without permissions and my reminder is in the past")+ .result+ end+ let!(:other_user_without_permissions_reminder_in_other_work_package) do+ Reminders::CreateService.new(user: other_user_without_permissions, contract_class: nil)+ .call(remindable: other_work_package,+ remind_at: 1.day.from_now,+ creator: other_user_without_permissions,+ note: "I'm the other user without permissions and my reminder is in the" \+ "future in another work package")+ .result+ end++ let(:href) { "/api/v3/work_packages/#{work_package.id}/reminders" }+ let(:request) { get href }+ let(:result) do+ request+ JSON.parse last_response.body+ end+ let(:subjects) { reminders.pluck("id") }++ def reminders+ result["_embedded"]["elements"]+ end++ context "with no permissions" do+ current_user { other_user_without_permissions }++ it "responds with unprocessable entity" do+ expect(result["errorIdentifier"]).to eq("urn:openproject-org:api:v3:errors:MissingPermission")+ end+ end++ context "with permissions" do+ current_user { user_with_permissions }++ it "returns the future reminders for the current user in the given work package" do+ expect(subjects).to contain_exactly(user_with_permissions_future_reminder.id)+ end+ end+end