Skip to content

Add attachment enabled option to initiative types and initiatives#6036

Merged
microstudi merged 5 commits intodecidim:developfrom
aspgems:feature/configurable_attachments_for_initiatives
May 26, 2020
Merged

Add attachment enabled option to initiative types and initiatives#6036
microstudi merged 5 commits intodecidim:developfrom
aspgems:feature/configurable_attachments_for_initiatives

Conversation

@ace
Copy link
Copy Markdown
Contributor

@ace ace commented Apr 28, 2020

🎩 What? Why?

Allow admins to configure whether initiatives for a type will allow attachments or not.

📌 Related Issues

📋 Subtasks

  • Add CHANGELOG entry
  • Add tests

@ace ace marked this pull request as ready for review April 28, 2020 13:53
@virgile-dev
Copy link
Copy Markdown
Contributor

@carolromero you can test this on osp-decidim.dev.aspgems.com/initiatives

@carolromero
Copy link
Copy Markdown
Member

Looks good to me, thanks @virgile-dev @ace

@virgile-dev
Copy link
Copy Markdown
Contributor

@tramuntanal This is approved by product can you guys review it and see if we can merge ? Thanks in advance :)

Copy link
Copy Markdown
Contributor

@microstudi microstudi left a comment

Choose a reason for hiding this comment

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

@ace please, can you rebase develop here? thanks!

@ace
Copy link
Copy Markdown
Contributor Author

ace commented May 21, 2020

Hi @microstudi. Sure, I was 'waiting' for this, too many PRs around the same code.

@ace ace force-pushed the feature/configurable_attachments_for_initiatives branch from d9bddba to 0f95414 Compare May 21, 2020 10:51
@ace ace mentioned this pull request May 21, 2020
2 tasks
Copy link
Copy Markdown
Contributor

@microstudi microstudi left a comment

Choose a reason for hiding this comment

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

Hi @ace nice work.
I have just a very slight change for extra safety!

return unless permission_action.action == :add_attachment &&
permission_action.subject == :initiative

toggle_allow(initiative_type.attachments_enabled?)
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.

Suggested change
toggle_allow(initiative_type.attachments_enabled?)
toggle_allow(initiative_type&.attachments_enabled?)

As initiative_type might be nil, should we be extra careful here?

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.

Hi @microstudi, thanks!
I'm not sure we need that, at the point we check that attachments permission the initiative_type is required. It can be nil only in the first step of the creation wizard and we check that on the third/fourth and on edit.
Do you think it is worth adding it just in case a future change may need it?

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.

Well, I'd put it, unless we are sure that initiative_type will never be nil. In which case:

      def initiative_type
        @initiative_type ||= context.fetch(:initiative_type, nil)
      end

Shouldn't return a default nil value. Just for coherence. But you are right, it will probably never be a problem in real life.

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.

Ah, I see your point, you're right. That fetch is wrong. There should always be an initiative_type at that point. If there is not, then we have an error, there's no point in having a nil default. Thanks for pointing it out!

@virgile-dev
Copy link
Copy Markdown
Contributor

@tramuntanal this can be merged now ! Thanks in advance !

@microstudi microstudi merged commit 19300c3 into decidim:develop May 26, 2020
@ace ace deleted the feature/configurable_attachments_for_initiatives branch May 26, 2020 10:00
ace pushed a commit to aspgems/decidim that referenced this pull request May 27, 2020
* develop:
  Include year in meetings card (decidim#6102)
  Add attachment enabled option to initiative types and initiatives (decidim#6036)
  Fix a flaky test in group profile conversations (decidim#6123)
  Add attachments to Initiatives (decidim#5844)
  Add initiatives export (decidim#6070)
  Improvements to conversations with more than one participant (decidim#6094)
  Elections module and election administration (decidim#6065)
  Separate forms in steps (decidim#6108)
  Add sorting by publishing date to initiatives (decidim#6016)
  Improve proposal preview: Use proposal card when previewing a proposal draft (decidim#6064)
  Newsletter templates fixes (decidim#6096)

# Conflicts:
#	decidim-initiatives/app/models/decidim/initiative.rb
#	decidim-initiatives/spec/system/admin/initiative_types_controller_spec.rb
ace pushed a commit to aspgems/decidim that referenced this pull request May 28, 2020
* feature/add_areas_to_initiatives: (30 commits)
  Adds areas to FO filters
  Fix lint issue
  Fixes rubocop issues
  Updates changelog
  Adds areas to initiatives
  Send notification when signature threshold reached (decidim#6098)
  Adds filter by initiative type to admin panel (decidim#6093)
  Require confirmation on exiting a survey mid-answering (decidim#6118)
  Information message when there isn't any Proposal (decidim#6063)
  Set email asset host dynamically (decidim#5888)
  Harmonizes the design of initiatives search in FO (decidim#6090)
  Include year in meetings card (decidim#6102)
  Add attachment enabled option to initiative types and initiatives (decidim#6036)
  Fix a flaky test in group profile conversations (decidim#6123)
  Add attachments to Initiatives (decidim#5844)
  Add initiatives export (decidim#6070)
  Improvements to conversations with more than one participant (decidim#6094)
  Elections module and election administration (decidim#6065)
  Separate forms in steps (decidim#6108)
  Add sorting by publishing date to initiatives (decidim#6016)
  ...

# Conflicts:
#	decidim-initiatives/app/cells/decidim/initiatives/initiative_m_cell.rb
#	decidim-initiatives/app/commands/decidim/initiatives/admin/update_initiative.rb
#	decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb
#	decidim-initiatives/app/forms/decidim/initiatives/admin/initiative_form.rb
#	decidim-initiatives/app/helpers/decidim/initiatives/application_helper.rb
#	decidim-initiatives/app/models/decidim/initiative.rb
#	decidim-initiatives/app/services/decidim/initiatives/initiative_search.rb
#	decidim-initiatives/app/views/decidim/initiatives/create_initiative/fill_data.html.erb
#	decidim-initiatives/app/views/decidim/initiatives/initiatives/_filters.html.erb
#	decidim-initiatives/app/views/decidim/initiatives/initiatives/_tags.html.erb
#	decidim-initiatives/config/locales/en.yml
#	decidim-initiatives/db/migrate/20200514085422_add_area_to_initiatives.rb
#	decidim-initiatives/db/migrate/20200514102631_add_area_enabled_option_to_initiatives.rb
#	decidim-initiatives/spec/forms/initiative_form_spec.rb
#	decidim-initiatives/spec/services/decidim/initiatives/initiative_search_spec.rb
#	decidim-initiatives/spec/shared/update_initiative_type_example.rb
#	decidim-initiatives/spec/system/admin/admin_manages_initiatives_spec.rb
#	decidim-initiatives/spec/system/admin/initiative_types_controller_spec.rb
#	decidim-initiatives/spec/system/filter_initiatives_spec.rb
@virgile-dev
Copy link
Copy Markdown
Contributor

@ace it looks like your PR was conflicting with this one #5844

#5844 allows user to add a joint file in the iniative creation wizzard
image
and adds 2 buttons in the initiative admin edit from
76428029-6c8ea080-63ad-11ea-8bf6-5f9e96aca07b

There were merged about at the same time. It looks like that you anticipated this but it's not working as expected.

Testing your feature on the udpated test instance it appears that it messed with your config flag to enable and disable the possibility to add joint files.

**Bug description : **

  • Even when "Enable attachements" config is not enabled on the initiative type I can add my attachement in 2 places : the initiative creation wizard (step 4) and in the admin : the 2 buttons appear at the of the edit form and the attachement menu tab appears on the left.

Capture d’écran 2020-05-29 à 09 06 25

Capture d’écran 2020-05-29 à 09 06 34

@ace
Copy link
Copy Markdown
Contributor Author

ace commented May 29, 2020

@virgile-dev That PR you linked that I made to integrate the attachments permissions was never merged into the branch on #5844, so my fix is not added.
This is the commit avoiding the attachment on the initiative creation armandfardeau@9bb25ca
Something similar should fix the admin problem (I don't remember seeing those buttons when I did the fix, but can't be sure).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants