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

Fixed wishlist spamming #1153

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion app/jobs/wishlist_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ def perform(domain_name, auction_remote_id)
return unless auction

wishlist_items.each do |item|
WishlistMailer.auction_notification_mail(item, auction).deliver_later
next if item.processed?

WishlistMailer.auction_notification_mail(item, auction).deliver_later(wait_until: auction.starts_at)
WishlistAutoOfferJob.set(wait_until: auction.starts_at).perform_later(auction.id)
item.update(processed: true)
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/registry/auction_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def put_same_values_as_before_for_new_round(auction)
# new_ends_at = Time.zone.now.beginning_of_day + legacy_difference_in_day.day + t
# end


ends_at_value = legacy_auction.initial_ends_at.present? ? legacy_auction.initial_ends_at : legacy_auction.ends_at

legacy_time_difference = (ends_at_value- legacy_auction.starts_at).to_i.abs
ends_at_value = legacy_auction.initial_ends_at.presence || legacy_auction.ends_at

legacy_time_difference = (ends_at_value - legacy_auction.starts_at).to_i.abs
legacy_difference_in_day = legacy_time_difference / 86_400
legacy_time = ends_at_value.strftime('%H:%M:%S')
t = Time.parse(legacy_time).seconds_since_midnight.seconds
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230927114150_add_processed_to_wishlist_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProcessedToWishlistItem < ActiveRecord::Migration[7.0]
def change
add_column :wishlist_items, :processed, :boolean, default: false
end
end
98 changes: 93 additions & 5 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,38 @@ CREATE SEQUENCE public.auctions_id_seq
ALTER SEQUENCE public.auctions_id_seq OWNED BY public.auctions.id;


--
-- Name: auto_bids; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.auto_bids (
id bigint NOT NULL,
wishlist_item_id bigint NOT NULL,
cents integer NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);


--
-- Name: auto_bids_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.auto_bids_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: auto_bids_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.auto_bids_id_seq OWNED BY public.auto_bids.id;


--
-- Name: autobiders; Type: TABLE; Schema: public; Owner: -
--
Expand All @@ -921,7 +953,7 @@ CREATE TABLE public.autobiders (
user_id bigint,
domain_name character varying,
cents integer,
uuid uuid DEFAULT gen_random_uuid(),
uuid uuid DEFAULT public.gen_random_uuid(),
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
Expand Down Expand Up @@ -1021,6 +1053,15 @@ CREATE SEQUENCE public.billing_profiles_id_seq
ALTER SEQUENCE public.billing_profiles_id_seq OWNED BY public.billing_profiles.id;


--
-- Name: data_migrations; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.data_migrations (
version character varying NOT NULL
);


--
-- Name: delayed_jobs; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1229,6 +1270,7 @@ CREATE TABLE public.invoices (
billing_address character varying DEFAULT ''::character varying NOT NULL,
billing_vat_code character varying,
billing_alpha_two_country_code character varying DEFAULT ''::character varying NOT NULL,
e_invoice_sent_at timestamp(6) without time zone,
CONSTRAINT invoices_cents_are_non_negative CHECK ((cents >= 0)),
CONSTRAINT invoices_due_date_is_not_before_issue_date CHECK ((issue_date <= due_date)),
CONSTRAINT paid_at_is_filled_when_status_is_paid CHECK ((NOT ((status = 'paid'::public.invoice_status) AND (paid_at IS NULL)))),
Expand Down Expand Up @@ -1544,6 +1586,7 @@ CREATE TABLE public.users (
uid character varying,
updated_by character varying,
daily_summary boolean DEFAULT false NOT NULL,
discarded_at timestamp without time zone,
CONSTRAINT users_roles_are_known CHECK ((roles <@ ARRAY['participant'::character varying, 'administrator'::character varying]))
);

Expand Down Expand Up @@ -1612,7 +1655,8 @@ CREATE TABLE public.wishlist_items (
uuid uuid DEFAULT public.gen_random_uuid(),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
cents integer
cents integer,
processed boolean DEFAULT false
);


Expand Down Expand Up @@ -1726,6 +1770,13 @@ ALTER TABLE ONLY audit.wishlist_items ALTER COLUMN id SET DEFAULT nextval('audit
ALTER TABLE ONLY public.auctions ALTER COLUMN id SET DEFAULT nextval('public.auctions_id_seq'::regclass);


--
-- Name: auto_bids id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.auto_bids ALTER COLUMN id SET DEFAULT nextval('public.auto_bids_id_seq'::regclass);


--
-- Name: autobiders id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2027,6 +2078,14 @@ ALTER TABLE ONLY public.ar_internal_metadata
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);


--
-- Name: auto_bids auto_bids_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.auto_bids
ADD CONSTRAINT auto_bids_pkey PRIMARY KEY (id);


--
-- Name: autobiders autobiders_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand All @@ -2051,6 +2110,14 @@ ALTER TABLE ONLY public.billing_profiles
ADD CONSTRAINT billing_profiles_pkey PRIMARY KEY (id);


--
-- Name: data_migrations data_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.data_migrations
ADD CONSTRAINT data_migrations_pkey PRIMARY KEY (version);


--
-- Name: delayed_jobs delayed_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2375,6 +2442,13 @@ CREATE UNIQUE INDEX index_auctions_on_remote_id ON public.auctions USING btree (
CREATE UNIQUE INDEX index_auctions_on_uuid ON public.auctions USING btree (uuid);


--
-- Name: index_auto_bids_on_wishlist_item_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_auto_bids_on_wishlist_item_id ON public.auto_bids USING btree (wishlist_item_id);


--
-- Name: index_autobiders_on_domain_name; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2696,7 +2770,6 @@ CREATE INDEX index_wishlist_items_on_domain_name ON public.wishlist_items USING

CREATE UNIQUE INDEX users_by_identity_code_and_country ON public.users USING btree (alpha_two_country_code, identity_code) WHERE ((alpha_two_country_code)::text = 'EE'::text);


--
-- Name: auctions process_auction_audit; Type: TRIGGER; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2780,7 +2853,6 @@ CREATE TRIGGER process_user_audit AFTER INSERT OR DELETE OR UPDATE ON public.use

CREATE TRIGGER process_wishlist_item_audit AFTER INSERT OR DELETE OR UPDATE ON public.wishlist_items FOR EACH ROW EXECUTE FUNCTION public.process_wishlist_item_audit();


--
-- Name: bans fk_rails_070022cd76; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2813,6 +2885,14 @@ ALTER TABLE ONLY public.autobiders
ADD CONSTRAINT fk_rails_3d4f798ed7 FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- Name: auto_bids fk_rails_473d19add3; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.auto_bids
ADD CONSTRAINT fk_rails_473d19add3 FOREIGN KEY (wishlist_item_id) REFERENCES public.wishlist_items(id);


--
-- Name: wishlist_items fk_rails_5c10acf6bc; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -3006,11 +3086,14 @@ INSERT INTO "schema_migrations" (version) VALUES
('20191025092912'),
('20191028092316'),
('20191121162323'),
('20191129102035'),
('20191206123023'),
('20191209073454'),
('20191209083000'),
('20191209085222'),
('20191213082941'),
('20191220131845'),
('20200109093043'),
('20200110135003'),
('20200115145246'),
('20200205092158'),
Expand All @@ -3022,6 +3105,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220422094307'),
('20220422094556'),
('20220422095751'),
('20220422121056'),
('20220425103701'),
('20220426082102'),
('20220527064738'),
Expand All @@ -3038,5 +3122,9 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230227085236'),
('20230309094132'),
('20230419114412'),
('20230607092953'),
('20230705192353'),
('20230607092953');
('20230925130405'),
('20230927114150');


11 changes: 8 additions & 3 deletions test/jobs/wishlist_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ def teardown
clear_email_deliveries
end

def test_it_sends_emails_when_there_is_a_wishlist_item
def test_it_sends_emails_and_only_once_when_there_is_a_wishlist_item
WishlistItem.create!(user: @user, domain_name: @auction.domain_name)

assert_enqueued_emails(1) do
WishlistJob.perform_now(@auction.domain_name, @auction.remote_id)
WishlistJob.perform_now(@auction.domain_name, @auction.remote_id)
end
end

Expand Down Expand Up @@ -60,9 +61,13 @@ def test_wait_time
end
end

def test_schedulle_auto_offer_job_when_there_is_a_wishlist_item
def test_schedules_auto_offer_job_and_only_once_when_there_is_a_wishlist_item
WishlistItem.create!(user: @user, domain_name: @auction.domain_name)
WishlistJob.perform_now(@auction.domain_name, @auction.remote_id)

assert_enqueued_jobs 1, only: WishlistAutoOfferJob do
WishlistJob.perform_now(@auction.domain_name, @auction.remote_id)
WishlistJob.perform_now(@auction.domain_name, @auction.remote_id)
end

assert_enqueued_with(job: WishlistAutoOfferJob, args: [@auction.id], at: @auction.starts_at)
end
Expand Down
3 changes: 2 additions & 1 deletion test/models/registry/auction_creator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def test_call_creates_auctions_that_end_at_the_end_of_day
assert_equal(Time.now.in_time_zone + 1.minute, example_auction.starts_at)
assert_equal((Date.tomorrow.to_datetime - 1.second), example_auction.ends_at)
end
end end
end
end

def test_call_creates_auctions_that_start_in_1_minute
setting = settings(:auctions_start_at)
Expand Down