From 28f04eb1b2434eaab709c949f8b6ae3f3c388fa5 Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 29 Mar 2013 20:18:03 -0400 Subject: [PATCH 1/7] adds commenter: and noter: metatags --- app/logical/post_query_builder.rb | 10 ++++++++++ app/models/tag.rb | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index 8fff27df7..f3a67b588 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -189,6 +189,16 @@ class PostQueryBuilder has_constraints! end + if q[:commenter_id] + relation = relation.where(:id => Comment.where("creator_id = ?", q[:commenter_id]).select("post_id").uniq) + has_constraints! + end + + if q[:noter_id] + relation = relation.where(:id => Note.where("creator_id = ?", q[:noter_id]).select("post_id").uniq) + has_constraints! + end + if q[:parent_id] relation = relation.where("(posts.id = ? or posts.parent_id = ?)", q[:parent_id], q[:parent_id]) has_constraints! diff --git a/app/models/tag.rb b/app/models/tag.rb index eb8698e87..4856e143c 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,5 +1,5 @@ class Tag < ActiveRecord::Base - METATAGS = "-user|user|-approver|approver|-pool|pool|-fav|fav|sub|md5|-rating|rating|width|height|mpixels|score|filesize|source|id|date|order|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|pixiv" + METATAGS = "-user|user|-approver|approver|commenter|noter|-pool|pool|-fav|fav|sub|md5|-rating|rating|width|height|mpixels|score|filesize|source|id|date|order|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|pixiv" attr_accessible :category has_one :wiki_page, :foreign_key => "name", :primary_key => "title" @@ -280,6 +280,14 @@ class Tag < ActiveRecord::Base q[:approver_id] = User.name_to_id($2) q[:approver_id] = -1 if q[:approver_id].nil? + when "commenter" + q[:commenter_id] = User.name_to_id($2) + q[:commenter_id] = -1 if q[:commenter_id].nil? + + when "noter" + q[:noter_id] = User.name_to_id($2) + q[:noter_id] = -1 if q[:noter_id].nil? + when "-pool" q[:tags][:exclude] << "pool:#{Pool.name_to_id($2)}" From fc83cd5fd3811de3d847beaecad12be2f63ab845 Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 29 Mar 2013 20:19:46 -0400 Subject: [PATCH 2/7] adds comm shortcut for comment metatags --- app/logical/post_query_builder.rb | 4 ++-- app/models/tag.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index f3a67b588..dd5a2f350 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -245,10 +245,10 @@ class PostQueryBuilder when "favcount_asc" relation = relation.order("posts.fav_count ASC, posts.id DESC") - when "comment" + when "comment", "comm" relation = relation.order("posts.last_commented_at DESC, posts.id DESC").where("posts.last_commented_at is not null") - when "comment_asc" + when "comment_asc", "comm_asc" relation = relation.order("posts.last_commented_at ASC, posts.id DESC").where("posts.last_commented_at is not null") when "note" diff --git a/app/models/tag.rb b/app/models/tag.rb index 4856e143c..ef23c739f 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,5 +1,5 @@ class Tag < ActiveRecord::Base - METATAGS = "-user|user|-approver|approver|commenter|noter|-pool|pool|-fav|fav|sub|md5|-rating|rating|width|height|mpixels|score|filesize|source|id|date|order|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|pixiv" + METATAGS = "-user|user|-approver|approver|commenter|comm|noter|-pool|pool|-fav|fav|sub|md5|-rating|rating|width|height|mpixels|score|filesize|source|id|date|order|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|pixiv" attr_accessible :category has_one :wiki_page, :foreign_key => "name", :primary_key => "title" @@ -280,7 +280,7 @@ class Tag < ActiveRecord::Base q[:approver_id] = User.name_to_id($2) q[:approver_id] = -1 if q[:approver_id].nil? - when "commenter" + when "commenter", "comm" q[:commenter_id] = User.name_to_id($2) q[:commenter_id] = -1 if q[:commenter_id].nil? From 5bdcc8c4966599f0415ee670dc656e4c8bbf1b6e Mon Sep 17 00:00:00 2001 From: ToksT Date: Sat, 30 Mar 2013 01:50:52 -0300 Subject: [PATCH 3/7] remove unnecessary uniqs --- app/logical/post_query_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index dd5a2f350..0984763fd 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -190,12 +190,12 @@ class PostQueryBuilder end if q[:commenter_id] - relation = relation.where(:id => Comment.where("creator_id = ?", q[:commenter_id]).select("post_id").uniq) + relation = relation.where(:id => Comment.where("creator_id = ?", q[:commenter_id]).select("post_id")) has_constraints! end if q[:noter_id] - relation = relation.where(:id => Note.where("creator_id = ?", q[:noter_id]).select("post_id").uniq) + relation = relation.where(:id => Note.where("creator_id = ?", q[:noter_id]).select("post_id")) has_constraints! end From a192287431771adaee0eb7e712bfaedb6267b62c Mon Sep 17 00:00:00 2001 From: ToksT Date: Sat, 30 Mar 2013 09:32:53 -0300 Subject: [PATCH 4/7] revert --- app/logical/post_query_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index 0984763fd..dd5a2f350 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -190,12 +190,12 @@ class PostQueryBuilder end if q[:commenter_id] - relation = relation.where(:id => Comment.where("creator_id = ?", q[:commenter_id]).select("post_id")) + relation = relation.where(:id => Comment.where("creator_id = ?", q[:commenter_id]).select("post_id").uniq) has_constraints! end if q[:noter_id] - relation = relation.where(:id => Note.where("creator_id = ?", q[:noter_id]).select("post_id")) + relation = relation.where(:id => Note.where("creator_id = ?", q[:noter_id]).select("post_id").uniq) has_constraints! end From 2dd21e03670c34701e047a29431b1464485bbbf1 Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 29 Mar 2013 23:57:49 -0400 Subject: [PATCH 5/7] adds basic support for user level-dependent classes --- app/models/user.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index a509c2c90..3a4bd0f17 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -355,6 +355,10 @@ class User < ActiveRecord::Base return true end + + def level_class + "user-#{level_string.downcase}" + end end module EmailMethods From eed6ece3ec7f7dda009795878fbc029de3a047cd Mon Sep 17 00:00:00 2001 From: Toks Date: Sat, 30 Mar 2013 10:22:40 -0400 Subject: [PATCH 6/7] adds missing updaters to forum posts, comments, and artist versions --- app/models/artist_version.rb | 2 +- app/models/comment.rb | 1 + app/models/forum_post.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/artist_version.rb b/app/models/artist_version.rb index 3677675e6..0bd3b40a3 100644 --- a/app/models/artist_version.rb +++ b/app/models/artist_version.rb @@ -1,5 +1,5 @@ class ArtistVersion < ActiveRecord::Base - belongs_to :updater + belongs_to :updater, :class_name => "User" belongs_to :artist def self.search(params) diff --git a/app/models/comment.rb b/app/models/comment.rb index 604bcd6f5..6c4fd6faa 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,6 +3,7 @@ class Comment < ActiveRecord::Base validates_format_of :body, :with => /\S/, :message => 'has no content' belongs_to :post belongs_to :creator, :class_name => "User" + belongs_to :updater, :class_name => "User" has_many :votes, :class_name => "CommentVote", :dependent => :destroy before_validation :initialize_creator, :on => :create before_validation :initialize_updater diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 0a239d6ce..32f5dd964 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -2,6 +2,7 @@ class ForumPost < ActiveRecord::Base attr_accessible :body, :topic_id, :as => [:member, :builder, :janitor, :privileged, :platinum, :contributor, :admin, :moderator, :default] attr_accessible :is_locked, :is_sticky, :is_deleted, :as => [:admin, :moderator, :janitor] belongs_to :creator, :class_name => "User" + belongs_to :updater, :class_name => "User" belongs_to :topic, :class_name => "ForumTopic" before_validation :initialize_creator, :on => :create before_validation :initialize_updater From 4f42ab8bdb6186d1018045bc4a5889abdaf7332c Mon Sep 17 00:00:00 2001 From: Toks Date: Sat, 30 Mar 2013 10:31:20 -0400 Subject: [PATCH 7/7] adds support for user level-dependent classes all links to users should have their class attribute set to that user's level_class --- app/presenters/user_presenter.rb | 2 +- app/views/artist_versions/index.html.erb | 2 +- app/views/comments/partials/show/_comment.html.erb | 4 ++-- app/views/dmails/index.html.erb | 4 ++-- app/views/dmails/show.html.erb | 4 ++-- app/views/forum_posts/_forum_post.html.erb | 4 ++-- app/views/forum_topics/index.html.erb | 4 ++-- app/views/mod_actions/index.html.erb | 2 +- app/views/note_versions/index.html.erb | 2 +- app/views/notes/index_by_note.html.erb | 2 +- app/views/pool_versions/index.html.erb | 2 +- app/views/pools/index.html.erb | 2 +- app/views/posts/partials/show/_information.html.erb | 4 ++-- app/views/user_feedbacks/index.html.erb | 4 ++-- app/views/users/index.html.erb | 4 ++-- app/views/wiki_page_versions/index.html.erb | 2 +- 16 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index b626914e5..788fd982a 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -105,7 +105,7 @@ class UserPresenter def inviter(template) if user.inviter_id - template.link_to(user.inviter.name, template.user_path(user.inviter_id)) + template.link_to(user.inviter.name, template.user_path(user.inviter_id), { :class => user.inviter.level_class }) else "None" end diff --git a/app/views/artist_versions/index.html.erb b/app/views/artist_versions/index.html.erb index 762b5fb52..ec2b72bf2 100644 --- a/app/views/artist_versions/index.html.erb +++ b/app/views/artist_versions/index.html.erb @@ -27,7 +27,7 @@ <%= artist_version_other_names_diff(artist_version) %> <%= artist_version.group_name %> <%= compact_time artist_version.created_at %> - <%= link_to artist_version.updater_name, user_path(artist_version.updater_id) %> + <%= link_to artist_version.updater_name, user_path(artist_version.updater_id), { :class => artist_version.updater.level_class } %> <%= artist_version.is_active? %>
    diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index be178e30e..5296df968 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -1,6 +1,6 @@
    -

    <%= link_to comment.creator_name, user_path(comment.creator_id) %>

    +

    <%= link_to comment.creator_name, user_path(comment.creator_id), { :class => comment.creator.level_class } %>

    <%= time_ago_in_words_tagged(comment.created_at) %>

    @@ -10,7 +10,7 @@ <%= format_text(comment.body) %> <% if comment.updater_id.present? && (comment.updater_id != comment.creator_id || comment.created_at != comment.updated_at) %> -

    Updated by <%= link_to comment.updater_name, user_path(comment.updater_id) %> <%= time_ago_in_words_tagged(comment.updated_at) %>

    +

    Updated by <%= link_to comment.updater_name, user_path(comment.updater_id), { :class => comment.updater.level_class } %> <%= time_ago_in_words_tagged(comment.updated_at) %>

    <% end %>
    diff --git a/app/views/dmails/index.html.erb b/app/views/dmails/index.html.erb index b6b29e41e..e6c495bd2 100644 --- a/app/views/dmails/index.html.erb +++ b/app/views/dmails/index.html.erb @@ -21,8 +21,8 @@ <% @dmails.each do |dmail| %> <%= compact_time(dmail.created_at) %> - <%= link_to dmail.from_name, user_path(dmail.from) %> - <%= link_to dmail.to_name, user_path(dmail.to) %> + <%= link_to dmail.from_name, user_path(dmail.from), { :class => dmail.from.level_class } %> + <%= link_to dmail.to_name, user_path(dmail.to), { :class => dmail.to.level_class } %> <%= link_to dmail.title, dmail_path(dmail) %> <% end %> diff --git a/app/views/dmails/show.html.erb b/app/views/dmails/show.html.erb index 726ba99c4..48cffab63 100644 --- a/app/views/dmails/show.html.erb +++ b/app/views/dmails/show.html.erb @@ -5,8 +5,8 @@

    <%= @dmail.title %>

      -
    • Sender: <%= link_to @dmail.from_name, user_path(@dmail.from_id) %>
    • -
    • Recipient: <%= link_to @dmail.to_name, user_path(@dmail.to_id) %>
    • +
    • Sender: <%= link_to @dmail.from_name, user_path(@dmail.from_id), { :class => @dmail.from.level_class } %>
    • +
    • Recipient: <%= link_to @dmail.to_name, user_path(@dmail.to_id), { :class => @dmail.to.level_class } %>
    • Date: <%= compact_time(@dmail.created_at) %>
    diff --git a/app/views/forum_posts/_forum_post.html.erb b/app/views/forum_posts/_forum_post.html.erb index 2bbd650f2..30932e88c 100644 --- a/app/views/forum_posts/_forum_post.html.erb +++ b/app/views/forum_posts/_forum_post.html.erb @@ -2,7 +2,7 @@

    - <%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %> + <%= link_to forum_post.creator.name, user_path(forum_post.creator_id), { :class => forum_post.creator.level_class } %> <% if forum_post.is_deleted? %> (deleted) <% end %> @@ -16,7 +16,7 @@ <%= format_text(forum_post.body) %>

    <% if forum_post.updater_id != forum_post.creator_id %> -

    Updated by <%= link_to forum_post.updater_name, user_path(forum_post.updater_id) %> <%= time_ago_in_words_tagged(forum_post.updated_at) %>

    +

    Updated by <%= link_to forum_post.updater_name, user_path(forum_post.updater_id), { :class => forum_post.updater.level_class } %> <%= time_ago_in_words_tagged(forum_post.updated_at) %>

    <% end %>
  • ID: <%= forum_post.id %>
  • diff --git a/app/views/forum_topics/index.html.erb b/app/views/forum_topics/index.html.erb index 8af6923bc..0cf1e970b 100644 --- a/app/views/forum_topics/index.html.erb +++ b/app/views/forum_topics/index.html.erb @@ -33,8 +33,8 @@ (locked) <% end %> - <%= link_to topic.creator.name, user_path(topic.creator) %> - <%= link_to topic.updater.name, user_path(topic.updater) %> + <%= link_to topic.creator.name, user_path(topic.creator), { :class => topic.creator.level_class } %> + <%= link_to topic.updater.name, user_path(topic.updater), { :class => topic.updater.level_class } %> <%= compact_time topic.updated_at %> <% end %> diff --git a/app/views/mod_actions/index.html.erb b/app/views/mod_actions/index.html.erb index 94b88fdd6..9c17f7c05 100644 --- a/app/views/mod_actions/index.html.erb +++ b/app/views/mod_actions/index.html.erb @@ -13,7 +13,7 @@ <% @mod_actions.each do |mod_action| %> <%= compact_time mod_action.created_at %> - <%= link_to mod_action.creator.name, user_path(mod_action.creator) %> + <%= link_to mod_action.creator.name, user_path(mod_action.creator), { :class => mod_action.creator.level_class } %> <%= format_text(mod_action.description) %> <% end %> diff --git a/app/views/note_versions/index.html.erb b/app/views/note_versions/index.html.erb index 05efde2e2..2758c587b 100644 --- a/app/views/note_versions/index.html.erb +++ b/app/views/note_versions/index.html.erb @@ -29,7 +29,7 @@ <%= note_version.updater_ip_addr %> <% end %> - <%= link_to note_version.updater.try(:name), user_path(note_version.updater) %> + <%= link_to note_version.updater.try(:name), user_path(note_version.updater), { :class => note_version.updater.level_class } %> <%= compact_time note_version.updated_at %> <% if CurrentUser.is_member? %> diff --git a/app/views/notes/index_by_note.html.erb b/app/views/notes/index_by_note.html.erb index 1d721591f..4d31ea455 100644 --- a/app/views/notes/index_by_note.html.erb +++ b/app/views/notes/index_by_note.html.erb @@ -16,7 +16,7 @@ <% @notes.each do |note| %> <%= link_to note.post_id, post_path(note.post_id) %> - <%= link_to note.creator.name, user_path(note.creator_id) %> + <%= link_to note.creator.name, user_path(note.creator_id), { :class => note.creator.level_class } %> <%= compact_time(note.created_at) %> <%= note.is_active? %> <%= format_text(note.body) %> diff --git a/app/views/pool_versions/index.html.erb b/app/views/pool_versions/index.html.erb index f82c80813..ff348d147 100644 --- a/app/views/pool_versions/index.html.erb +++ b/app/views/pool_versions/index.html.erb @@ -20,7 +20,7 @@ <%= link_to pool_version.pool.name, pool_path(pool_version.pool_id) %> <%= link_to pool_version.post_id_array.size, pool_versions_path(:search => {:pool_id => pool_version.pool_id}) %> <%= pool_version_diff(pool_version) %> - <%= link_to pool_version.updater_name, user_path(pool_version.updater_id) %> + <%= link_to pool_version.updater_name, user_path(pool_version.updater_id), { :class => pool_version.updater.level_class } %> <% if CurrentUser.is_janitor? %> <%= pool_version.updater_ip_addr %> diff --git a/app/views/pools/index.html.erb b/app/views/pools/index.html.erb index 8e27ac4a7..bcda70dea 100644 --- a/app/views/pools/index.html.erb +++ b/app/views/pools/index.html.erb @@ -19,7 +19,7 @@ <%= link_to h(pool.pretty_name), pool_path(pool) %> - <%= link_to h(pool.creator.name), user_path(pool.creator) %> + <%= link_to h(pool.creator.name), user_path(pool.creator), { :class => pool.creator.level_class } %> <%= pool.post_count %> diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb index aca43d9f5..4ac51b9f1 100644 --- a/app/views/posts/partials/show/_information.html.erb +++ b/app/views/posts/partials/show/_information.html.erb @@ -1,9 +1,9 @@
    • ID: <%= post.id %>
    • -
    • Uploader: <%= link_to_unless(post.uploader.nil?, post.uploader_name, user_path(post.uploader)) %>
    • +
    • Uploader: <%= link_to_unless(post.uploader.nil?, post.uploader_name, user_path(post.uploader), { :class => post.uploader.level_class }) %>
    • Date: <%= link_to time_ago_in_words_tagged(post.created_at), posts_path(:tags => "date:#{post.created_at.to_date}") %>
    • <% if post.approver %> -
    • Approver: <%= link_to(post.approver.name, user_path(post.approver_id)) %>
    • +
    • Approver: <%= link_to(post.approver.name, user_path(post.approver_id), { :class => post.approver.level_class }) %>
    • <% end %>
    • Size: <%= link_to_if Danbooru.config.can_user_see_post?(CurrentUser.user, post), number_to_human_size(post.file_size), post.file_url %> diff --git a/app/views/user_feedbacks/index.html.erb b/app/views/user_feedbacks/index.html.erb index 84db628fe..ce4601949 100644 --- a/app/views/user_feedbacks/index.html.erb +++ b/app/views/user_feedbacks/index.html.erb @@ -15,8 +15,8 @@ <% @user_feedbacks.each do |feedback| %> - <%= link_to feedback.user_name, user_path(feedback.user_id) %> - <%= link_to feedback.creator_name, user_path(feedback.creator_id) %> + <%= link_to feedback.user_name, user_path(feedback.user_id), { :class => feedback.user.level_class } %> + <%= link_to feedback.creator_name, user_path(feedback.creator_id), { :class => feedback.creator.level_class } %> <%= compact_time(feedback.created_at) %> <%= format_text(feedback.body) %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 2aded5c6e..1ac0d48b9 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -30,9 +30,9 @@ <% end %> - <%= link_to user.pretty_name, user_path(user.id) %> + <%= link_to user.pretty_name, user_path(user.id), { :class => user.level_class } %> <% if user.inviter %> - ← <%= link_to user.inviter.name, user_path(user.inviter_id) %> + ← <%= link_to user.inviter.name, user_path(user.inviter_id), { :class => user.inviter.level_class } %> <% end %> <%= link_to user.posts.count, posts_path(:tags => "user:#{user.name}") %> diff --git a/app/views/wiki_page_versions/index.html.erb b/app/views/wiki_page_versions/index.html.erb index 5d1c8b4ec..8bad2d85f 100644 --- a/app/views/wiki_page_versions/index.html.erb +++ b/app/views/wiki_page_versions/index.html.erb @@ -43,7 +43,7 @@ <%= compact_time(wiki_page_version.updated_at) %> <% if wiki_page_version.updater %> by - <%= link_to wiki_page_version.updater_name, user_path(wiki_page_version.updater) %> + <%= link_to wiki_page_version.updater_name, user_path(wiki_page_version.updater), { :class => wiki_page_version.updater.level_class } %> <% end %>