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:
evazion
2020-02-16 23:02:23 -06:00
parent 207861fd40
commit 2dab9aa075
16 changed files with 23 additions and 46 deletions

View File

@@ -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

View File

@@ -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?

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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] %>

View File

@@ -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 %>

View File

@@ -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 %>

View File

@@ -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" %>