-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Valuation comments #2403
Valuation comments #2403
Conversation
44feee6
to
9ec0af2
Compare
Why: Budget Investment's valuators need to be able to comment on investments without making those comments public. We need a way to clearly make a distinction to avoid "leaking" internal valuation comments. How: Adding a boolean `valuation` attribute defaulted to false to the Comments table, and index on it with concurrent algorithm as explained at https://robots.thoughtbot.com/how-to-create-postgres-indexes-concurrently-in The name `valuation` was chosen instead of `internal` because of the more specific meaning as well as avoiding a collision with existing internal_comments attribute on Budget::Investment model (soon to be deprecated & removed)
Why: Internal valuation comments are only for admins and valuators, not for the public view. How: Adding a `not_valuations` scope and use it at the `public_for_api` one
Why: Budget Investments already has an existing `comments` relation that is on use. We need to keep that relation unaltered after adding the internal valuation comments, that means scoping the relation to only public comments (non valuation ones) so existing code using it will remain working as expected. A new second relation will be needed to explicitly ask for valuation comments only where needed, again scoping to valuation comments. How: Adding a second `valuations` relationship and filtering on both with the new `valuation` flag from Comment model.
d14548a
to
635efe1
Compare
Different implementations where evaluated: A- Copy&Paste the entire Comment feature as "Valuation". As easy and quick.. as but Brutal and Inneficient B- Using a boolean "valuation" flag attribute at & a default scope at Comment model: Makes it easy to maintain existing comments feature intact, but has a huge caveat because many implicit "where/find" over Comment model would require the explicit use of C- Using a boolean "valuation" flag and 2 explicit scopes ( D- Add another polymorphic relationship E- Create another relationship at Budget::Investment using existing commentable polymorphism and the use of a has_many :comments, -> {where(valuation: false)}, as: :commentable, class_name: 'Comment'
has_many :valuations, -> {where(valuation: true)}, as: :commentable, class_name: 'Comment' To keep |
Why: Budget Investment's valuators should be able to see internal valuation comments thread at both show and edit views. How: At Valuation::BudgetInvestmentsController: * Include CommentableActions to gain access to the entire feature, with required resource_model & resource_name methods. * Add the only possible order (oldest to newest) * Load comments on both show & edit actions, passing `valuations` flag to the CommentTree in order to only list those. At CommentTree: * Use `valuations` flag as instance variable to decide wich comment threat to load: valuations (if relation exists) or comments.
56ae198
to
7863422
Compare
How: Using a local variable at partials to set a hidden true/false value for `valuation` parameter on the comment creation form. Allowing that new param at the comment controller and using it when building a new Comment.
Why: Only admins or valuators (for those investments they've assigned) can create internal valuation comments on them. How: * Creating a new `comment_valuation` ability for admins and valuators in the same manner the `valuate` ability works. * Adding a validation at Comment model for those with `valuation` flag active that checks if the author can make a valuation comment on the commentable, as well as the respective active record error messages. This will prevent comments from being created at a controller level as well. * Improving comment factory trait `valuation` to have an associated investment, author that is a valuator and setting the valuator on the valuators list of the investment
As Budget::Investment has two relationships over commentable polymorphic relationship, the counter_cache is counting the sum of both comments and valuations. We don't show valuations count anywhere, only the (public) comments so we just use comments.count in this case
7863422
to
4ec30a9
Compare
Exquisite 😌 |
Valuation comments
Where
What
We need a comment thread on the investment valuation pages to enable replies instead of using deprecated
internal_comment
textarea by multiple users. Only adminsn and valuators assigned to an investment can create thos comments.Those comments should be internal only and not displayed to public at investment pages or apis (and that thread should not show public comments)
Voting or Flagging comments won't be needed
How
Added a
valuation
boolean attribute to Comment model, as well as an index de615a5Filtered valuation comments out from public api comments 09a6174
Created a second comment relationship named
valuations
at Budget::Investment model, and scoped existingcomments
relationship to non-valuations so everything around it won't be affected. 43c6804Added valuation comment thread to Budget Investment Valuation show & edit pages 3ca134c taking care that only objects with a
valuations
relation can get a CommentTree for those comment typesAllowed valuation comment creation at Budget Investment Valuation show & edit pages 5dd0ef0
Added a new
comment_valuation
ability to admins and valuators with the same restrictions as the currentvaluate
ability has. c87351d including a validation at Comment model to prevent creation of valuation comments without the abilityHidden voting buttons on comments at valuations thread 9c81979 as well as flagging actions d14548a
Screenshots
Public comments work as previously
Without being show at valuation page, neither valuation comments at public page
Notifications work for valuation comments
Test
Created a new Budget Investment Valuation feature under comments folder af8c9af
The scenarios have been copied from existing
/spec/features/comments/budget_investments_spec.rb
but altered to work with internal valuation comments.Apart form the "common usage" there are scenarios to:
Check only valuation comments are shown (without public comments)
A normal user cannot alter the public comment form to create a valuation comment
Create as well a
:valuation
trait for the comment factory that complies with abilities for valuators.Increased existing Budget Investment feature spec to check no valuation internal comments appear on the public pages
Added scenario to comment model spec to check public api doesn't return valuation comments
Deployment
As usual
Warnings
The next PR will remove existing usage of Budget::Invesment#internal_comments and a rake task to migrate existing values to a first comment.
A third PR that creates Valuator Groups will fulfill the
Valuator's names should be listed with their Alias and ValuatorGroup (if existent) #2362
requirement