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

[38077] Skip rendering initial journal details in notifications

Oliver Günthera87031982be0
diff --git a/.rubocop.yml b/.rubocop.yml
index 5e375151df1..9df0cc8b1ba 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -140,6 +140,11 @@ RSpec/MultipleMemoizedHelpers:
RSpec/NestedGroups:
Max: 4
+# Don't force the second argument of describe
+# to be .class_method or #instance_method
+RSpec/DescribeMethod:
+ Enabled: false
+
Style/Alias:
Enabled: false
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 1b6611a1595..8cad67ddf83 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1376,6 +1376,7 @@ en:
notifications:
work_packages:
subject:
+ created: "The work package was created."
assigned: "You have been assigned to %{work_package}"
subscribed: "You subscribed to %{work_package}"
mentioned: "You have been mentioned in %{work_package}"
diff --git a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.html b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.html
index 12d4b33bf4b..cea9c430e33 100644
--- a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.html
+++ b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.html
@@ -1,59 +1,57 @@
<div
- class="op-ian-item"
- [class.op-ian-item_expanded]="notification.expanded"
- attr.data-qa-selector="op-ian-notification-item-{{notification.id}}"
- [attr.data-qa-ian-read]="notification.readIAN === true || undefined"
+ class="op-ian-item"
+ [class.op-ian-item_expanded]="notification.expanded"
+ attr.data-qa-selector="op-ian-notification-item-{{notification.id}}"
+ [attr.data-qa-ian-read]="notification.readIAN === true || undefined"
>
<button
- type="button"
- class="op-ian-item--row"
- (click)="toggleDetails()"
+ type="button"
+ class="op-ian-item--row"
+ (click)="toggleDetails()"
>
<div
- *ngIf="project"
- class="op-ian-item--project"
+ *ngIf="project"
+ class="op-ian-item--project"
>
<a
- class="op-ian-item--project-link"
- [href]="project.showUrl"
- [textContent]="project.title"
- (click)="projectClicked($event)"
- target="_blank"
- ></a>
- </div>
+ class="op-ian-item--project-link"[href]="project.showUrl"
+ [textContent]="project.title"
+ (click)="projectClicked($event)"
+ target="_blank"
+ ></a></div>
<ng-container *ngIf="workPackage$ && (workPackage$ | async) as workPackage; else workPackageLoading">
<span
- class="op-ian-item--title"
- ngPreserveWhitespaces
+ class="op-ian-item--title"
+ ngPreserveWhitespaces
>
<span [ngClass]="'__hl_inline_type_' + workPackage.type.id" [textContent]="workPackage.type.name">
</span>
<a
- [attr.title]="workPackage.subject"
- uiSref="work-packages.show"
- [uiParams]="{workPackageId: workPackage.id}"
- [textContent]="'#' + workPackage.id"
- (click)="resourceLinkClicked.emit(workPackage)"
+ [attr.title]="workPackage.subject"
+ uiSref="work-packages.show"
+ [uiParams]="{workPackageId: workPackage.id}"
+ [textContent]="'#' + workPackage.id"
+ (click)="resourceLinkClicked.emit(workPackage)"
>
</a>
<span
- [textContent]="workPackage.subject"
- class="op-ian-item--work-package-subject"
- [class.-read]="notification.readIAN"
+ [textContent]="workPackage.subject"
+ class="op-ian-item--work-package-subject"
+ [class.-read]="notification.readIAN"
>
</span>
</span>
</ng-container>
<ng-template #workPackageLoading>
<span
- class="op-ian-item--title"
- [textContent]="text.loading"
+ class="op-ian-item--title"
+ [textContent]="text.loading"
></span>
</ng-template>
<ng-container *ngIf="!workPackage$">
<span
- class="op-ian-item--title"
- [textContent]="notification.subject"
+ class="op-ian-item--title"
+ [textContent]="notification.subject"
></span>
</ng-container>
<div
@@ -69,40 +67,48 @@
></op-principal>
</div>
<div
- class="op-ian-item--reason"
- [textContent]="translatedReason || notification.reason"
+ class="op-ian-item--reason"
+ [textContent]="translatedReason || notification.reason"
></div>
<div
- class="op-ian-item--date"
- [title]="fixedTime"
- [textContent]="relativeTime$ | async"
+ class="op-ian-item--date"
+ [title]="fixedTime"
+ [textContent]="relativeTime$ | async"
></div>
</button>
<div
- *ngIf="notification.expanded"
- class="op-ian-item--details"
- data-qa-selector="op-ian-details"
+ *ngIf="notification.expanded"
+ class="op-ian-item--details"
+ data-qa-selector="op-ian-details"
>
<ng-container *ngIf="body.length > 0">
<div class="op-ian-item--body">
<ng-container *ngFor="let bodyItem of body">
<div
- class="op-ian-item--body-item"
- [innerHTML]="bodyItem.html"
+ class="op-ian-item--body-item"
+ [innerHTML]="bodyItem.html"
>
</div>
</ng-container>
</div>
</ng-container>
- <ul class="work-package-details-activities-messages" *ngIf="notification.details.length > 1">
+ <ul
+ class="work-package-details-activities-messages"
+ *ngIf="details.length > 1"
+ >
<ng-container *ngFor="let detail of details">
<li *ngIf="detail.html && detail.html !== ''">
<span
- class="message"
- [innerHtml]="detail.html"
+ class="message"
+ [innerHtml]="detail.html"
></span>
</li>
</ng-container>
</ul>
+ <span
+ *ngIf="details.length === 1"
+ class="message"
+ [innerHtml]="details[0].html"
+ ></span>
</div>
</div>
diff --git a/lib/api/v3/notifications/notification_representer.rb b/lib/api/v3/notifications/notification_representer.rb
index 49c4f1c2043..d1b36d4860c 100644
--- a/lib/api/v3/notifications/notification_representer.rb
+++ b/lib/api/v3/notifications/notification_representer.rb
@@ -58,7 +58,7 @@ module API
getter: ->(*) do
next unless represented.journal
- formatted_details(represented.journal)
+ formatted_notification_details(represented.journal)
.unshift formatted_notes(represented.journal)
end,
render_nil: false
@@ -99,6 +99,20 @@ module API
def _type
'Notification'
end
+
+ ##
+ # For notifications, we want to skip the initial journal
+ # as the information is not that useful
+ def formatted_notification_details(journal)
+ if journal.initial?
+ note_created = I18n.t('notifications.work_packages.subject.created')
+ [
+ { format: 'custom', raw: note_created, html: "<em>#{note_created}</em>" }
+ ]
+ else
+ formatted_details(journal)
+ end
+ end
end
end
end
diff --git a/spec/features/notifications/notification_center_spec.rb b/spec/features/notifications/notification_center_spec.rb
index 0c467d0c4d8..3b686e6fc67 100644
--- a/spec/features/notifications/notification_center_spec.rb
+++ b/spec/features/notifications/notification_center_spec.rb
@@ -19,6 +19,25 @@ describe "Notification center", type: :feature, js: true do
let(:center) { ::Components::Notifications::Center.new }
+ describe 'notification for a new journal' do
+ current_user { recipient }
+
+ it 'will not show all details of the journal' do
+ allow(notification.journal).to receive(:initial?).and_return true
+ visit home_path
+ center.expect_bell_count 1
+ center.open
+
+ center.expect_work_package_item notification
+ center.click_item notification
+ center.expect_expanded notification
+
+ center.within_item(notification) do
+ expect(page).to have_text "The work package was created."
+ end
+ end
+ end
+
describe 'basic use case' do
current_user { recipient }
diff --git a/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb b/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb
index f22a5cc45a6..63383b6082d 100644
--- a/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb
@@ -31,6 +31,8 @@ require 'spec_helper'
describe ::API::V3::Notifications::NotificationRepresenter, 'rendering' do
include ::API::V3::Utilities::PathHelper
+ subject(:generated) { representer.to_json }
+
shared_let(:project) { FactoryBot.create :project }
shared_let(:resource) { FactoryBot.create :work_package, project: project }
@@ -55,8 +57,6 @@ describe ::API::V3::Notifications::NotificationRepresenter, 'rendering' do
let(:embed_links) { false }
let(:read_ian) { false }
- subject(:generated) { representer.to_json }
-
describe 'self link' do
it_behaves_like 'has a titled link' do
let(:link) { 'self' }
@@ -201,6 +201,26 @@ describe ::API::V3::Notifications::NotificationRepresenter, 'rendering' do
.at_path("_embedded/activity/_type")
end
end
+
+ it 'renders details of journal' do
+ allow(journal).to receive(:initial?).and_return false
+
+ expect(generated)
+ .to have_json_size(10)
+ .at_path('details')
+ end
+
+ it 'renders a placeholder if journal is initial' do
+ allow(journal).to receive(:initial?).and_return true
+
+ details = [
+ { format: 'markdown', raw: '', html: '' },
+ { format: 'custom', raw: "The work package was created.", html: "<em>The work package was created.</em>" }
+ ]
+ expect(generated)
+ .to be_json_eql(details.to_json)
+ .at_path('details')
+ end
end
end
end