Skip to content

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

[38712] Immediate reminder options

Oliver Günther6647c4489fb3
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 8a368243445..d8addfce1e4 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -122,6 +122,10 @@ class UserPreference < ApplicationRecord
super.presence || { enabled: true, times: ["08:00:00+00:00"] }.with_indifferent_access
end
+ def immediate_reminders
+ super.presence || { mentioned: false }.with_indifferent_access
+ end
+
def canonical_time_zone
return if time_zone.nil?
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index f3f426fedc8..da1d86f25d4 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -635,6 +635,9 @@ en:
explanation: 'You will receive these reminders only for unread notifications and only at hours you specify.'
time_label: 'Time %{counter}:'
title: 'Send me daily email reminders for unread notifications'
+ immediate:
+ title: 'Send me an email reminder'
+ mentioned: 'Immediately when someone @mentions me'
title: 'Email reminders'
diff --git a/config/schemas/user_preferences.schema.json b/config/schemas/user_preferences.schema.json
index 704c8932f40..1d4e14c27aa 100644
--- a/config/schemas/user_preferences.schema.json
+++ b/config/schemas/user_preferences.schema.json
@@ -24,6 +24,9 @@
},
"daily_reminders": {
"$ref": "#/definitions/DailyReminders"
+ },
+ "immediate_reminders": {
+ "$ref": "#/definitions/ImmediateReminders"
}
},
"title": "UserPreferences"
@@ -48,6 +51,19 @@
"times"
],
"title": "DailyReminders"
+ },
+ "ImmediateReminders": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "mentioned": {
+ "type": "boolean"
+ }
+ },
+ "required": [
+ "mentioned"
+ ],
+ "title": "ImmediateReminders"
}
}
}
diff --git a/db/migrate/20210902201126_cleanup_user_preferences.rb b/db/migrate/20210902201126_cleanup_user_preferences.rb
index c5f32e9aba6..0503c2c9dca 100644
--- a/db/migrate/20210902201126_cleanup_user_preferences.rb
+++ b/db/migrate/20210902201126_cleanup_user_preferences.rb
@@ -12,6 +12,18 @@ class CleanupUserPreferences < ActiveRecord::Migration[6.1]
WHERE settings ->> 'warn_on_leaving_unsaved' = '0'
SQL
+ execute <<~SQL.squish
+ UPDATE user_preferences
+ SET settings = settings - 'hide_mail' || '{"hide_mail": false}'
+ WHERE settings ->> 'hide_mail' = '0'
+ SQL
+
+ execute <<~SQL.squish
+ UPDATE user_preferences
+ SET settings = settings - 'hide_mail' || '{"hide_mail": true}'
+ WHERE settings ->> 'hide_mail' = '1'
+ SQL
+
# Remove all other keys from the user preferences
object_map = UserPreferences::Schema.properties.map { |key| "'#{key}', settings->'#{key}'" }.join(", ")
execute <<~SQL.squish
@@ -39,5 +51,17 @@ class CleanupUserPreferences < ActiveRecord::Migration[6.1]
SET settings = settings - 'warn_on_leaving_unsaved' || '{"warn_on_leaving_unsaved": "0"}'
WHERE settings ->> 'warn_on_leaving_unsaved' = 'false'
SQL
+
+ execute <<~SQL.squish
+ UPDATE user_preferences
+ SET settings = settings - 'hide_mail' || '{"hide_mail": 0}'
+ WHERE settings ->> 'hide_mail' = 'true'
+ SQL
+
+ execute <<~SQL.squish
+ UPDATE user_preferences
+ SET settings = settings - 'hide_mail' || '{"hide_mail": 1}'
+ WHERE settings ->> 'hide_mail' = 'false'
+ SQL
end
end
diff --git a/frontend/src/app/features/user-preferences/reminder-settings/immediate-reminders/immediate-reminder-settings.component.html b/frontend/src/app/features/user-preferences/reminder-settings/immediate-reminders/immediate-reminder-settings.component.html
new file mode 100644
index 00000000000..ad7e1e2a571
--- /dev/null
+++ b/frontend/src/app/features/user-preferences/reminder-settings/immediate-reminders/immediate-reminder-settings.component.html
@@ -0,0 +1,14 @@
+<ng-container
+ *ngIf="(immediateReminders$ | async) as immediateReminders">
+ <!-- TODO: use checkbox component for the enabled input -->
+ <input
+ [ngModel]="immediateReminders.mentioned"
+ (ngModelChange)="toggleEnabled('mentioned', $event)"
+ type="checkbox"
+ id="op-reminder-settings-immediate-mentioned"
+ >
+ <label
+ for="op-reminder-settings-immediate-mentioned"
+ [textContent]="text.mentioned">
+ </label>
+</ng-container>
\ No newline at end of file
diff --git a/frontend/src/app/features/user-preferences/reminder-settings/immediate-reminders/immediate-reminder-settings.component.ts b/frontend/src/app/features/user-preferences/reminder-settings/immediate-reminders/immediate-reminder-settings.component.ts
new file mode 100644
index 00000000000..b528e2c305d
--- /dev/null
+++ b/frontend/src/app/features/user-preferences/reminder-settings/immediate-reminders/immediate-reminder-settings.component.ts
@@ -0,0 +1,37 @@
+import {
+ ChangeDetectionStrategy,
+ Component,
+} from '@angular/core';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { UserPreferencesService } from 'core-app/features/user-preferences/state/user-preferences.service';
+import { ImmediateRemindersSettings } from 'core-app/features/user-preferences/state/user-preferences.model';
+
+@Component({
+ selector: 'op-immediate-reminder-settings',
+ templateUrl: './immediate-reminder-settings.component.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class ImmediateReminderSettingsComponent {
+ immediateReminders$ = this.storeService.query.select('immediateReminders');
+
+ text = {
+ mentioned: this.I18n.t('js.reminders.settings.immediate.mentioned'),
+ };
+
+ constructor(
+ private I18n:I18nService,
+ private storeService:UserPreferencesService,
+ ) {
+ }
+
+ toggleEnabled(key:keyof ImmediateRemindersSettings, enabled:boolean):void {
+ this.storeService.store.update(({ immediateReminders }) => (
+ {
+ immediateReminders: {
+ ...immediateReminders,
+ [key]: enabled,
+ },
+ }
+ ));
+ }
+}
diff --git a/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.html b/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.html
index 2851810caf5..08cda0a8c3f 100644
--- a/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.html
+++ b/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.html
@@ -4,7 +4,11 @@
<form>
<section class="form--section">
- <h5 [textContent]="text.daily.title" class="form--section-title"></h5>
+ <h5 [textContent]="text.immediate.title"></h5>
+ <op-immediate-reminder-settings></op-immediate-reminder-settings>
+ </section>
+ <section class="form--section">
+ <h5 [textContent]="text.daily.title"></h5>
<p [textContent]="text.daily.explanation"></p>
<op-reminder-settings-daily-time>
diff --git a/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.ts b/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.ts
index 1bafe8e28da..fd917293534 100644
--- a/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.ts
+++ b/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.ts
@@ -1,12 +1,14 @@
import {
- ChangeDetectionStrategy, Component, Input, OnInit,
+ ChangeDetectionStrategy,
+ Component,
+ Input,
+ OnInit,
} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
import { take } from 'rxjs/internal/operators/take';
import { UIRouterGlobals } from '@uirouter/core';
import { UserPreferencesService } from 'core-app/features/user-preferences/state/user-preferences.service';
-import { UserPreferencesQuery } from 'core-app/features/user-preferences/state/user-preferences.query';
export const myReminderPageComponentSelector = 'op-reminders-page';
@@ -26,12 +28,15 @@ export class ReminderSettingsPageComponent implements OnInit {
title: this.I18n.t('js.reminders.settings.daily.title'),
explanation: this.I18n.t('js.reminders.settings.daily.explanation'),
},
+ immediate: {
+ title: this.I18n.t('js.reminders.settings.immediate.title'),
+ explanation: this.I18n.t('js.reminders.settings.immediate.explanation'),
+ },
};
constructor(
private I18n:I18nService,
- private stateService:UserPreferencesService,
- private query:UserPreferencesQuery,
+ private storeService:UserPreferencesService,
private currentUserService:CurrentUserService,
private uiRouterGlobals:UIRouterGlobals,
) {
@@ -45,12 +50,12 @@ export class ReminderSettingsPageComponent implements OnInit {
.pipe(take(1))
.subscribe((user) => {
this.userId = this.userId || user?.id as string;
- this.stateService.get(this.userId);
+ this.storeService.get(this.userId);
});
}
public saveChanges():void {
- const prefs = this.query.getValue();
- this.stateService.update(this.userId, prefs);
+ const prefs = this.storeService.query.getValue();
+ this.storeService.update(this.userId, prefs);
}
}
diff --git a/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.ts b/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.ts
index 567631c7bef..5dcbda63ba0 100644
--- a/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.ts
+++ b/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.ts
@@ -1,11 +1,14 @@
-import { Component, ChangeDetectionStrategy } from '@angular/core';
+import {
+ ChangeDetectionStrategy,
+ Component,
+} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { UserPreferencesQuery } from 'core-app/features/user-preferences/state/user-preferences.query';
import {
- map, skip,
+ map,
+ skip,
} from 'rxjs/operators';
-import { UserPreferencesStore } from 'core-app/features/user-preferences/state/user-preferences.store';
import { combineLatest } from 'rxjs';
+import { UserPreferencesService } from 'core-app/features/user-preferences/state/user-preferences.service';
@Component({
selector: 'op-reminder-settings-daily-time',
@@ -30,14 +33,15 @@ export class ReminderSettingsDailyTimeComponent {
// The daily reminders with the first value skipped. Only used
// for that skipping as the first value is produced by the front end (default value).
- public dailyReminders$ = this.query.dailyReminders$.pipe(skip(1));
+ public dailyReminders$ = this.storeService.query.dailyReminders$.pipe(skip(1));
// Whether the reminder are active at all.
- public enabled$ = this.query.dailyRemindersEnabled$;
+ public enabled$ = this.storeService.query.dailyRemindersEnabled$;
// The active times as present in the store interleaved with the inactive
// times.
public selectedTimes$ = this
+ .storeService
.query
.dailyRemindersTimes$
.pipe(map((times) => {
@@ -56,22 +60,22 @@ export class ReminderSettingsDailyTimeComponent {
// Times that are truly active:
// * the reminders are not disabled completely
// * the times are not inactive individually.
- public activeTimes$ = combineLatest(
- this.query.dailyRemindersEnabled$,
- this.query.dailyRemindersTimes$,
- ).pipe(map(([enabled, times]) => (enabled ? times : [])));
+ public activeTimes$ = combineLatest([
+ this.storeService.query.dailyRemindersEnabled$,
+ this.storeService.query.dailyRemindersTimes$,
+ ]).pipe(map(([enabled, times]) => (enabled ? times : [])));
// Times can only be removed if the element is active and if there is more than one time present.
- public timeRemovable$ = combineLatest(
- this.query.dailyRemindersEnabled$,
+ public timeRemovable$ = combineLatest([
+ this.storeService.query.dailyRemindersEnabled$,
this.selectedTimes$,
- ).pipe(map(([enabled, selectedTimes]) => enabled && selectedTimes.length > 1));
+ ]).pipe(map(([enabled, selectedTimes]) => enabled && selectedTimes.length > 1));
// Times can not be added if the element is disabled or if all the possible times have already been added (active or not).
- public nonAddable$ = combineLatest(
- this.query.dailyRemindersEnabled$,
+ public nonAddable$ = combineLatest([
+ this.storeService.query.dailyRemindersEnabled$,
this.selectedTimes$,
- ).pipe(map(([enabled, selectedTimes]) => !enabled || selectedTimes.length === this.availableTimes.length));
+ ]).pipe(map(([enabled, selectedTimes]) => !enabled || selectedTimes.length === this.availableTimes.length));
text = {
timeLabel: (counter:number):string => this.I18n.t('js.reminders.settings.daily.time_label', { counter }),
@@ -81,8 +85,7 @@ export class ReminderSettingsDailyTimeComponent {
constructor(
private I18n:I18nService,
- private query:UserPreferencesQuery,
- private store:UserPreferencesStore,
+ private storeService:UserPreferencesService,
) { }
addTime(selectedTimes:string[]):void {
@@ -131,7 +134,7 @@ export class ReminderSettingsDailyTimeComponent {
}
toggleEnabled(enabled:boolean):void {
- this.store.update(({ dailyReminders }) => (
+ this.storeService.store.update(({ dailyReminders }) => (
{
dailyReminders: {
...dailyReminders,
@@ -161,7 +164,7 @@ export class ReminderSettingsDailyTimeComponent {
}
private storeTimes(selectedTimes:string[]) {
- this.store.update(({ dailyReminders }) => (
+ this.storeService.store.update(({ dailyReminders }) => (
{
dailyReminders: {
...dailyReminders,
diff --git a/frontend/src/app/features/user-preferences/state/user-preferences.model.ts b/frontend/src/app/features/user-preferences/state/user-preferences.model.ts
index 9db5a9b4a8d..8dd44a17498 100644
--- a/frontend/src/app/features/user-preferences/state/user-preferences.model.ts
+++ b/frontend/src/app/features/user-preferences/state/user-preferences.model.ts
@@ -4,6 +4,9 @@ export interface DailyRemindersSettings {
enabled:boolean;
times:string[];
}
+export interface ImmediateRemindersSettings {
+ mentioned:boolean;
+}
export interface UserPreferencesModel {
autoHidePopups:boolean;
@@ -13,4 +16,5 @@ export interface UserPreferencesModel {
warnOnLeavingUnsaved:boolean;
notifications:NotificationSetting[];
dailyReminders:DailyRemindersSettings;
+ immediateReminders:ImmediateRemindersSettings;
}
diff --git a/frontend/src/app/features/user-preferences/state/user-preferences.query.ts b/frontend/src/app/features/user-preferences/state/user-preferences.query.ts
index fb1bad78bfe..e43e62fd6d1 100644
--- a/frontend/src/app/features/user-preferences/state/user-preferences.query.ts
+++ b/frontend/src/app/features/user-preferences/state/user-preferences.query.ts
@@ -7,7 +7,6 @@ import { UserPreferencesStore } from 'core-app/features/user-preferences/state/u
import { UserPreferencesModel } from 'core-app/features/user-preferences/state/user-preferences.model';
import { NotificationSetting } from 'core-app/features/user-preferences/state/notification-setting.model';
-@Injectable()
export class UserPreferencesQuery extends Query<UserPreferencesModel> {
/** All notification settings */
notificationSettings$ = this.select('notifications');
diff --git a/frontend/src/app/features/user-preferences/state/user-preferences.service.ts b/frontend/src/app/features/user-preferences/state/user-preferences.service.ts
index f184944f5c5..f7e5e006e59 100644
--- a/frontend/src/app/features/user-preferences/state/user-preferences.service.ts
+++ b/frontend/src/app/features/user-preferences/state/user-preferences.service.ts
@@ -6,11 +6,15 @@ import { Apiv3UserPreferencesPaths } from 'core-app/core/apiv3/endpoints/users/a
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { UserPreferencesModel } from 'core-app/features/user-preferences/state/user-preferences.model';
import { UserPreferencesStore } from 'core-app/features/user-preferences/state/user-preferences.store';
+import { UserPreferencesQuery } from 'core-app/features/user-preferences/state/user-preferences.query';
@Injectable({ providedIn: 'root' })
export class UserPreferencesService {
+ readonly store = new UserPreferencesStore();
+
+ readonly query = new UserPreferencesQuery(this.store);
+
constructor(
- private store:UserPreferencesStore,
private http:HttpClient,
private apiV3Service:APIV3Service,
private notifications:NotificationsService,
diff --git a/frontend/src/app/features/user-preferences/state/user-preferences.store.ts b/frontend/src/app/features/user-preferences/state/user-preferences.store.ts
index 2af412a6655..9de94ab486b 100644
--- a/frontend/src/app/features/user-preferences/state/user-preferences.store.ts
+++ b/frontend/src/app/features/user-preferences/state/user-preferences.store.ts
@@ -42,10 +42,12 @@ function createInitialState():UserPreferencesModel {
enabled: true,
times: ['08:00'],
},
+ immediateReminders: {
+ mentioned: false,
+ },
};
}
-@Injectable()
@StoreConfig({ name: 'notification-settings' })
export class UserPreferencesStore extends Store<UserPreferencesModel> {
constructor() {
diff --git a/frontend/src/app/features/user-preferences/user-preferences.module.ts b/frontend/src/app/features/user-preferences/user-preferences.module.ts
index f2e623432ec..c61e14a81bb 100644
--- a/frontend/src/app/features/user-preferences/user-preferences.module.ts
+++ b/frontend/src/app/features/user-preferences/user-preferences.module.ts
@@ -1,11 +1,12 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { UIRouterModule } from '@uirouter/angular';
-import { FormsModule, ReactiveFormsModule } from '@angular/forms';
+import {
+ FormsModule,
+ ReactiveFormsModule,
+} from '@angular/forms';
import { OPSharedModule } from 'core-app/shared/shared.module';
import { OpenprojectAutocompleterModule } from 'core-app/shared/components/autocompleter/openproject-autocompleter.module';
-import { UserPreferencesStore } from 'core-app/features/user-preferences/state/user-preferences.store';
-import { UserPreferencesQuery } from 'core-app/features/user-preferences/state/user-preferences.query';
import { UserPreferencesService } from 'core-app/features/user-preferences/state/user-preferences.service';
import { NotificationsSettingsPageComponent } from 'core-app/features/user-preferences/notifications-settings/page/notifications-settings-page.component';
import { NotificationSettingRowComponent } from 'core-app/features/user-preferences/notifications-settings/row/notification-setting-row.component';
@@ -15,11 +16,10 @@ import { NotificationsSettingsToolbarComponent } from './notifications-settings/
import { NotificationSettingsTableComponent } from './notifications-settings/table/notification-settings-table.component';
import { ReminderSettingsPageComponent } from './reminder-settings/page/reminder-settings-page.component';
import { ReminderSettingsDailyTimeComponent } from 'core-app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component';
+import { ImmediateReminderSettingsComponent } from 'core-app/features/user-preferences/reminder-settings/immediate-reminders/immediate-reminder-settings.component';
@NgModule({
providers: [
- UserPreferencesStore,
- UserPreferencesQuery,
UserPreferencesService,
],
declarations: [
@@ -30,6 +30,7 @@ import { ReminderSettingsDailyTimeComponent } from 'core-app/features/user-prefe
NotificationSettingsTableComponent,
ReminderSettingsPageComponent,
ReminderSettingsDailyTimeComponent,
+ ImmediateReminderSettingsComponent,
],
imports: [
CommonModule,
diff --git a/lib/api/v3/user_preferences/user_preference_representer.rb b/lib/api/v3/user_preferences/user_preference_representer.rb
index cc1dab96fb4..92f9c8247b3 100644
--- a/lib/api/v3/user_preferences/user_preference_representer.rb
+++ b/lib/api/v3/user_preferences/user_preference_representer.rb
@@ -79,6 +79,8 @@ module API
daily_reminders['times'].map! { |time| time.gsub(/\A(\d{2}:\d{2})\z/, '\1:00+00:00') }
end
+ property :immediate_reminders
+
property :notification_settings,
as: :notifications,
exec_context: :decorator,
diff --git a/spec/features/notifications/immediate_reminder_spec.rb b/spec/features/notifications/immediate_reminder_spec.rb
new file mode 100644
index 00000000000..cf2f82bbcfd
--- /dev/null
+++ b/spec/features/notifications/immediate_reminder_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper'
+
+describe "Immediate reminder settings", type: :feature, js: true do
+ shared_examples 'immediate reminder settings' do
+ it 'allows to configure the reminder settings' do
+ # Save prefs so we can reload them later
+ pref.save!
+
+ # Configure the reminders
+ reminders_settings_page.visit!
+
+ # By default the immediate reminder is unchecked
+ expect(pref.immediate_reminders[:mentioned]).to eq false
+ reminders_settings_page.expect_immediate_reminder :mentioned, false
+
+ reminders_settings_page.set_immediate_reminder :mentioned, true
+
+ reminders_settings_page.save
+
+ reminders_settings_page.expect_and_dismiss_notification(message: I18n.t('js.notice_successful_update'))
+
+ reminders_settings_page.reload!
+
+ reminders_settings_page.set_immediate_reminder :mentioned, true
+
+ expect(pref.reload.immediate_reminders[:mentioned]).to eq true
+ end
+ end
+
+ context 'with the my page' do
+ let(:reminders_settings_page) { Pages::My::Reminders.new(current_user) }
+ let(:pref) { current_user.pref }
+
+ current_user do
+ FactoryBot.create :user
+ end
+
+ it_behaves_like 'immediate reminder settings'
+ end
+
+ context 'with the user administration page' do
+ let(:reminders_settings_page) { Pages::Reminders::Settings.new(other_user) }
+
+ let(:other_user) { FactoryBot.create :user }
+ let(:pref) { other_user.pref }
+
+ current_user do
+ FactoryBot.create :admin
+ end
+
+ it_behaves_like 'immediate reminder settings'
+ end
+end
diff --git a/spec/support/pages/reminders/settings.rb b/spec/support/pages/reminders/settings.rb
index b2c46636592..d9762a303fa 100644
--- a/spec/support/pages/reminders/settings.rb
+++ b/spec/support/pages/reminders/settings.rb
@@ -68,6 +68,24 @@ module Pages
end
end
+ def expect_immediate_reminder(name, enabled)
+ if enabled
+ expect(page).to have_checked_field("op-reminder-settings-immediate-#{name}")
+ else
+ expect(page).to have_no_checked_field("op-reminder-settings-immediate-#{name}")
+ end
+ end
+
+ def set_immediate_reminder(name, enabled)
+ field = page.find_field("op-reminder-settings-immediate-#{name}")
+
+ if enabled
+ field.check
+ else
+ field.uncheck
+ end
+ end
+
def save
click_button 'Save'
end