Module: Decidim::Amendable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/decidim/amendable.rb,
app/forms/decidim/amendable/form.rb,
app/commands/decidim/amendable/accept.rb,
app/commands/decidim/amendable/reject.rb,
app/forms/decidim/amendable/edit_form.rb,
app/commands/decidim/amendable/promote.rb,
app/commands/decidim/amendable/withdraw.rb,
app/forms/decidim/amendable/create_form.rb,
app/forms/decidim/amendable/reject_form.rb,
app/forms/decidim/amendable/review_form.rb,
app/forms/decidim/amendable/promote_form.rb,
app/forms/decidim/amendable/publish_form.rb,
app/commands/decidim/amendable/create_draft.rb,
app/commands/decidim/amendable/update_draft.rb,
app/commands/decidim/amendable/destroy_draft.rb,
app/commands/decidim/amendable/publish_draft.rb,
app/cells/decidim/amendable/announcement_cell.rb,
app/cells/decidim/amendable/amenders_list_cell.rb,
app/cells/decidim/amendable/wizard_step_form_cell.rb,
app/events/decidim/amendable/amendment_base_event.rb,
app/cells/decidim/amendable/amend_button_card_cell.rb,
app/cells/decidim/amendable/emendation_actions_cell.rb,
app/cells/decidim/amendable/promote_button_card_cell.rb,
app/events/decidim/amendable/amendment_created_event.rb,
app/events/decidim/amendable/amendment_accepted_event.rb,
app/events/decidim/amendable/amendment_rejected_event.rb,
app/events/decidim/amendable/emendation_promoted_event.rb
Overview
This concern contains the logic related to amendable resources.
Defined Under Namespace
Classes: Accept, AmendButtonCardCell, AmendersListCell, AmendmentAcceptedEvent, AmendmentBaseEvent, AmendmentCreatedEvent, AmendmentRejectedEvent, AnnouncementCell, CreateDraft, CreateForm, DestroyDraft, EditForm, EmendationActionsCell, EmendationPromotedEvent, Form, Promote, PromoteButtonCardCell, PromoteForm, PublishDraft, PublishForm, Reject, RejectForm, ReviewForm, UpdateDraft, Withdraw, WizardStepFormCell
Instance Method Summary collapse
-
#add_author(author, user_group = nil) ⇒ Object
Handles the logic to assign an author to the resource, be it Authorable or Coauthorable.
-
#amendable? ⇒ Boolean
Checks if the resource CAN be amended by other resources.
-
#amendable_fields ⇒ Object
Returns the fields that can be amended.
-
#amendable_form ⇒ Object
Returns the form used for the validation and creation of the emendation.
-
#amendment ⇒ Object
Returns the polymorphic association.
-
#emendation? ⇒ Boolean
Checks if the resource HAS amended another resource.
-
#linked_promoted_resource ⇒ Object
Returns the linked resource to or from this model for the given resource name and link name.
-
#notifiable_identities ⇒ Object
Returns an Array of Decidim::User.
-
#process_amendment_state_change! ⇒ Object
Callback called when amendment state is updated.
-
#state ⇒ Object
Returns the state of the amendment or the state of the resource.
-
#visible_amendments_for(user) ⇒ Object
Returns the amendments (polymorphic association) of the emendations that are visible to the user based on the component’s amendments settings.
-
#visible_emendations_for(user) ⇒ Object
Returns the emendations of an amendable that are visible to the user based on the component’s amendments settings and filtering out the “drafts”.
Instance Method Details
#add_author(author, user_group = nil) ⇒ Object
Handles the logic to assign an author to the resource, be it Authorable or Coauthorable.
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/decidim/amendable.rb', line 151 def (, user_group = nil) if is_a?(Decidim::Authorable) if persisted? update(author: user_group || ) else self. = user_group || end else # Assume is_a?(Decidim::Coauthorable) .clear (, user_group: user_group) end end |
#amendable? ⇒ Boolean
Checks if the resource CAN be amended by other resources. Returns true or false.
110 111 112 |
# File 'lib/decidim/amendable.rb', line 110 def amendable? amendable.blank? end |
#amendable_fields ⇒ Object
Returns the fields that can be amended.
86 87 88 |
# File 'lib/decidim/amendable.rb', line 86 def amendable_fields self.class.[:fields] end |
#amendable_form ⇒ Object
Returns the form used for the validation and creation of the emendation.
91 92 93 |
# File 'lib/decidim/amendable.rb', line 91 def amendable_form self.class.[:form].constantize end |
#amendment ⇒ Object
Returns the polymorphic association.
96 97 98 99 100 |
# File 'lib/decidim/amendable.rb', line 96 def amendment associated_resource = emendation? ? :emendation : :amendable Decidim::Amendment.find_by(associated_resource => id) end |
#emendation? ⇒ Boolean
Checks if the resource HAS amended another resource. Returns true or false.
104 105 106 |
# File 'lib/decidim/amendable.rb', line 104 def emendation? amendable.present? end |
#linked_promoted_resource ⇒ Object
Returns the linked resource to or from this model for the given resource name and link name. See Decidim::Resourceable#link_resources
124 125 126 |
# File 'lib/decidim/amendable.rb', line 124 def linked_promoted_resource linked_resources(self.class, "created_from_rejected_emendation").first end |
#notifiable_identities ⇒ Object
Returns an Array of Decidim::User.
168 169 170 171 172 173 174 |
# File 'lib/decidim/amendable.rb', line 168 def notifiable_identities if is_a?(Decidim::Authorable) [] else # Assume is_a?(Decidim::Coauthorable) super end end |
#process_amendment_state_change! ⇒ Object
Callback called when amendment state is updated
165 |
# File 'lib/decidim/amendable.rb', line 165 def process_amendment_state_change!; end |
#state ⇒ Object
Returns the state of the amendment or the state of the resource.
115 116 117 118 119 |
# File 'lib/decidim/amendable.rb', line 115 def state return amendment.state if emendation? attributes["state"] end |
#visible_amendments_for(user) ⇒ Object
Returns the amendments (polymorphic association) of the emendations that are visible to the user based on the component’s amendments settings.
146 147 148 |
# File 'lib/decidim/amendable.rb', line 146 def visible_amendments_for(user) amendments.where(emendation: visible_emendations_for(user)) end |
#visible_emendations_for(user) ⇒ Object
Returns the emendations of an amendable that are visible to the user based on the component’s amendments settings and filtering out the “drafts”.
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/decidim/amendable.rb', line 130 def visible_emendations_for(user) published_emendations = emendations.published return published_emendations unless component.settings.amendments_enabled case component.current_settings.amendments_visibility when "participants" return self.class.none unless user published_emendations.where(decidim_amendments: { decidim_user_id: user.id }) else # Assume 'all' published_emendations end end |