Skip to content

Commit

Permalink
Merge pull request #9016 from CitizenLabDotCo/TAN-2224/co-sponsors-si…
Browse files Browse the repository at this point in the history
…de-effects

TAN-2224 Co-sponsors side effects
  • Loading branch information
IvaKop authored Oct 7, 2024
2 parents 9f5d98d + 8358f9c commit 8509f59
Show file tree
Hide file tree
Showing 85 changed files with 1,221 additions and 22 deletions.
4 changes: 2 additions & 2 deletions back/app/controllers/web_api/v1/cosponsorships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def index
end

def accept
if @cosponsorship.status == 'pending'
if @cosponsorship.save && @cosponsorship.status == 'pending'
@cosponsorship.update(status: 'accepted')
# SideFxAcceptedCosponsorshipService.new.after_accept(@cosponsorship, current_user)
SideFxCosponsorshipService.new.after_accept(@cosponsorship, current_user)
render json: WebApi::V1::CosponsorshipSerializer.new(@cosponsorship, params: jsonapi_serializer_params).serializable_hash
else
render json: { errors: @cosponsorship.errors.details }, status: :unprocessable_entity
Expand Down
5 changes: 3 additions & 2 deletions back/app/controllers/web_api/v1/ideas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def create

def update
input = Idea.find params[:id]

authorize input

if invalid_blank_author_for_update? input, params
Expand Down Expand Up @@ -228,12 +229,12 @@ def update
end

sidefx.before_update(input, current_user)

cosponsor_ids = input.cosponsors.map(&:id)
save_options = {}
save_options[:context] = :publication if params.dig(:idea, :publication_status) == 'published'
ActiveRecord::Base.transaction do
if input.save(**save_options)
sidefx.after_update(input, current_user)
sidefx.after_update(input, current_user, cosponsor_ids)
update_file_upload_fields input, input.custom_form, update_params
render json: WebApi::V1::IdeaSerializer.new(
input.reload,
Expand Down
4 changes: 4 additions & 0 deletions back/app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand All @@ -77,6 +80,7 @@ class Notification < ApplicationRecord
belongs_to :project_folder, optional: true
belongs_to :basket, optional: true
belongs_to :cosponsors_initiative, optional: true
belongs_to :cosponsorship, optional: true

has_many :activities, as: :item

Expand Down
3 changes: 3 additions & 0 deletions back/app/models/notifications/admin_rights_received.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
3 changes: 3 additions & 0 deletions back/app/models/notifications/comment_deleted_by_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
3 changes: 3 additions & 0 deletions back/app/models/notifications/comment_marked_as_spam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
3 changes: 3 additions & 0 deletions back/app/models/notifications/comment_on_idea_you_follow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
3 changes: 3 additions & 0 deletions back/app/models/notifications/comment_on_your_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
93 changes: 93 additions & 0 deletions back/app/models/notifications/cosponsor_of_your_idea.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: notifications
#
# id :uuid not null, primary key
# type :string
# read_at :datetime
# recipient_id :uuid
# post_id :uuid
# comment_id :uuid
# project_id :uuid
# created_at :datetime not null
# updated_at :datetime not null
# initiating_user_id :uuid
# spam_report_id :uuid
# invite_id :uuid
# reason_code :string
# other_reason :string
# post_status_id :uuid
# official_feedback_id :uuid
# phase_id :uuid
# post_type :string
# post_status_type :string
# project_folder_id :uuid
# inappropriate_content_flag_id :uuid
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
# index_notifications_on_internal_comment_id (internal_comment_id)
# index_notifications_on_invite_id (invite_id)
# index_notifications_on_official_feedback_id (official_feedback_id)
# index_notifications_on_phase_id (phase_id)
# index_notifications_on_post_id_and_post_type (post_id,post_type)
# index_notifications_on_post_status_id (post_status_id)
# index_notifications_on_post_status_id_and_post_status_type (post_status_id,post_status_type)
# index_notifications_on_recipient_id (recipient_id)
# index_notifications_on_recipient_id_and_read_at (recipient_id,read_at)
# index_notifications_on_spam_report_id (spam_report_id)
#
# Foreign Keys
#
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
# fk_rails_... (invite_id => invites.id)
# fk_rails_... (official_feedback_id => official_feedbacks.id)
# fk_rails_... (phase_id => phases.id)
# fk_rails_... (project_id => projects.id)
# fk_rails_... (recipient_id => users.id)
# fk_rails_... (spam_report_id => spam_reports.id)
#
module Notifications
class CosponsorOfYourIdea < Notification
validates :initiating_user, :cosponsorship, presence: true

ACTIVITY_TRIGGERS = { 'Cosponsorship' => { 'accepted' => true } }
EVENT_NAME = 'Cosponsor has accepted your invitation to cosponsor your input'

def self.make_notifications_on(activity)
cosponsorship = activity&.item
initiating_user = activity&.user
idea = cosponsorship&.idea
recipient_id = idea&.author_id

if recipient_id && initiating_user && idea
[new(
recipient_id: recipient_id,
initiating_user: initiating_user,
cosponsorship: cosponsorship,
post: idea
)]
else
[]
end
end
end
end
3 changes: 3 additions & 0 deletions back/app/models/notifications/cosponsor_of_your_initiative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
3 changes: 3 additions & 0 deletions back/app/models/notifications/idea_marked_as_spam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
3 changes: 3 additions & 0 deletions back/app/models/notifications/initiative_assigned_to_you.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
3 changes: 3 additions & 0 deletions back/app/models/notifications/initiative_marked_as_spam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
# internal_comment_id :uuid
# basket_id :uuid
# cosponsors_initiative_id :uuid
# cosponsorship_id :uuid
#
# Indexes
#
# index_notifications_on_basket_id (basket_id)
# index_notifications_on_cosponsors_initiative_id (cosponsors_initiative_id)
# index_notifications_on_cosponsorship_id (cosponsorship_id)
# index_notifications_on_created_at (created_at)
# index_notifications_on_inappropriate_content_flag_id (inappropriate_content_flag_id)
# index_notifications_on_initiating_user_id (initiating_user_id)
Expand All @@ -52,6 +54,7 @@
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (comment_id => comments.id)
# fk_rails_... (cosponsors_initiative_id => cosponsors_initiatives.id)
# fk_rails_... (cosponsorship_id => cosponsorships.id)
# fk_rails_... (inappropriate_content_flag_id => flag_inappropriate_content_inappropriate_content_flags.id)
# fk_rails_... (initiating_user_id => users.id)
# fk_rails_... (internal_comment_id => internal_comments.id)
Expand Down
Loading

0 comments on commit 8509f59

Please sign in to comment.