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

Merge branch 'dev' into feature/38723-notification-settings-frontend

Benjamin Bädorfaf73a59acff6
diff --cc app/controllers/my_controller.rb
index be0782b3a6b,1fd1a6c2daf..60cd3af57c3
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@@ -85,22 -86,26 +86,29 @@@ class MyController < ApplicationControl
def notifications
render html: '',
layout: 'angular',
- locals: { menu_name: :my_menu }
+ locals: {
+ menu_name: :my_menu,
+ page_title: [I18n.t(:label_my_account), I18n.t('js.notifications.settings.title')]
+ }
end
+ # Configure user's mail reminders
+ def reminders
+ render html: '',
+ layout: 'angular',
+ locals: { menu_name: :my_menu }
+ end
+
# Create a new feeds key
def generate_rss_key
- if request.post?
- token = Token::RSS.create!(user: current_user)
- flash[:info] = [
- t('my.access_token.notice_reset_token', type: 'RSS').html_safe,
- content_tag(:strong, token.plain_value),
- t('my.access_token.token_value_warning')
- ]
- end
+ token = Token::RSS.create!(user: current_user)
+ flash[:info] = [
+ # rubocop:disable Rails/OutputSafety
+ t('my.access_token.notice_reset_token', type: 'RSS').html_safe,
+ # rubocop:enable Rails/OutputSafety
+ content_tag(:strong, token.plain_value),
+ t('my.access_token.token_value_warning')
+ ]
rescue StandardError => e
Rails.logger.error "Failed to reset user ##{current_user.id} RSS key: #{e}"
flash[:error] = t('my.access_token.failed_to_reset_token', error: e.message)
diff --cc frontend/src/app/features/user-preferences/notifications-settings/inline-create/notification-setting-inline-create.component.ts
index 3bcdc45a8a5,447c086d9a4..b04d36be3e8
--- a/frontend/src/app/features/user-preferences/notifications-settings/inline-create/notification-setting-inline-create.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/inline-create/notification-setting-inline-create.component.ts
@@@ -50,7 -50,7 +51,6 @@@ export class NotificationSettingInlineC
constructor(
private I18n:I18nService,
private apiV3Service:APIV3Service,
- private query:UserPreferencesQuery,
- private storeService:UserPreferencesService,
) {
}
diff --cc frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
index 5e5e8c4503a,42eb376ee47..e122714c611
--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
@@@ -91,11 -26,8 +91,11 @@@ export class NotificationsSettingsPageC
};
constructor(
+ private changeDetectorRef:ChangeDetectorRef,
private I18n:I18nService,
- private stateService:UserPreferencesService,
+ private storeService:UserPreferencesService,
+ private query:UserPreferencesQuery,
+ private store:UserPreferencesStore,
private currentUserService:CurrentUserService,
private uiRouterGlobals:UIRouterGlobals,
) {
@@@ -110,94 -41,12 +110,94 @@@
.pipe(take(1))
.subscribe((user) => {
this.userId = this.userId || user.id!;
- this.stateService.get(this.userId);
+ this.storeService.get(this.userId);
});
+
+ this.query.notificationsForGlobal$
+ .pipe(this.untilDestroyed())
+ .subscribe((settings) => {
+ if (!settings) {
+ return;
+ }
+
+ this.form.get('involved')?.setValue(settings.involved);
+ this.form.get('workPackageCreated')?.setValue(settings.workPackageCreated);
+ this.form.get('workPackageProcessed')?.setValue(settings.workPackageProcessed);
+ this.form.get('workPackageScheduled')?.setValue(settings.workPackageScheduled);
+ this.form.get('workPackagePrioritized')?.setValue(settings.workPackagePrioritized);
+ this.form.get('workPackageCommented')?.setValue(settings.workPackageCommented);
+ });
+
+ this.query.projectNotifications$
+ .pipe(this.untilDestroyed())
+ .subscribe((settings) => {
+ if (!settings) {
+ return;
+ }
+
+ const projectSettings = new FormArray([]);
+ projectSettings.clear();
+ settings
+ .sort(
+ (a, b):number => a._links.project.title!.localeCompare(b._links.project.title!),
+ )
+ .forEach((setting) => projectSettings.push(new FormGroup({
+ project: new FormControl(setting._links.project),
+ involved: new FormControl(setting.involved),
+ workPackageCreated: new FormControl(setting.workPackageCreated),
+ workPackageProcessed: new FormControl(setting.workPackageProcessed),
+ workPackageScheduled: new FormControl(setting.workPackageScheduled),
+ workPackagePrioritized: new FormControl(setting.workPackagePrioritized),
+ workPackageCommented: new FormControl(setting.workPackageCommented),
+ })));
+
+ this.form.setControl('projectSettings', projectSettings);
+ this.changeDetectorRef.detectChanges();
+ });
}
public saveChanges():void {
- const prefs = this.storeService.query.getValue();
- this.storeService.update(this.userId, prefs);
+ const prefs = this.store.getValue();
+ const notificationSettings:IFullNotificationSettingsValue = this.form.value;
+ const globalPrefs:NotificationSetting = {
+ _links: { project: { href: null } },
+ channel: 'in_app',
+ watched: true,
+ mentioned: true,
+ involved: notificationSettings.involved,
+ workPackageCreated: notificationSettings.workPackageCreated,
+ workPackageProcessed: notificationSettings.workPackageProcessed,
+ workPackageScheduled: notificationSettings.workPackageScheduled,
+ workPackagePrioritized: notificationSettings.workPackagePrioritized,
+ workPackageCommented: notificationSettings.workPackageCommented,
+ all: false,
+ };
+
+ const projectPrefs:NotificationSetting[] = notificationSettings.projectSettings.map((settings) => ({
+ _links: { project: { href: settings.project.href } },
+ channel: 'in_app',
+ watched: true,
+ mentioned: true,
+ involved: settings.involved,
+ workPackageCreated: settings.workPackageCreated,
+ workPackageProcessed: settings.workPackageProcessed,
+ workPackageScheduled: settings.workPackageScheduled,
+ workPackagePrioritized: settings.workPackagePrioritized,
+ workPackageCommented: settings.workPackageCommented,
+ all: false,
+ }));
+
- this.stateService.update(this.userId, {
++ this.storeService.update(this.userId, {
+ ...prefs,
+ notifications: [
+ globalPrefs,
+ ...projectPrefs,
+ ].reduce((total, next) => [
+ ...total,
+ next,
+ { ...next, channel: 'mail' },
+ { ...next, channel: 'mail_digest' },
+ ], []),
+ });
}
}
diff --cc frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts
index 7d9011b59ce,684da640951..ac49f15951d
--- a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts
@@@ -1,15 -1,19 +1,16 @@@
// noinspection ES6UnusedImports
import {
- ChangeDetectionStrategy,
Component,
+ ChangeDetectionStrategy,
Input,
} from '@angular/core';
-import { KeyValue } from '@angular/common';
+import { FormArray, FormGroup, FormControl } from '@angular/forms';
+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
+import idFromLink from 'core-app/features/hal/helpers/id-from-link';
+ import { UserPreferencesService } from 'core-app/features/user-preferences/state/user-preferences.service';
import { HalSourceLink } from 'core-app/features/hal/resources/hal-resource';
-import {
- buildNotificationSetting,
- NotificationSetting,
-} from 'core-app/features/user-preferences/state/notification-setting.model';
-import { arrayAdd } from '@datorama/akita';
@Component({
selector: 'op-notification-settings-table',
diff --cc frontend/src/app/features/user-preferences/notifications-settings/toolbar/notifications-settings-toolbar.component.ts
index a5710b09057,8496b410e19..312d5a3e703
--- a/frontend/src/app/features/user-preferences/notifications-settings/toolbar/notifications-settings-toolbar.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/toolbar/notifications-settings-toolbar.component.ts
@@@ -7,8 -11,11 +11,10 @@@ import { UserPreferencesService } from
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NotificationsSettingsToolbarComponent {
+ projectSettings$ = this.storeService.query.projectNotifications$;
+
text = {
title: this.I18n.t('js.notifications.settings.title'),
- remove_projects: this.I18n.t('js.notifications.settings.remove_projects'),
};
constructor(
diff --cc frontend/src/app/features/user-preferences/state/user-preferences.query.ts
index 1819953dc31,e43e62fd6d1..d5934789e11
--- 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,10 -7,11 +7,9 @@@ import { UserPreferencesStore } from 'c
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');
- /** Notification settings grouped by Project */
notificationsGroupedByProject$:Observable<{ [key:string]:NotificationSetting[] }> = this
.notificationSettings$
.pipe(
diff --cc frontend/src/app/features/user-preferences/user-preferences.module.ts
index a09391636fe,c61e14a81bb..828de21697a
--- a/frontend/src/app/features/user-preferences/user-preferences.module.ts
+++ b/frontend/src/app/features/user-preferences/user-preferences.module.ts
@@@ -1,13 -1,15 +1,14 @@@
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';
import { NotificationSettingInlineCreateComponent } from 'core-app/features/user-preferences/notifications-settings/inline-create/notification-setting-inline-create.component';
import { MY_ACCOUNT_ROUTES } from 'core-app/features/user-preferences/user-preferences.routes';
import { NotificationsSettingsToolbarComponent } from './notifications-settings/toolbar/notifications-settings-toolbar.component';
diff --cc spec/features/notifications/digest_mail_spec.rb
index 92c94d49235,1ba1004b122..aee3da13605
--- a/spec/features/notifications/digest_mail_spec.rb
+++ b/spec/features/notifications/digest_mail_spec.rb
@@@ -85,11 -132,9 +89,9 @@@ describe "Digest email", type: :feature
5.times { perform_enqueued_jobs }
expect(ActionMailer::Base.deliveries.length)
- .to be 1
+ .to be 2
expect(ActionMailer::Base.deliveries.first.subject)
- .to eql I18n.t(:'mail.digests.work_packages.subject',
- date: Time.current.strftime('%m/%d/%Y'),
- number: 1)
+ .to eql "OpenProject - 1 unread notification including a mention"
end
end