forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Archive and unarchive debates * Add empty message * Fix erb, rb and i18norm offenses * Archive debate from debate close form * Put back accidentally removed create_debates migration * Add spec for Archive command * Add spec for archived? method in debate * Add system spec for archiving debates * Enable unarchiving from close form * Add seeds for archived debates * Change icon class when debate is closed / archived * Allow admin to archive non-official debates * Allow open debates to be archived too # Conflicts: # decidim-debates/app/views/decidim/debates/admin/debates/index.html.erb # decidim-debates/lib/decidim/debates/component.rb
- Loading branch information
1 parent
0bb15b5
commit ac37d1c
Showing
17 changed files
with
356 additions
and
60 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
decidim-debates/app/commands/decidim/debates/admin/archive_debate.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Debates | ||
module Admin | ||
# A command with all the business logic when an admin archives a debate. | ||
class ArchiveDebate < Rectify::Command | ||
# Public: Initializes the command. | ||
# | ||
# archive - Boolean, whether to archive (true) or unarchive (false) the debate. | ||
# debate - The debate object to archive. | ||
# user - The user performing the action. | ||
def initialize(archive, debate, user) | ||
@archive = archive | ||
@debate = debate | ||
@user = user | ||
end | ||
|
||
# Executes the command. Broadcasts these events: | ||
# | ||
# - :ok when the debate is valid. | ||
# - :invalid if the debate wasn't valid and we couldn't proceed. | ||
# | ||
# Returns nothing. | ||
def call | ||
archive_debate | ||
broadcast(:ok) | ||
rescue ActiveRecord::RecordInvalid | ||
broadcast(:invalid) | ||
end | ||
|
||
attr_reader :debate | ||
|
||
private | ||
|
||
def archive_debate | ||
@debate = Decidim.traceability.perform_action!( | ||
:close, | ||
@debate, | ||
@user | ||
) do | ||
@debate.update!( | ||
archived_at: @archive ? Time.zone.now : nil | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class ArchiveDebates < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :decidim_debates_debates, :archived_at, :datetime | ||
add_index :decidim_debates_debates, :archived_at | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.