Skip to content

Private processes or assemblies#2618

Merged
josepjaume merged 53 commits intomasterfrom
feature/2282_private_processes_or_assemblies
Mar 15, 2018
Merged

Private processes or assemblies#2618
josepjaume merged 53 commits intomasterfrom
feature/2282_private_processes_or_assemblies

Conversation

@isaacmg410
Copy link
Copy Markdown
Contributor

@isaacmg410 isaacmg410 commented Feb 1, 2018

🎩 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

  • Add CHANGELOG entry
  • Add private space to assembly and proccess
  • Invite users by email to assembly and process
  • Show private spaces only if current_user is assigned to these space
  • Show stats only when the spaces are public
  • Rspec Test

@@ -27,7 +27,16 @@
end

feature.register_stat :results_count, primary: true, priority: Decidim::StatsRegistry::HIGH_PRIORITY do |features, _start_at, _end_at|
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isaacmg410 The HomeStats Presenter only returns features from spaces matching the public_spaces scope:

def public_participatory_spaces
@public_participatory_spaces ||= Decidim.participatory_space_manifests.flat_map do |manifest|
manifest.participatory_spaces.call(organization).public_spaces
end
end

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.

@carolromero
Copy link
Copy Markdown
Member

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.

@isaacmg410 isaacmg410 force-pushed the feature/2282_private_processes_or_assemblies branch from 9e67ab9 to 0d18580 Compare February 6, 2018 13:42
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 6, 2018

Codecov Report

Merging #2618 into master will decrease coverage by 0.02%.
The diff coverage is 96.6%.

@@            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

@isaacmg410
Copy link
Copy Markdown
Contributor Author

@decidim/lot-core do you know why codecov say this?

No coverage uploaded for pull request base (master@8387db0). Click here to learn what that means. The diff coverage is 81.39%."

@mrcasals
Copy link
Copy Markdown
Contributor

mrcasals commented Feb 7, 2018

@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.

@isaacmg410
Copy link
Copy Markdown
Contributor Author

@mrcasals also codeclimate is saying that there are similar blocks.
I have followed the same strategy as creating admin roles, but in this case codeclimate not say anything about similar blocks, how can I do that codeclimate not take into account?

@mrcasals
Copy link
Copy Markdown
Contributor

mrcasals commented Feb 7, 2018

@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 😄

@isaacmg410 isaacmg410 force-pushed the feature/2282_private_processes_or_assemblies branch 3 times, most recently from 6eb36c9 to f60ee69 Compare February 8, 2018 15:14
@isaacmg410 isaacmg410 changed the title [WIP] Feature/2282 private processes or assemblies Feature/2282 private processes or assemblies Feb 8, 2018
@isaacmg410
Copy link
Copy Markdown
Contributor Author

@decidim/lot-core ready to review. About the codeclimate issues to fix, I can't find a good way to abstract this.

@mrcasals mrcasals changed the title Feature/2282 private processes or assemblies Private processes or assemblies Feb 9, 2018

def show; end
def show
redirect_to "/404" unless (current_participatory_space.private_space? &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this to something like current_user_can_visit_space? so we encapsulate the logic? I feel this is hard to follow

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't interpolate strings here, use ? to replace the values: .where("my_field = ?", my_value)

slug
end

def private_space?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded, Rails adds this for you.

private_space
end

def self.private_space
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded

private_space
end

def self.private_space
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in assemblies

where(private_space: true)
end

def self.public_process
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in assemblies

# frozen_string_literal: true

module Decidim
# An ParticipatoryProcessPrivateUser associate user with participatory process
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🤷‍♂️

@isaacmg410 isaacmg410 force-pushed the feature/2282_private_processes_or_assemblies branch from f60ee69 to bb32814 Compare February 12, 2018 09:25
Copy link
Copy Markdown
Contributor

@josepjaume josepjaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

@isaacmg410 isaacmg410 Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what you think if the scope name will be public_and_private_participatory_processes_for, as it returns all processes for the current_user?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use the PrivateParticipatoryProcesses query here instead? It looks like it's mostly doing the same thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are querin the processes of a group of processes... I don't thins that is the same..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry! My fault.

@isaacmg410 isaacmg410 force-pushed the feature/2282_private_processes_or_assemblies branch from cda1817 to c87ca5e Compare February 13, 2018 12:12
@xabier
Copy link
Copy Markdown

xabier commented Feb 14, 2018

almost there! 😄

@isaacmg410 isaacmg410 dismissed stale reviews from mrcasals and josepjaume February 15, 2018 08:00

Requested Changes applied


def create_or_invite_user
@user ||= existing_user || new_user
@create_or_invite_user ||= existing_user || new_user
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This double assign is weird 😕

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are doing the same in @user = @user ||= existing_user || new_user in CreateAssemblyAdmin... 😕

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - I believe that's a Rubocop automated change 🤷‍♂️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, can this PR be accepted?

@isaacmg410
Copy link
Copy Markdown
Contributor Author

Can you review it and accept PR? @decidim/lot-core

mrcasals
mrcasals previously approved these changes Mar 15, 2018
oriolgual
oriolgual previously approved these changes Mar 15, 2018
@mrcasals
Copy link
Copy Markdown
Contributor

@isaacmg410 after merging #2851 some conflicts appeared, can you check them please?

@isaacmg410 isaacmg410 dismissed stale reviews from oriolgual and mrcasals via cf15bf6 March 15, 2018 09:06
@isaacmg410
Copy link
Copy Markdown
Contributor Author

@mrcasals done

Copy link
Copy Markdown
Contributor

@josepjaume josepjaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going in! 🎉🎉🎉🎉

@josepjaume josepjaume merged commit 419e3ba into master Mar 15, 2018
@josepjaume josepjaume deleted the feature/2282_private_processes_or_assemblies branch March 15, 2018 21:54
@ghost ghost removed the in-review label Mar 15, 2018
mrcasals pushed a commit that referenced this pull request Apr 2, 2019
#### 🎩 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)
![Description](URL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants