models: remove creator_id from artists, notes, and pools.
Remove the creator_id field from artists, notes, and pools. The creator_id wasn't otherwise used and was inconsistent with the artist/note/pool history in some cases, especially for old artists.
This commit is contained in:
@@ -44,7 +44,7 @@ class ArtistsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@artist = Artist.create(artist_params.merge(creator: CurrentUser.user))
|
||||
@artist = Artist.create(artist_params)
|
||||
respond_with(@artist)
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class NotesController < ApplicationController
|
||||
|
||||
def index
|
||||
@notes = Note.paginated_search(params)
|
||||
@notes = @notes.includes(:creator, :post) if request.format.html?
|
||||
@notes = @notes.includes(:post) if request.format.html?
|
||||
|
||||
respond_with(@notes)
|
||||
end
|
||||
@@ -20,7 +20,7 @@ class NotesController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@note = Note.create(note_params(:create).merge(creator: CurrentUser.user))
|
||||
@note = Note.create(note_params(:create))
|
||||
respond_with(@note) do |fmt|
|
||||
fmt.json do
|
||||
if @note.errors.any?
|
||||
|
||||
@@ -18,7 +18,6 @@ class PoolsController < ApplicationController
|
||||
|
||||
def index
|
||||
@pools = Pool.paginated_search(params, count_pages: true)
|
||||
@pools = @pools.includes(:creator) if request.format.html?
|
||||
|
||||
respond_with(@pools)
|
||||
end
|
||||
@@ -40,7 +39,7 @@ class PoolsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@pool = Pool.create(pool_params.merge(creator: CurrentUser.user))
|
||||
@pool = Pool.create(pool_params)
|
||||
flash[:notice] = @pool.valid? ? "Pool created" : @pool.errors.full_messages.join("; ")
|
||||
respond_with(@pool)
|
||||
end
|
||||
|
||||
@@ -11,7 +11,6 @@ class Artist < ApplicationRecord
|
||||
after_save :clear_url_string_changed
|
||||
validate :validate_tag_category
|
||||
validates :name, tag_name: true, uniqueness: true
|
||||
belongs_to :creator, class_name: "User"
|
||||
has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name"
|
||||
has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl", :autosave => true
|
||||
has_many :versions, -> {order("artist_versions.id ASC")}, :class_name => "ArtistVersion"
|
||||
@@ -386,7 +385,7 @@ class Artist < ApplicationRecord
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
q = q.search_attributes(params, :is_active, :is_banned, :creator, :name, :group_name, :other_names)
|
||||
q = q.search_attributes(params, :is_active, :is_banned, :name, :group_name, :other_names)
|
||||
|
||||
if params[:any_other_name_like]
|
||||
q = q.any_other_name_like(params[:any_other_name_like])
|
||||
@@ -446,6 +445,6 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
[:creator, :members, :urls, :wiki_page, :tag_alias, :tag]
|
||||
[:members, :urls, :wiki_page, :tag_alias, :tag]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,6 @@ class Note < ApplicationRecord
|
||||
|
||||
attr_accessor :html_id
|
||||
belongs_to :post
|
||||
belongs_to :creator, class_name: "User"
|
||||
has_many :versions, -> {order("note_versions.id ASC")}, :class_name => "NoteVersion", :dependent => :destroy
|
||||
validates_presence_of :x, :y, :width, :height, :body
|
||||
validate :note_within_image
|
||||
@@ -19,7 +18,7 @@ class Note < ApplicationRecord
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
q = q.search_attributes(params, :creator, :post, :is_active, :x, :y, :width, :height, :body, :version)
|
||||
q = q.search_attributes(params, :post, :is_active, :x, :y, :width, :height, :body, :version)
|
||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index)
|
||||
|
||||
q.apply_default_order(params)
|
||||
@@ -123,9 +122,8 @@ class Note < ApplicationRecord
|
||||
save!
|
||||
end
|
||||
|
||||
def copy_to(new_post, creator: CurrentUser.user)
|
||||
def copy_to(new_post)
|
||||
new_note = dup
|
||||
new_note.creator = creator
|
||||
new_note.post_id = new_post.id
|
||||
new_note.version = 0
|
||||
|
||||
@@ -154,6 +152,6 @@ class Note < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
[:creator, :post]
|
||||
[:post]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,6 @@ class Pool < ApplicationRecord
|
||||
POOL_ORDER_LIMIT = 1000
|
||||
|
||||
array_attribute :post_ids, parse: /\d+/, cast: :to_i
|
||||
belongs_to :creator, class_name: "User"
|
||||
|
||||
validates_uniqueness_of :name, case_sensitive: false, if: :name_changed?
|
||||
validate :validate_name, if: :name_changed?
|
||||
@@ -53,7 +52,7 @@ class Pool < ApplicationRecord
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
q = q.search_attributes(params, :creator, :is_deleted, :name, :description, :post_ids)
|
||||
q = q.search_attributes(params, :is_deleted, :name, :description, :post_ids)
|
||||
q = q.text_attribute_matches(:description, params[:description_matches])
|
||||
|
||||
if params[:post_tags_match]
|
||||
@@ -300,8 +299,4 @@ class Pool < ApplicationRecord
|
||||
errors[:base] << "You cannot removes posts from pools within the first week of sign up"
|
||||
end
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
[:creator]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<%= search_form_for(artists_path) do |f| %>
|
||||
<%= f.input :any_name_matches, label: "Name", hint: "Use * for wildcard", input_html: { value: params[:search][:any_name_matches], data: { autocomplete: "artist" }} %>
|
||||
<%= f.input :url_matches, label: "URL", as: "string", input_html: { value: params[:search][:url_matches] } %>
|
||||
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :is_active, label: "Active?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:is_active] %>
|
||||
<%= f.input :is_banned, label: "Banned?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:is_banned] %>
|
||||
<%= f.input :has_tag, label: "Has tag?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:has_tag] %>
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% t.column "Created" do |note| %>
|
||||
<%= link_to_user note.creator %>
|
||||
<%= link_to "»", notes_path(search: { creator_name: note.creator.name }) %>
|
||||
<div><%= time_ago_in_words_tagged(note.created_at) %></div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
<%= f.hidden_field :group_by, value: "note" %>
|
||||
|
||||
<%= f.input :body_matches, label: "Body" %>
|
||||
<%= f.input :creator_name, label: "Author", input_html: { data: { autocomplete: "user" } } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
<%= f.input :name_matches, label: "Name", input_html: { value: params.dig(:search, :name_matches), "data-autocomplete": "pool" } %>
|
||||
<%= f.input :description_matches, label: "Description", input_html: { value: params.dig(:search, :description_matches) } %>
|
||||
<%= f.input :post_tags_match, label: "Post tags", input_html: { value: params.dig(:search, :post_tags_match), "data-autocomplete": "tag-query" } %>
|
||||
<%= f.input :creator_name, label: "Creator", input_html: { value: params.dig(:search, :creator_name), "data-autocomplete": "user" } %>
|
||||
<%= f.input :category, collection: %w[series collection], include_blank: true, selected: params[:search][:category] %>
|
||||
<%= f.input :order, collection: [%w[Last\ updated updated_at], %w[Name name], %w[Recently\ created created_at], %w[Post\ count post_count]], include_blank: true, selected: params.dig(:search, :order) %>
|
||||
<%= f.submit "Search" %>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class DropCreatorFromArtistsNotesPools < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
remove_index :pools, column: [:creator_id]
|
||||
remove_index :notes, column: [:creator_id, :post_id]
|
||||
|
||||
remove_column :artists, :creator_id, :integer, null: false
|
||||
remove_column :notes, :creator_id, :integer, null: false
|
||||
remove_column :pools, :creator_id, :integer, null: false
|
||||
end
|
||||
end
|
||||
@@ -594,7 +594,6 @@ ALTER SEQUENCE public.artist_versions_id_seq OWNED BY public.artist_versions.id;
|
||||
CREATE TABLE public.artists (
|
||||
id integer NOT NULL,
|
||||
name character varying NOT NULL,
|
||||
creator_id integer NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
is_banned boolean DEFAULT false NOT NULL,
|
||||
other_names text[] DEFAULT '{}'::text[] NOT NULL,
|
||||
@@ -2437,7 +2436,6 @@ ALTER SEQUENCE public.note_versions_id_seq OWNED BY public.note_versions.id;
|
||||
|
||||
CREATE TABLE public.notes (
|
||||
id integer NOT NULL,
|
||||
creator_id integer NOT NULL,
|
||||
post_id integer NOT NULL,
|
||||
x integer NOT NULL,
|
||||
y integer NOT NULL,
|
||||
@@ -2509,7 +2507,6 @@ ALTER SEQUENCE public.pixiv_ugoira_frame_data_id_seq OWNED BY public.pixiv_ugoir
|
||||
CREATE TABLE public.pools (
|
||||
id integer NOT NULL,
|
||||
name character varying,
|
||||
creator_id integer NOT NULL,
|
||||
description text,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
post_ids integer[] DEFAULT '{}'::integer[] NOT NULL,
|
||||
@@ -6512,13 +6509,6 @@ CREATE INDEX index_note_versions_on_updater_ip_addr ON public.note_versions USIN
|
||||
CREATE INDEX index_notes_on_body_index ON public.notes USING gin (body_index);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_notes_on_creator_id_and_post_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_notes_on_creator_id_and_post_id ON public.notes USING btree (creator_id, post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_notes_on_post_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -6540,13 +6530,6 @@ CREATE UNIQUE INDEX index_pixiv_ugoira_frame_data_on_post_id ON public.pixiv_ugo
|
||||
CREATE INDEX index_pools_on_category ON public.pools USING btree (category);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_pools_on_creator_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_pools_on_creator_id ON public.pools USING btree (creator_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_pools_on_is_deleted; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -7368,6 +7351,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20200118015014'),
|
||||
('20200119184442'),
|
||||
('20200119193110'),
|
||||
('20200123184743');
|
||||
('20200123184743'),
|
||||
('20200217044719');
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory(:artist) do
|
||||
creator
|
||||
name { rand(1_000_000).to_s }
|
||||
is_active { true }
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory(:note) do
|
||||
creator
|
||||
post
|
||||
x { 1 }
|
||||
y { 1 }
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory(:pool) do
|
||||
creator
|
||||
name {"pool_" + rand(100..1000099).to_s}
|
||||
description {FFaker::Lorem.sentences.join(" ")}
|
||||
end
|
||||
|
||||
@@ -524,7 +524,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
context "#new_with_defaults" do
|
||||
should "fetch the defaults from the given source" do
|
||||
source = "https://i.pximg.net/img-original/img/2018/01/28/23/56/50/67014762_p0.jpg"
|
||||
artist = Artist.new_with_defaults(source: source, creator: create(:user))
|
||||
artist = Artist.new_with_defaults(source: source)
|
||||
|
||||
assert_equal("niceandcool", artist.name)
|
||||
assert_equal("nice_and_cool", artist.other_names_string)
|
||||
|
||||
Reference in New Issue
Block a user