-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: write message to gestionnaires as administrateur
- Loading branch information
seb-by-ouidou
committed
Dec 22, 2023
1 parent
33e9106
commit cfd420d
Showing
27 changed files
with
378 additions
and
3 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
app/components/groupe_gestionnaire/card/commentaires_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class GroupeGestionnaire::Card::CommentairesComponent < ApplicationComponent | ||
def initialize(groupe_gestionnaire:, administrateur:, path:) | ||
@groupe_gestionnaire = groupe_gestionnaire | ||
@administrateur = administrateur | ||
@path = path | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
app/components/groupe_gestionnaire/card/commentaires_component/commentaires_component.fr.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
fr: | ||
title: | ||
one: Message | ||
other: Messages |
9 changes: 9 additions & 0 deletions
9
...mponents/groupe_gestionnaire/card/commentaires_component/commentaires_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.fr-col-6.fr-col-md-4.fr-col-lg-3 | ||
= link_to @path, id: 'administrateurs', class: 'fr-tile fr-enlarge-link' do | ||
.fr-tile__body.flex.column.align-center.justify-between | ||
%div | ||
.line-count.fr-my-1w | ||
%p.fr-tag= @administrateur.commentaire_groupe_gestionnaires.size | ||
%h3.fr-h6 | ||
= t('.title', count: @administrateur.commentaire_groupe_gestionnaires.size) | ||
%p.fr-btn.fr-btn--tertiary= t('views.shared.actions.see') |
24 changes: 24 additions & 0 deletions
24
app/components/groupe_gestionnaire/groupe_gestionnaire_commentaires/commentaire_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class GroupeGestionnaire::GroupeGestionnaireCommentaires::CommentaireComponent < ApplicationComponent | ||
include ApplicationHelper | ||
|
||
def initialize(commentaire:, connected_user:, is_gestionnaire: true) | ||
@commentaire = commentaire | ||
@connected_user = connected_user | ||
@is_gestionnaire = is_gestionnaire | ||
end | ||
|
||
private | ||
|
||
def commentaire_issuer | ||
if @commentaire.sent_by?(@connected_user) | ||
t('.you') | ||
else | ||
(@commentaire.gestionnaire || @commentaire.sender).email | ||
end | ||
end | ||
|
||
def commentaire_date | ||
is_current_year = (@commentaire.created_at.year == Time.zone.today.year) | ||
l(@commentaire.created_at, format: is_current_year ? :message_date : :message_date_with_year) | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
...naire/groupe_gestionnaire_commentaires/commentaire_component/commentaire_component.en.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
en: | ||
reply: Reply | ||
delete_button: Delete this message | ||
confirm: Are you sure you want to delete this message ? | ||
you: You | ||
deleted_body: Message deleted |
7 changes: 7 additions & 0 deletions
7
...naire/groupe_gestionnaire_commentaires/commentaire_component/commentaire_component.fr.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
fr: | ||
reply: Répondre | ||
delete_button: Supprimer le message | ||
confirm: Êtes-vous sûr de vouloir supprimer ce message ? | ||
you: Vous | ||
deleted_body: Message supprimé |
12 changes: 12 additions & 0 deletions
12
...re/groupe_gestionnaire_commentaires/commentaire_component/commentaire_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.width-100 | ||
%h2.fr-h6 | ||
%span.mail | ||
= commentaire_issuer | ||
|
||
%span.date{ class: ["fr-text--xs", "fr-text-mention--grey", "font-weight-normal"] } | ||
= commentaire_date | ||
.rich-text | ||
- if @commentaire.discarded? | ||
%p= t('.deleted_body') | ||
- else | ||
= render SimpleFormatComponent.new(@commentaire.body, allow_a: false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class CommentaireGroupeGestionnaire < ApplicationRecord | ||
include Discard::Model | ||
belongs_to :groupe_gestionnaire | ||
belongs_to :gestionnaire, optional: true | ||
belongs_to :sender, polymorphic: true | ||
|
||
validates :body, presence: { message: "ne peut être vide" } | ||
|
||
def soft_deletable?(connected_user) | ||
sent_by?(connected_user) && sent_by_gestionnaire? && !discarded? | ||
end | ||
|
||
def soft_delete! | ||
discard! | ||
end | ||
|
||
def sent_by_gestionnaire? | ||
gestionnaire_id.present? | ||
end | ||
|
||
def sent_by?(someone) | ||
if gestionnaire | ||
someone == gestionnaire | ||
else | ||
someone == sender | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/views/administrateurs/groupe_gestionnaire/commentaires.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
= render partial: 'gestionnaires/breadcrumbs', | ||
locals: { steps: [['Mon groupe gestionnaire', admin_groupe_gestionnaire_path], | ||
['Messagerie']], preview: false } | ||
|
||
.container | ||
%h1 Messagerie de « #{@groupe_gestionnaire.name} » | ||
.messagerie.container | ||
- if current_administrateur.commentaire_groupe_gestionnaires.where(groupe_gestionnaire: @groupe_gestionnaire).present? | ||
%ul.messages-list{ data: { controller: 'scroll-to' } } | ||
- current_administrateur.commentaire_groupe_gestionnaires.where(groupe_gestionnaire: @groupe_gestionnaire).each do |commentaire| | ||
%li.message{ class: commentaire_is_from_me_class(commentaire, current_administrateur), id: dom_id(commentaire) } | ||
= render(GroupeGestionnaire::GroupeGestionnaireCommentaires::CommentaireComponent.new(commentaire: commentaire, connected_user: current_administrateur, is_gestionnaire: false)) | ||
= render partial: "shared/groupe_gestionnaires/commentaires/form", locals: { commentaire: @commentaire, form_url: admin_groupe_gestionnaire_create_commentaire_path } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/views/shared/groupe_gestionnaires/commentaires/_form.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
= render NestedForms::FormOwnerComponent.new | ||
= form_for(commentaire, url: form_url) do |f| | ||
- dossier = commentaire.dossier | ||
- placeholder = t('views.shared.dossiers.messages.form.write_message_to_administration_placeholder') | ||
- if instructeur_signed_in? || administrateur_signed_in? || expert_signed_in? | ||
- placeholder = t('views.shared.dossiers.messages.form.write_message_placeholder') | ||
%p.mandatory-explanation= t('asterisk_html', scope: [:utils]) | ||
|
||
= render Dsfr::InputComponent.new(form: f, attribute: :body, input_type: :text_area, opts: { rows: 5, placeholder: placeholder, title: placeholder, class: 'fr-input message-textarea'}) | ||
|
||
.fr-mt-3w | ||
= f.submit t('views.shared.dossiers.messages.form.send_message'), class: 'fr-btn', data: { disable: true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
db/migrate/20231016134902_create_commentaire_groupe_gestionnaires.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateCommentaireGroupeGestionnaires < ActiveRecord::Migration[6.1] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
create_table "commentaire_groupe_gestionnaires" do |t| | ||
t.references :groupe_gestionnaire, index: { name: :index_commentaire_groupe_gestionnaires_on_groupe_gestionnaire } | ||
t.references "gestionnaire", null: true | ||
t.string "sender_type", null: false | ||
t.bigint "sender_id", null: false | ||
t.string "body" | ||
t.datetime "discarded_at" | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...onents/groupe_gestionnaire/groupe_gestionnaire_commentaires/commentaire_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
RSpec.describe GroupeGestionnaire::GroupeGestionnaireCommentaires::CommentaireComponent, type: :component do | ||
let(:component) do | ||
described_class.new( | ||
commentaire: commentaire, | ||
connected_user: connected_user | ||
) | ||
end | ||
let(:connected_user) { create(:administrateur) } | ||
let(:commentaire) { create(:commentaire_groupe_gestionnaire, sender: connected_user) } | ||
|
||
subject { render_inline(component).to_html } | ||
|
||
it { is_expected.to include("plop") } | ||
|
||
describe '#commentaire_date' do | ||
let(:present_date) { Time.zone.local(2018, 9, 2, 10, 5, 0) } | ||
let(:creation_date) { present_date } | ||
let(:commentaire) do | ||
Timecop.freeze(creation_date) { create(:commentaire_groupe_gestionnaire, sender: connected_user) } | ||
end | ||
|
||
subject do | ||
Timecop.freeze(present_date) { component.send(:commentaire_date) } | ||
end | ||
|
||
it 'doesn’t include the creation year' do | ||
expect(subject).to eq 'le 2 septembre à 10 h 05' | ||
end | ||
|
||
context 'when displaying a commentaire created on a previous year' do | ||
let(:creation_date) { present_date.prev_year } | ||
it 'includes the creation year' do | ||
expect(subject).to eq 'le 2 septembre 2017 à 10 h 05' | ||
end | ||
end | ||
|
||
context 'when formatting the first day of the month' do | ||
let(:present_date) { Time.zone.local(2018, 9, 1, 10, 5, 0) } | ||
it 'includes the ordinal' do | ||
expect(subject).to eq 'le 1er septembre à 10 h 05' | ||
end | ||
end | ||
end | ||
|
||
describe '#commentaire_issuer' do | ||
let(:commentaire) { create(:commentaire_groupe_gestionnaire, sender: connected_user) } | ||
|
||
subject { component.send(:commentaire_issuer) } | ||
|
||
context 'issuer is connected_user' do | ||
it 'returns "Vous"' do | ||
expect(subject).to include 'Vous' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :commentaire_groupe_gestionnaire do | ||
association :groupe_gestionnaire | ||
|
||
body { 'plop' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.