[UserFeedback] Add Updater

This commit is contained in:
Donovan Daniels 2024-01-04 14:31:54 -06:00
parent acae76a907
commit c11ad6b874
No known key found for this signature in database
GPG Key ID: 907D29CBFD6157BA
4 changed files with 41 additions and 6 deletions

View File

@ -2,6 +2,7 @@ class UserFeedback < ApplicationRecord
self.table_name = "user_feedback"
belongs_to :user
belongs_to_creator
belongs_to_updater
validates :body, :category, presence: true
validates :category, inclusion: { in: %w[positive negative neutral] }
validates :body, length: { minimum: 1, maximum: Danbooru.config.user_feedback_max_size }
@ -75,7 +76,7 @@ class UserFeedback < ApplicationRecord
return unless should_send
action = saved_change_to_id? ? "created" : "updated"
body = %(#{creator_name} #{action} a "#{category} record":/user_feedbacks?search[user_id]=#{user_id} for your account:\n\n#{self.body})
body = %(#{updater_name} #{action} a "#{category} record":/user_feedbacks?search[user_id]=#{user_id} for your account:\n\n#{self.body})
Dmail.create_automated(to_id: user_id, title: "Your user record has been updated", body: body)
end

View File

@ -0,0 +1,6 @@
class UserFeedbackAddUpdaterId < ActiveRecord::Migration[7.0]
def change
add_column :user_feedback, :updater_id, :integer
add_foreign_key :user_feedback, :users, column: :updater_id
end
end

View File

@ -2096,7 +2096,8 @@ CREATE TABLE public.user_feedback (
body text NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_ip_addr inet
creator_ip_addr inet,
updater_id integer
);
@ -4437,6 +4438,14 @@ ALTER TABLE ONLY public.tickets
ADD CONSTRAINT fk_rails_45cd696dba FOREIGN KEY (accused_id) REFERENCES public.users(id);
--
-- Name: user_feedback fk_rails_9329a36823; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.user_feedback
ADD CONSTRAINT fk_rails_9329a36823 FOREIGN KEY (updater_id) REFERENCES public.users(id);
--
-- Name: mascots fk_rails_9901e810fa; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -4743,6 +4752,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230513074838'),
('20230517155547'),
('20230518182034'),
('20230531080817');
('20230531080817'),
('20240101042716');

View File

@ -5,18 +5,36 @@ class UserFeedbackTest < ActiveSupport::TestCase
setup do
@user = create(:user)
@mod = create(:moderator_user)
@admin = create(:admin_user)
CurrentUser.user = @mod
end
should "create a dmail" do
dmail = <<~EOS.chomp
dmail = <<~DMAIL.chomp
#{@mod.name} created a "positive record":/user_feedbacks?search[user_id]=#{@user.id} for your account:
good job!
EOS
DMAIL
assert_difference("Dmail.count", 1) do
create(:user_feedback, user: @user, body: "good job!")
assert_equal(dmail, @user.dmails.last.body)
assert_equal(dmail, @user.dmails.first.body)
end
end
should "correctly credit the updater" do
feedback = create(:user_feedback, user: @user, body: "good job!")
dmail = <<~DMAIL.chomp
#{@admin.name} updated a "positive record":/user_feedbacks?search[user_id]=#{@user.id} for your account:
great job!
DMAIL
assert_difference("Dmail.count", 1) do
CurrentUser.scoped(@admin) do
feedback.update(body: "great job!", send_update_dmail: true)
end
assert_equal(dmail, @user.dmails.first.body)
end
end