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/cells/decidim/amendable/amendments_cell.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/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, AmendmentAcceptedEvent, AmendmentBaseEvent, AmendmentCreatedEvent, AmendmentRejectedEvent, AmendmentsCell, 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.
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/decidim/amendable.rb', line 150 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:) end end |
#amendable? ⇒ Boolean
Checks if the resource CAN be amended by other resources. Returns true or false.
109 110 111 |
# File 'lib/decidim/amendable.rb', line 109 def amendable? amendable.blank? end |
#amendable_fields ⇒ Object
Returns the fields that can be amended.
85 86 87 |
# File 'lib/decidim/amendable.rb', line 85 def amendable_fields self.class.[:fields] end |
#amendable_form ⇒ Object
Returns the form used for the validation and creation of the emendation.
90 91 92 |
# File 'lib/decidim/amendable.rb', line 90 def amendable_form self.class.[:form].constantize end |
#amendment ⇒ Object
Returns the polymorphic association.
95 96 97 98 99 |
# File 'lib/decidim/amendable.rb', line 95 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.
103 104 105 |
# File 'lib/decidim/amendable.rb', line 103 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
123 124 125 |
# File 'lib/decidim/amendable.rb', line 123 def linked_promoted_resource linked_resources(self.class, "created_from_rejected_emendation").first end |
#notifiable_identities ⇒ Object
Returns an Array of Decidim::User.
167 168 169 170 171 172 173 |
# File 'lib/decidim/amendable.rb', line 167 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
164 |
# File 'lib/decidim/amendable.rb', line 164 def process_amendment_state_change!; end |
#state ⇒ Object
Returns the state of the amendment or the state of the resource.
114 115 116 117 118 |
# File 'lib/decidim/amendable.rb', line 114 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.
145 146 147 |
# File 'lib/decidim/amendable.rb', line 145 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”.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/decidim/amendable.rb', line 129 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 |