Conversation
| @@ -27,7 +27,16 @@ | |||
| end | |||
|
|
|||
| feature.register_stat :results_count, primary: true, priority: Decidim::StatsRegistry::HIGH_PRIORITY do |features, _start_at, _end_at| | |||
There was a problem hiding this comment.
Is there any way to filter these features, depending on the participatory_space is private or public? I'm using the query below because I have not found any other way, but I think it's not the most optimal way .. @decidim/lot-core, any idea?
There was a problem hiding this comment.
@isaacmg410 The HomeStats Presenter only returns features from spaces matching the public_spaces scope:
decidim/decidim-core/app/presenters/decidim/home_stats_presenter.rb
Lines 77 to 81 in 1d57472
You need to modify this scope in each space to return only those that are public. I would not change this result depending on the user, so I would only return those spaces that are public for everyone.
|
Hi! For not having staled PRs on @decidim/product we're gonna change the policy for merging this kind of issues: let's merge it and not have a bottleneck with design (cc/ @decidim/lot-px). When the design for this kind of issues is ready, then we'll open a new PR with only design changes. We're afraid that if we let the time pass only for design it'd be much more difficult to merge given our current pace. |
9e67ab9 to
0d18580
Compare
Codecov Report
@@ Coverage Diff @@
## master #2618 +/- ##
==========================================
- Coverage 98.69% 98.66% -0.03%
==========================================
Files 1674 1692 +18
Lines 39871 40329 +458
==========================================
+ Hits 39349 39791 +442
- Misses 522 538 +16 |
|
@decidim/lot-core do you know why codecov say this?
|
|
@isaacmg410 it's because tests are failing, and coverage is calculated after the tests are run. Please fix the tests (and the conflicts), and once the suite is green Codecov will update its comment accordingly. |
|
@mrcasals also codeclimate is saying that there are similar blocks. |
|
@isaacmg410 if you can't find a good way to abstract this, then I say we can ignore these warnings. There's one of them that can be fixed automatically though 😄 |
6eb36c9 to
f60ee69
Compare
|
@decidim/lot-core ready to review. About the codeclimate issues to fix, I can't find a good way to abstract this. |
|
|
||
| def show; end | ||
| def show | ||
| redirect_to "/404" unless (current_participatory_space.private_space? && |
There was a problem hiding this comment.
can you move this to something like current_user_can_visit_space? so we encapsulate the logic? I feel this is hard to follow
There was a problem hiding this comment.
Is this returning a 404 Not Found HTTP status? I think we should.
| joins("LEFT JOIN decidim_assembly_private_users ON | ||
| decidim_assembly_private_users.decidim_assembly_id = decidim_assemblies.id") | ||
| .where("(private_space = true and decidim_assembly_private_users.decidim_user_id | ||
| = #{user} ) or private_space = false") |
There was a problem hiding this comment.
Don't interpolate strings here, use ? to replace the values: .where("my_field = ?", my_value)
| slug | ||
| end | ||
|
|
||
| def private_space? |
There was a problem hiding this comment.
Unneeded, Rails adds this for you.
| private_space | ||
| end | ||
|
|
||
| def self.private_space |
There was a problem hiding this comment.
def private_assemblies maybe? So it doesn't clash with meaning with Decidim::Participable.public_spaces...
| where(private_space: true) | ||
| end | ||
|
|
||
| def self.public_assembly |
There was a problem hiding this comment.
def public_assemblies, maybe? Although this might clash in meaning with Decidim::Participable.public_spaces...
Maybe something like def non_private_assemblies?
| slug | ||
| end | ||
|
|
||
| def private_space? |
| private_space | ||
| end | ||
|
|
||
| def self.private_space |
| where(private_space: true) | ||
| end | ||
|
|
||
| def self.public_process |
| # frozen_string_literal: true | ||
|
|
||
| module Decidim | ||
| # An ParticipatoryProcessPrivateUser associate user with participatory process |
There was a problem hiding this comment.
Can you improve the docs? Reading this I don't understand why this class is used. Saying something like: "this class gives a given User access to a given private Process", or something like this, would be good.
Same for assemblies.
| success: Participatory process group updated successfully. | ||
| participatory_process_private_users: | ||
| destroy: | ||
| success: Participatory process private user destroyed successfully. |
There was a problem hiding this comment.
I think this naming might be confusing for the end user. What about something like: "Private Process User Access"? Would this be clearer?
In case of doubt refer to @decidim/product 🤷♂️
f60ee69 to
bb32814
Compare
josepjaume
left a comment
There was a problem hiding this comment.
Really good work! I posted some comments regarding some naming/design details I think could be improved. Some involve a bit of a refactoring over existing code, others are just a matter of separating concerns.
Sorry to be so nitpicky, but both processes and assemblies are central constructs of the project and are both gonna be used as an example for further development, so we need to put extra care in naming, conventions, etc.
But as I said, good work! This wasn't a trivial task to solve 👍
| scope :upcoming, -> { where(arel_table[:start_date].gt(Time.current)) } | ||
| scope :active, -> { where(arel_table[:start_date].lteq(Time.current).and(arel_table[:end_date].gt(Time.current).or(arel_table[:end_date].eq(nil)))) } | ||
|
|
||
| scope :private_spaces_user, lambda { |user| |
There was a problem hiding this comment.
Since we're implementing this both in assemblies and participatory_processes, i'd scope the method name to something more specific, for readability purposes. private_participatory_processes_for and private_assemblies_for looks better to me. Same thing for assemblies. Otherwise the next developer might think there's a common abstraction - which there isn't.
I'm also not sure wether we should be returning all the public assemblies/processes as well. Looking at the method's name, one might expect for it to return only the private spaces for that user.
There was a problem hiding this comment.
what you think if the scope name will be public_and_private_participatory_processes_for, as it returns all processes for the current_user?
There was a problem hiding this comment.
What about just returning the private ones instead and dealing with that at the Queries down below? In case not, what about visible_participatory_processes_for?
| module Decidim | ||
| module Assemblies | ||
| # This query class filters assemblies given a current_user. | ||
| class PrivateAssemblies < Rectify::Query |
There was a problem hiding this comment.
I've struggled a bit to understand what this class actually does. It looks like instead of returning PrivateAssemblies, it actually returns VisibleAssemblies right? If a user is provided, it will scope them to all the assemblies the user can see. Otherwise, it will return all the public assemblies.
| where(private_space: true) | ||
| end | ||
|
|
||
| def self.non_private_assemblies |
There was a problem hiding this comment.
This class already extends Participable, which includes some functionality to figure out public spaces, as a means to provide statistics on the home page and other places. We probably should be using that instead (probably overriding it for the assemblies and processes case):
https://github.com/decidim/decidim/blob/master/decidim-core/lib/decidim/participable.rb#L82
Otherwise, data from private spaces might leak to statistics.
There was a problem hiding this comment.
If I didn't go wrong. It was said that statistics would not take into account private processes, no?
| where(private_space: true) | ||
| end | ||
|
|
||
| def self.non_private_processes |
There was a problem hiding this comment.
Same as in assemblies: We should probably be extending this instead: https://github.com/decidim/decidim/blob/master/decidim-core/lib/decidim/participable.rb#L82
| module Decidim | ||
| module ParticipatoryProcesses | ||
| # This query class filters participatory processes given a current_user. | ||
| class PrivateParticipatoryProcesses < Rectify::Query |
There was a problem hiding this comment.
Same concerns as in PrivateAssemblies, please check them out 👍
| def participatory_processes | ||
| @participatory_processes ||= group.participatory_processes.published | ||
| @participatory_processes ||= if current_user | ||
| group.participatory_processes.private_spaces_user(current_user.id).published |
There was a problem hiding this comment.
Maybe we could use the PrivateParticipatoryProcesses query here instead? It looks like it's mostly doing the same thing.
There was a problem hiding this comment.
We are querin the processes of a group of processes... I don't thins that is the same..
cda1817 to
c87ca5e
Compare
|
almost there! 😄 |
Requested Changes applied
|
|
||
| def create_or_invite_user | ||
| @user ||= existing_user || new_user | ||
| @create_or_invite_user ||= existing_user || new_user |
There was a problem hiding this comment.
This seems to be copied from another command. The @user variable was set here so that the attr_reader works. Now the user method returns nil since this change.
There was a problem hiding this comment.
@mrcasals then how can we solve this ? Naming/MemoizedInstanceVariableName: Memoized variable @user does not match method name create_or_invite_user. Use @ create_or_invite_user instead.
There was a problem hiding this comment.
Make the method be called def user and remove the attr_reader
|
|
||
| ActiveRecord::Base.transaction do | ||
| create_or_invite_user | ||
| @user = @user ||= existing_user || new_user |
There was a problem hiding this comment.
This double assign is weird 😕
There was a problem hiding this comment.
you are doing the same in @user = @user ||= existing_user || new_user in CreateAssemblyAdmin... 😕
There was a problem hiding this comment.
And it's being discussed in the PR that added it. Might be some weird Rubocop change, but it's still weird and non-idiomatic. Can you change it, please? 😄
There was a problem hiding this comment.
Sorry - I believe that's a Rubocop automated change 🤷♂️
There was a problem hiding this comment.
So, can this PR be accepted?
|
Can you review it and accept PR? @decidim/lot-core |
|
@isaacmg410 after merging #2851 some conflicts appeared, can you check them please? |
|
@mrcasals done |
#### 🎩 What? Why? This PR fixes that as a normal user (no private user) I can comment on a private assembly where is available. Meetigns, Proposals, etc. #### 📌 Related Issues - Related to #2618 #3438 - Fixes #4869 #### 📋 Subtasks - [x] Add `CHANGELOG` entry - [x] Add tests ### 📷 Screenshots (optional) 
🎩 What? Why?
This PR adds the functionality of making a participatory space private and make it visible only for a series of users selected. Users are invited by sending an email.
📌 Related Issues
📋 Subtasks
CHANGELOGentry