Skip to content
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

Merged
merged 10 commits into from
Jan 31, 2018
Merged

Valuation comments #2403

merged 10 commits into from
Jan 31, 2018

Commits on Jan 30, 2018

  1. Add valuation boolean flag to Comment model

    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)
    bertocq committed Jan 30, 2018
    Configuration menu
    Copy the full SHA
    c84b2f0 View commit details
    Browse the repository at this point in the history
  2. Filter internal valuation comments from public api

    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
    bertocq committed Jan 30, 2018
    Configuration menu
    Copy the full SHA
    56fc5c9 View commit details
    Browse the repository at this point in the history
  3. Add valuation comments relation at Budget Investment

    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.
    bertocq committed Jan 30, 2018
    Configuration menu
    Copy the full SHA
    767fd04 View commit details
    Browse the repository at this point in the history

Commits on Jan 31, 2018

  1. Show valuation comment thread @ Valuation show/edit

    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.
    bertocq committed Jan 31, 2018
    Configuration menu
    Copy the full SHA
    dff966d View commit details
    Browse the repository at this point in the history
  2. Allow valuation internal comments to be created

    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.
    bertocq committed Jan 31, 2018
    Configuration menu
    Copy the full SHA
    149c813 View commit details
    Browse the repository at this point in the history
  3. Create valuation comments creation ability

    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
    bertocq committed Jan 31, 2018
    Configuration menu
    Copy the full SHA
    26cf91c View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    1c3924b View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    a4718f6 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    033c197 View commit details
    Browse the repository at this point in the history
  7. Avoid using comments_count counter_cache at 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
    bertocq committed Jan 31, 2018
    Configuration menu
    Copy the full SHA
    4ec30a9 View commit details
    Browse the repository at this point in the history