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

[TAN-3658] Add new not_reactable_status_code reason to deny reacting_idea #10197

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions back/app/controllers/web_api/v1/ideas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def index
:idea_trending_info,
:topics,
:phases,
:idea_status,
:creation_phase,
:manual_votes_last_updated_by,
{
Expand Down
1 change: 1 addition & 0 deletions back/app/models/idea_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class IdeaStatus < ApplicationRecord
CODES = %w[prescreening proposed threshold_reached expired viewed under_consideration accepted implemented rejected answered ineligible custom].freeze
LOCKED_CODES = %w[prescreening proposed threshold_reached expired].freeze
MANUAL_TRANSITION_NOT_ALLOWED_CODES = %w[prescreening threshold_reached expired].freeze
REACTING_NOT_ALLOWED_CODES = %w[prescreening expired ineligible].freeze
NON_PUBLIC_CODES = %w[prescreening].freeze

scope :for_public_posts, -> { where.not(code: NON_PUBLIC_CODES) }
Expand Down
9 changes: 7 additions & 2 deletions back/app/services/permissions/idea_permissions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class IdeaPermissionsService < ProjectPermissionsService
idea_not_in_current_phase: 'idea_not_in_current_phase',
votes_exist: 'votes_exist',
published_after_screening: 'published_after_screening',
not_author: 'not_author'
not_author: 'not_author',
not_reactable_status_code: 'not_reactable_status_code'
}.freeze

def initialize(idea, user, user_requirements_service: nil)
Expand Down Expand Up @@ -39,7 +40,11 @@ def denied_reason_for_action(action, reaction_mode: nil, delete_action: false)
# We preserved the behaviour that was already there, but we're not
# sure if this is the desired behaviour.
current_phase = @timeline_service.current_phase_not_archived project
IDEA_DENIED_REASONS[:idea_not_in_current_phase] if current_phase && !idea_in_current_phase?(current_phase)
return IDEA_DENIED_REASONS[:idea_not_in_current_phase] if current_phase && !idea_in_current_phase?(current_phase)

if action == 'reacting_idea' && IdeaStatus::REACTING_NOT_ALLOWED_CODES.include?(idea.idea_status.code)
IDEA_DENIED_REASONS[:not_reactable_status_code]
end
end
end

Expand Down
37 changes: 37 additions & 0 deletions back/spec/services/permissions/idea_permissions_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,42 @@
expect(reason).to be_nil
end

context "when idea has 'proposed' status" do
let(:proposed_status) { create(:idea_status, code: 'proposed') }
let(:input) { create(:idea, project: project, phases: [project.phases[2]], idea_status: proposed_status) }

it "does not return 'not_reactable_status_code'" do
expect(reason).to be_nil
end
end

context "when idea has 'prescreening' status" do
let(:prescreening_status) { create(:idea_status, code: 'prescreening') }
let(:input) { create(:idea, project: project, phases: [project.phases[2]], publication_status: 'submitted', idea_status: prescreening_status) }

it "returns 'not_reactable_status_code'" do
expect(reason).to eq 'not_reactable_status_code'
end
end

context "when idea has 'ineligible' status" do
let(:ineligible_status) { create(:idea_status, code: 'ineligible') }
let(:input) { create(:idea, project: project, phases: [project.phases[2]], idea_status: ineligible_status) }

it "returns 'not_reactable_status_code'" do
expect(reason).to eq 'not_reactable_status_code'
end
end

context "when idea has 'expired' status" do
let(:expired_status) { create(:idea_status, code: 'ineligible') }
let(:input) { create(:idea, project: project, phases: [project.phases[2]], idea_status: expired_status) }

it "returns 'not_reactable_status_code'" do
expect(reason).to eq 'not_reactable_status_code'
end
end

context 'when the idea is not in the current phase' do
let(:input) { create(:idea, project: project, phases: [project.phases[1]]) }

Expand Down Expand Up @@ -471,6 +507,7 @@
:idea_images, :idea_trending_info, :topics,
:idea_import,
:phases,
:idea_status,
{
project: [:admin_publication, { phases: { permissions: [:groups] } }, { custom_form: [:custom_fields] }],
author: [:unread_notifications]
Expand Down