From 276949c0cd800794118ae0ba74d3e7d09edb2a76 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 28 May 2017 17:39:06 -0400 Subject: [PATCH 01/24] Added badge system --- app/assets/stylesheets/style.css.scss | 12 ++-- app/controllers/users_controller.rb | 17 ++++-- app/models/badge.rb | 18 ++++++ app/models/user.rb | 3 +- app/views/statics/donate.html.erb | 4 +- app/views/users/_username.html.erb | 4 +- app/views/users/edit.html.erb | 12 ++-- app/views/users/index.html.erb | 10 +++- .../20170319193517_add_badge_id_to_users.rb | 8 +++ db/schema.rb | 10 +++- db/seeds.rb | 55 ++++++++++++++++++- 11 files changed, 124 insertions(+), 29 deletions(-) create mode 100644 app/models/badge.rb create mode 100644 db/migrate/20170319193517_add_badge_id_to_users.rb diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss index 6de5aa2..da15801 100644 --- a/app/assets/stylesheets/style.css.scss +++ b/app/assets/stylesheets/style.css.scss @@ -437,18 +437,14 @@ blockquote p { color: #ddd !important; } } - - .donor { - color: #fff; - background: #f60 !important; - margin-left: 2px !important; - } - .ign { display: block; color: #000; font-style: italic; } + .badge { + margin-left: 2px !important; + } } #online-users { @@ -1026,4 +1022,4 @@ nav.pagination { padding: 0.1em 0.2em; border-radius: 0.2em; text-shadow: none; -} \ No newline at end of file +} diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5dc0e80..27e89af 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -10,8 +10,6 @@ class UsersController < ApplicationController if params[:role] if params[:role].downcase == "staff" @users = User.joins(:role).where("roles.value >= ?", Role.get(:mod).to_i) - elsif params[:role].downcase == "donor" - @users = User.joins(:role).where(donor: true) else if role = Role.get(params[:role]) @users = User.joins(:role).where(role: role) @@ -21,10 +19,18 @@ class UsersController < ApplicationController return end end + elsif params[:badge] + if badge = Badge.get(params[:badge]) + @users = User.joins(:badge).where(badge: badge) + else + flash[:alert] = "badge '#{params[:badge]}' does not exist!" + redirect_to users_path + return + end else @users = User.joins(:role).where.not(id: User.first.id) #Remove first user end - @users = @users.order("roles.value desc", "confirmed desc", :name) + @users = @users.order("roles.value desc", "confirmed desc", :name) unless params[:badge] @count = @users.size @users = @users.page(params[:page]).per(100) end @@ -151,7 +157,7 @@ class UsersController < ApplicationController def update if (mod? && current_user.role >= @user.role ) || (@user.is?(current_user) && confirmed?) if mod? - userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about, :role, :confirmed, :donor]) + userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about, :role, :badge, :confirmed]) else userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about]) end @@ -164,6 +170,9 @@ class UsersController < ApplicationController userdata.delete(:role) end end + if userdata[:badge] + userdata[:badge] = Badge.get(userdata[:badge]) + end if @user.youtube != userdata[:youtube] youtube = get_youtube(userdata[:youtube]) userdata[:youtube] = youtube[:channel] diff --git a/app/models/badge.rb b/app/models/badge.rb new file mode 100644 index 0000000..a7ff831 --- /dev/null +++ b/app/models/badge.rb @@ -0,0 +1,18 @@ +class Badge < ActiveRecord::Base + include Comparable + has_many :users + + def self.get (input) + if input.is_a?(String) || input.is_a?(Symbol) + Badge.find_by_name(input) + elsif input.is_a?(Fixnum) + Badge.find_by_id(input) + elsif input.is_a?(Badge) + return input + end + end + + def to_s + self.name + end +end diff --git a/app/models/user.rb b/app/models/user.rb index c422e28..ab7471e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,6 +5,7 @@ class User < ActiveRecord::Base strip_attributes belongs_to :role + belongs_to :badge has_secure_password @@ -173,4 +174,4 @@ class User < ActiveRecord::Base def set_email_token self.email_token ||= SecureRandom.hex(16) end -end \ No newline at end of file +end diff --git a/app/views/statics/donate.html.erb b/app/views/statics/donate.html.erb index 2831807..774d917 100644 --- a/app/views/statics/donate.html.erb +++ b/app/views/statics/donate.html.erb @@ -11,7 +11,7 @@
  • Donator+ ($20 or more) -

    We also have <%= link_to "list of users who donated", users_path(role: "donor") %> already!

    +

    We also have <%= link_to "list of users who donated", users_path(badge: "donor") %> already!

    Perks for you

    For Donator and Donator+

    @@ -45,4 +45,4 @@
    -

    Please note that you are not buying anything. We do not guarantee for these perks, however, we will try hard to make sure you'll get them! Donations are processed manually, it can take a few hours.

    \ No newline at end of file +

    Please note that you are not buying anything. We do not guarantee for these perks, however, we will try hard to make sure you'll get them! Donations are processed manually, it can take a few hours.

    diff --git a/app/views/users/_username.html.erb b/app/views/users/_username.html.erb index 10adb36..4e78673 100644 --- a/app/views/users/_username.html.erb +++ b/app/views/users/_username.html.erb @@ -1,4 +1,4 @@
    <%= link_to user.name, user, class: "role #{user.role.name} #{"banned" if user.banned?} #{"disabled" if user.disabled?} #{"unconfirmed" unless user.confirmed?}", title: "#{user.ign} – #{user.role}", style: "color: #{fcolor(user.role.color)}; background-color: #{user.role.color}" %> - <%= link_to "$", donate_statics_path, class: "role donor", title: "Donator" if user.donor? %> -
    \ No newline at end of file + <%= link_to user.badge.symbol, users_path(badge: user.badge.name), class: "role badge", title: user.badge.name, style: "color: #{fcolor(user.badge.color)}; background-color: #{user.badge.color}" unless user.badge.value == 0 %> + diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 6a6fe4d..5e63c00 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -28,15 +28,17 @@ - Confirmed email address + Badge - <%= f.select :confirmed, [["No", false], ["Yes", true]], {}, { disabled: !can_edit? } %> + <% if current_user.role >= Role.get(:mod) %> + <%= f.select :badge, Badge.all %> + <% end %> - Donator + Confirmed email address - <%= f.select :donor, [["No", false], ["Yes", true]], {}, { disabled: !can_edit? } %> + <%= f.select :confirmed, [["No", false], ["Yes", true]], {}, { disabled: !can_edit? } %> <% end %> @@ -87,4 +89,4 @@ This user has not confirmed his email! <% end %> <% end %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 883ffb0..95ab480 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,12 +1,16 @@

    - <% if params[:role] %> + <% if params[:role] && !params[:badge]%> <%= title "All '#{params[:role]}' users" %> + <% elsif params[:badge] && !params[:role] %> + <%= title "All '#{params[:badge]}' users" %> + <% elsif params[:role] && params[:badge] %> + <%= title "All '#{params[:role]}' and '#{params[:badge]}' users" %> <% else %> <%= title "All Users" %> <% end %> (<%= @count %>)

    -<%= link_to "show all", users_path if params[:role] %> +<%= link_to "show all", users_path if params[:role] || params[:badge] %>
    <% @users.each do |u| %> @@ -19,4 +23,4 @@
    <% end %> <%= paginate @users %> - \ No newline at end of file + diff --git a/db/migrate/20170319193517_add_badge_id_to_users.rb b/db/migrate/20170319193517_add_badge_id_to_users.rb new file mode 100644 index 0000000..08328cf --- /dev/null +++ b/db/migrate/20170319193517_add_badge_id_to_users.rb @@ -0,0 +1,8 @@ +class AddBadgeIdToUsers < ActiveRecord::Migration + def change + add_column :users, :badge_id, :integer + add_column :users, :badge_id, :integer, default: 0 + User.where(donor: true).update_all(badge_id: 1) + remove_column :users, :donor + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c68029..b38ae38 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160926220738) do +ActiveRecord::Schema.define(version: 20170319193517) do create_table "blogposts", force: :cascade do |t| t.string "title" @@ -90,6 +90,12 @@ ActiveRecord::Schema.define(version: 20160926220738) do t.string "color" end + create_table "badges", force: :cascade do |t| + t.string "name" + t.string "symbol" + t.string "color" + end + create_table "sessions", force: :cascade do |t| t.string "session_id", null: false t.text "data", limit: 65535 @@ -122,7 +128,6 @@ ActiveRecord::Schema.define(version: 20160926220738) do t.string "youtube" t.string "youtube_channelname" t.string "twitter" - t.boolean "donor", default: false t.string "email_token" t.boolean "confirmed", default: false t.datetime "last_seen" @@ -134,6 +139,7 @@ ActiveRecord::Schema.define(version: 20160926220738) do t.boolean "mail_own_blogpost_comment", default: true t.boolean "mail_other_blogpost_comment", default: true t.boolean "mail_mention", default: true + t.integer "badge_id" end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree diff --git a/db/seeds.rb b/db/seeds.rb index 780ddb5..06c8d10 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -10,6 +10,14 @@ Role.create!([ {name: "superadmin", value: 500, color: "#d22"} ]) +Badge.create!([ + {name: "none", symbol: "", color: "#000"}, + {name: "donor", symbol: "$", color: "#f60"}, + {name: "developer", symbol: "D", color: "#a0a"}, + {name: "retired", symbol: "R", color: "#0aa"}, + {name: "lead", symbol: "L", color: "#a00"} +]) + userpw = SecureRandom.hex(36) @@ -23,6 +31,7 @@ deleted_user = User.create!( password: userpw, password_confirmation: userpw, role: Role.get(:disabled), + badge: Badge.get(:none), skype: "echo123", skype_public: true, last_ip: "0.0.0.0", @@ -37,5 +46,47 @@ User.create!( email: "jomo@example.com", password: "123456789", # high seructity! password_confirmation: "123456789", - role: Role.get(:superadmin) -) \ No newline at end of file + role: Role.get(:superadmin), + badge: Badge.get(:donor), + confirmed: true +) +User.create!( + uuid: "7f52491ab5d64c11b4a43806db47a101", + ign: "YummyRedstone", + email: "yummy@example.com", + password: "123456789", # high seructity! + password_confirmation: "123456789", + role: Role.get(:admin), + badge: Badge.get(:lead), + confirmed: true +) +User.create!( + uuid: "d2693e9193e14e3f929ff38e1ce8df03", + ign: "Pepich1851", + email: "pepe@example.com", + password: "123456789", # high seructity! + password_confirmation: "123456789", + role: Role.get(:superadmin), + badge: Badge.get(:retired), + confirmed: true +) +User.create!( + uuid: "c69f8316c60a4f8ca922bda933e01acd", + ign: "Doomblah", + email: "doom@example.com", + password: "123456789", # high seructity! + password_confirmation: "123456789", + role: Role.get(:normal), + badge: Badge.get(:developer), + confirmed: true +) +User.create!( + uuid: "b85a91b558b0474da2a42d5dd025f9e5", + ign: "Futsy", + email: "futsy@example.com", + password: "123456789", # high seructity! + password_confirmation: "123456789", + role: Role.get(:mod), + badge: Badge.get(:none), + confirmed: true +) -- 2.52.0 From e4d86d4bb0ad17bc4bb1730052089b94841fe47c Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 28 May 2017 17:40:50 -0400 Subject: [PATCH 02/24] Added Necropost Warning --- app/controllers/forumgroups_controller.rb | 2 +- app/controllers/forums_controller.rb | 4 +- app/views/forums/edit.html.erb | 6 ++- app/views/forums/new.html.erb | 6 ++- app/views/threadreplies/_new.html.erb | 17 +++++++- ...170409135858_add_necro_length_to_forums.rb | 5 +++ db/schema.rb | 43 ++++++++++--------- 7 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 db/migrate/20170409135858_add_necro_length_to_forums.rb diff --git a/app/controllers/forumgroups_controller.rb b/app/controllers/forumgroups_controller.rb index a7b31ab..fe359af 100644 --- a/app/controllers/forumgroups_controller.rb +++ b/app/controllers/forumgroups_controller.rb @@ -77,4 +77,4 @@ class ForumgroupsController < ApplicationController params.require(:forumgroup).permit(a) end -end \ No newline at end of file +end diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index ecf570e..486d21c 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -89,7 +89,7 @@ class ForumsController < ApplicationController end def forum_params(add = []) - a = [:name, :position, :role_read_id, :role_write_id] + add + a = [:name, :position, :role_read_id, :role_write_id, :necro_length] + add params.require(:forum).permit(a) end -end \ No newline at end of file +end diff --git a/app/views/forums/edit.html.erb b/app/views/forums/edit.html.erb index 60b3fb1..571b3b7 100644 --- a/app/views/forums/edit.html.erb +++ b/app/views/forums/edit.html.erb @@ -21,8 +21,12 @@ <%= f.label :role_write_id, "Min. write role" %> <%= f.select :role_write_id, role_selection, include_blank: false %> + + <%= f.label :necro_length, "Necropost warning delay (in days)" %> + <%= f.number_field :necro_length, placeholder: "Warning Delay (leave blank for no warning)" %> +

    <%= f.submit "Update forum", class: "btn blue left" %>

    <% end %>

    <%= button_to "Delete forum", @forum, method: "delete", data: {confirm: "Delete forum forever?\nThreads won't be accessible!"}, class: "btn red right" %>

    -
    \ No newline at end of file +
    diff --git a/app/views/forums/new.html.erb b/app/views/forums/new.html.erb index f60e2b3..836a9b2 100644 --- a/app/views/forums/new.html.erb +++ b/app/views/forums/new.html.erb @@ -21,8 +21,12 @@ <%= f.label :role_write_id, "Min. write role" %> <%= f.select :role_write_id, role_selection, include_blank: false %> + + <%= f.label :necro_length, "Necropost warning delay (in days)" %> + <%= f.number_field :necro_length, placeholder: "Warning Delay (leave blank for no warning)" %> + <%= f.hidden_field :forumgroup_id %>

    <%= f.submit "Create forum", class: "btn blue left" %>

    -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/threadreplies/_new.html.erb b/app/views/threadreplies/_new.html.erb index b0c4b5e..9d716d8 100644 --- a/app/views/threadreplies/_new.html.erb +++ b/app/views/threadreplies/_new.html.erb @@ -1,4 +1,17 @@ <%= form_for [reply.thread, reply] do |f| %> <%= render partial: "md_editor", locals: {name: "threadreply[content]", content: reply.content} %> -

    <%= f.submit "Reply#{ ' (Locked)' if reply.thread.locked? }", class: "btn blue" %>

    -<% end %> \ No newline at end of file + <% nec_msg = "" %> + <% forum = Forum.find(reply.thread.forum_id) %> + <% if forum.necro_length != nil %> + <% if Threadreply.where(forumthread: reply.thread).count != 0 %> + <% prevAgo = Threadreply.where(forumthread: reply.thread).order(:id).last.created_at %> + <% if prevAgo <= forum.necro_length.days.ago.utc %> + <% nec_msg = "You may be necroposting, as the last reply was made at least #{forum.necro_length} days ago. If you still wish to make this reply, press 'Ok'." %> + <% end %> + <% elsif reply.thread.created_at <= forum.necro_length.days.ago.utc %> + <% nec_msg = "You may be necroposting, as this thread was posted at least #{forum.necro_length} days ago. If you still wish to make this reply, press 'Ok'." %> + <% end %> + <% end %> +

    <%= f.submit "Reply#{ ' (Locked)' if reply.thread.locked? }", class: "btn blue", data: { confirm: nec_msg } %>

    + <% nec_msg = "" %> +<% end %> diff --git a/db/migrate/20170409135858_add_necro_length_to_forums.rb b/db/migrate/20170409135858_add_necro_length_to_forums.rb new file mode 100644 index 0000000..53199e4 --- /dev/null +++ b/db/migrate/20170409135858_add_necro_length_to_forums.rb @@ -0,0 +1,5 @@ +class AddNecroLengthToForums < ActiveRecord::Migration + def change + add_column :forums, :necro_length, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index b38ae38..353c482 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,10 +11,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170319193517) do +ActiveRecord::Schema.define(version: 20170409135858) do create_table "blogposts", force: :cascade do |t| - t.string "title" + t.string "title", limit: 191 t.text "content", limit: 65535 t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 @@ -32,18 +32,19 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "forumgroups", force: :cascade do |t| - t.string "name" + t.string "name", limit: 191 t.integer "position", limit: 4 t.integer "role_read_id", limit: 4 t.integer "role_write_id", limit: 4 end create_table "forums", force: :cascade do |t| - t.string "name" + t.string "name", limit: 191 t.integer "position", limit: 4 t.integer "role_read_id", limit: 4 t.integer "role_write_id", limit: 4 t.integer "forumgroup_id", limit: 4 + t.integer "necro_length", limit: 4, default: -1 end create_table "forums_labels", id: false, force: :cascade do |t| @@ -52,7 +53,7 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "forumthreads", force: :cascade do |t| - t.string "title" + t.string "title", limit: 191 t.text "content", limit: 65535 t.boolean "sticky", default: false t.boolean "locked", default: false @@ -65,29 +66,29 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "info", force: :cascade do |t| - t.string "title" + t.string "title", limit: 191 t.text "content", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "labels", force: :cascade do |t| - t.string "name" - t.string "color" + t.string "name", limit: 191 + t.string "color", limit: 191 end create_table "register_tokens", force: :cascade do |t| - t.string "uuid", null: false - t.string "token", null: false - t.string "email", null: false + t.string "uuid", limit: 191, null: false + t.string "token", limit: 191, null: false + t.string "email", limit: 191, null: false end add_index "register_tokens", ["uuid"], name: "index_register_tokens_on_uuid", unique: true, using: :btree create_table "roles", force: :cascade do |t| - t.string "name" + t.string "name", limit: 191 t.integer "value", limit: 4 - t.string "color" + t.string "color", limit: 191 end create_table "badges", force: :cascade do |t| @@ -97,7 +98,7 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "sessions", force: :cascade do |t| - t.string "session_id", null: false + t.string "session_id", limit: 191, null: false t.text "data", limit: 65535 t.datetime "created_at" t.datetime "updated_at" @@ -116,14 +117,14 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "users", force: :cascade do |t| - t.string "uuid", null: false - t.string "name", null: false - t.string "password_digest", null: false - t.string "ign", null: false - t.string "email", null: false + t.string "uuid", limit: 191, null: false + t.string "name", limit: 191, null: false + t.string "password_digest", limit: 191, null: false + t.string "ign", limit: 191, null: false + t.string "email", limit: 191, null: false t.text "about", limit: 65535 - t.string "last_ip" - t.string "skype" + t.string "last_ip", limit: 191 + t.string "skype", limit: 191 t.boolean "skype_public", default: false t.string "youtube" t.string "youtube_channelname" -- 2.52.0 From 888c863b108b3319c32250453a81f2ac138d8712 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 28 May 2017 17:42:39 -0400 Subject: [PATCH 03/24] Added Reply Reversal And Toggle --- app/controllers/forumthreads_controller.rb | 8 ++++++-- app/views/forumthreads/show.html.erb | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index b9b5714..b1dffd9 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -7,7 +7,11 @@ class ForumthreadsController < ApplicationController end def show - @replies = @thread.replies.page(params[:page]) + if params[:reverse] + @replies = @thread.replies.reverse_order.page(params[:page]) + else + @replies = @thread.replies.page(params[:page]) + end end def edit @@ -92,4 +96,4 @@ class ForumthreadsController < ApplicationController a += add params.require(:forumthread).permit(a) end -end \ No newline at end of file +end diff --git a/app/views/forumthreads/show.html.erb b/app/views/forumthreads/show.html.erb index 876d55d..82f8fb3 100644 --- a/app/views/forumthreads/show.html.erb +++ b/app/views/forumthreads/show.html.erb @@ -1,6 +1,12 @@ <%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %> → <%= link_to @thread.forum, @thread.forum %> → <%=truncate(@thread.title, length: 60, omission: " …") %> -

    <%= render partial: "labels/label", locals: {label: @thread.label} %><%= title @thread.title %>

    - +

    + <%= render partial: "labels/label", locals: {label: @thread.label} %><%= title @thread.title %> + <% if params[:reverse] %> + <%= link_to "Reverse Replies", @thread, class: "btn right blue" %> + <% else %> + <%= link_to "Reverse Replies", forumthread_path(@thread, reverse: true), class: "btn right blue" %> + <% end %> +

    <%= link_to(@thread.author.avatar(64), @thread.author, title: @thread.author.ign) %> @@ -44,4 +50,4 @@ <% else %>

    Please <%= link_to "Log in", login_path(return_path: request.env['PATH_INFO']), action: "new" %> to post a reply.

    <% end %> -
    \ No newline at end of file +
    -- 2.52.0 From dfb1ed9185449350d35eb7316ba5a60c72266419 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 28 May 2017 17:46:39 -0400 Subject: [PATCH 04/24] Added Website Settings --- Gemfile | 3 +- app/assets/stylesheets/dark.css.scss | 105 ++++++++++++++++++ app/assets/stylesheets/mobi.css.scss | 15 ++- app/assets/stylesheets/style.css.scss | 24 +++- app/controllers/users_controller.rb | 11 +- app/helpers/application_helper.rb | 6 +- app/views/layouts/_head.html.erb | 9 +- app/views/layouts/application.html.erb | 11 +- app/views/users/edit.html.erb | 7 +- .../users/edit_website_settings.html.erb | 34 ++++++ config/initializers/assets.rb | 1 + .../20170320195301_add_utc_time_to_users.rb | 5 + ...170328100851_add_header_scroll_to_users.rb | 5 + .../20170515200733_add_dark_to_users.rb | 5 + db/schema.rb | 7 +- db/seeds.rb | 48 ++------ 16 files changed, 236 insertions(+), 60 deletions(-) create mode 100644 app/assets/stylesheets/dark.css.scss create mode 100644 app/views/users/edit_website_settings.html.erb create mode 100644 config/initializers/assets.rb create mode 100644 db/migrate/20170320195301_add_utc_time_to_users.rb create mode 100644 db/migrate/20170328100851_add_header_scroll_to_users.rb create mode 100644 db/migrate/20170515200733_add_dark_to_users.rb diff --git a/Gemfile b/Gemfile index 4714ee3..a277484 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem 'activerecord-session_store' gem 'highlight_js-rails', github: 'RedstonerServer/highlight_js-rails' gem 'kaminari', github: 'jomo/kaminari', branch: 'patch-2' # pagination gem 'jquery-textcomplete-rails', github: 'RedstonerServer/jquery-textcomplete-rails' # @mentions +gem 'actionpack-action_caching' # Gems used only for assets and not required # in production environments by default. @@ -43,4 +44,4 @@ end group :production do # Use unicorn as the app server gem 'unicorn' -end \ No newline at end of file +end diff --git a/app/assets/stylesheets/dark.css.scss b/app/assets/stylesheets/dark.css.scss new file mode 100644 index 0000000..90c7fc0 --- /dev/null +++ b/app/assets/stylesheets/dark.css.scss @@ -0,0 +1,105 @@ +body { + background-color:rgb(50, 50, 50); + text-shadow:none !important; + color:rgb(190, 190, 190) !important; +} +::selection { + background-color:rgb(100, 150, 255); +} +a { + color:rgb(203, 75, 22); + border-color:black !important; +} +a:hover { + color:rgb(215, 100, 40); +} +#main-content { + border-color:black !important; + padding:30px 100px; + box-shadow:none; +} +#main-content-scroll { + padding: 131px 100px; + border: 1px solid #000; + box-shadow: 0 0 5px #000; +} +hr { + background-color:black !important; + border-color:black !important; +} +code { + background-color:rgb(30, 30, 30) !important; + border-color:black !important; + color:white !important; +} +#head_top { + width:100%; + z-index:100; +} +#head_scroll { + @extend #head_top; + position: fixed; + width: 100%; + z-index: 1; +} +div#userbar { + background-color:rgb(90, 90, 90) !important; + border-color:black !important; + color:white !important; + text-shadow:none !important; +} +#head a { + text-shadow:none !important; + color:white !important; +} +#head a:hover { + color:rgb(190, 190, 190) !important; +} +.header { + background-color:rgb(0, 0, 0); + border:none !important; +} +input[type="email"], input[type="text"], input[type="password"] { + background-color:rgb(110, 110, 110) !important; + color:white !important; +} +::placeholder { + color:lightgray; +} +.item { + background-color:rgb(40, 40, 40) !important; + border-color:black !important; +} +.item-group { + border-color:black !important; +} +div.header { + background-color:rgb(20, 20, 20) !important; +} +.avatar { + border-color:black !important; +} +.items { + border-color:black !important; +} +.markdown-help { + background-color:rgb(90, 90, 90); + color:white; + border-color:black; +} +textarea { + background-color:rgb(100, 100, 100); + color:white; +} +.headline { + border-color:black !important; +} +.role { + opacity:0.7 !important; +} +.label { + opacity:0.7 !important; +} +.notice { + color:white; +} diff --git a/app/assets/stylesheets/mobi.css.scss b/app/assets/stylesheets/mobi.css.scss index cc437cb..c1b44fd 100644 --- a/app/assets/stylesheets/mobi.css.scss +++ b/app/assets/stylesheets/mobi.css.scss @@ -4,12 +4,12 @@ th, td { // force tables into line-mode - // it's a bit ugly, but probably the best + // it''s a bit ugly, but probably the best // solution for small screens display: block; } - #head { + #head_top { #menu { #logo { display: none; @@ -17,10 +17,19 @@ } } + #head_scroll { + @extend #head_top; + position: fixed; +} + #main-content { padding: 30px 5px; } + #main-content-scroll { + padding: 181px 5px; + } + .front-page { h1 { font-size: 2em !important; @@ -66,4 +75,4 @@ margin: 50px 20px 0; } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss index da15801..18042ad 100644 --- a/app/assets/stylesheets/style.css.scss +++ b/app/assets/stylesheets/style.css.scss @@ -80,7 +80,7 @@ a { } } -#head { +#head_top { background: #3f3f3f; #menu { @@ -181,6 +181,13 @@ a { } } +#head_scroll { + @extend #head_top; + position: fixed; + width: 100%; + z-index: 1; +} + .front-page { margin: auto; text-align: center; @@ -260,6 +267,11 @@ span.no-about { } } +#main-content-scroll { + @extend #main-content; + padding: 131px 100px; +} + #user-info { .user-avatar { margin-bottom: 30px; @@ -454,6 +466,7 @@ blockquote p { } .md_editor { + .field_container { position: relative; @@ -461,7 +474,7 @@ blockquote p { position: absolute; top: 1em; left: 1em; - z-index: 10; + z-index: 0; } .editor_field { @@ -671,6 +684,13 @@ tr.spacer { color: #ddd; } + &.variable-size { + background: #4096ee; + @media only screen and (max-width: 500px) { + font-size: 9px; + } + } + &.blue { background: #4096ee; diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 27e89af..16f42d3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -157,9 +157,9 @@ class UsersController < ApplicationController def update if (mod? && current_user.role >= @user.role ) || (@user.is?(current_user) && confirmed?) if mod? - userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about, :role, :badge, :confirmed]) + userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about, :role, :badge, :confirmed, :header_scroll, :utc_time, :dark]) else - userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about]) + userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about, :header_scroll, :utc_time, :dark]) end if userdata[:role] role = Role.get(userdata[:role]) @@ -241,6 +241,13 @@ class UsersController < ApplicationController end end + def edit_website_settings + unless @user.is?(current_user) || admin? && current_user.role > @user.role || superadmin? + flash[:alert] = "You are not allowed to edit this user's website settings!" + redirect_to @user + end + end + def update_login if @user.is?(current_user) || admin? && current_user.role > @user.role || superadmin? authenticated = !@user.is?(current_user) || @user.authenticate(params[:current_password]) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1419391..a1bf22c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -11,10 +11,12 @@ module ApplicationHelper end def ago(tm) - if tm + if tm && current_user.try(:utc_time) != true content_tag :time, title: tm.strftime("%e %b %Y, %H:%M %Z"), datetime: tm.to_datetime.rfc3339 do tm.strftime("%e %b %Y, %H:%M") end + else + tm end end @@ -90,4 +92,4 @@ module ApplicationHelper https://www.youtube-nocookie.com/embed/\\1?theme=light&vq=hd720&hd=1&iv_load_policy=3&showinfo=1&showsearch=0&rel=0&modestbranding&hd=1&autohide=1&html5=1&start=\\3'> ") end -end \ No newline at end of file +end diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb index 183a615..e6b5080 100644 --- a/app/views/layouts/_head.html.erb +++ b/app/views/layouts/_head.html.erb @@ -1,4 +1,9 @@ - \ No newline at end of file + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a0a5f83..e85d417 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,6 +5,9 @@ <%= stylesheet_link_tag "application", :media => "all" %> + <% if current_user.try(:dark) == true %> + <%= stylesheet_link_tag "dark", :media => "all" %> + <% end %> <%= csrf_meta_tags %> <%= favicon_link_tag "favicon.ico" %> <%= javascript_include_tag "https://cdn.rawgit.com/jomo/ago.js/v0.0.1/ago.min.js", crossorigin: :anonymous, integrity: "sha256-xw0JUUdbuZQCVO+QScoxrlEsD4nZGCjMRh9PP8GLhcY=" %> @@ -14,7 +17,11 @@ <%= render partial: "/layouts/head" %> -
    + <% content = "main-content" %> + <% if current_user.try(:header_scroll) == true %> + <% content = "main-content-scroll" %> + <% end %> +
    <% if alert %>
    <%= alert %>
    <% end %> @@ -25,4 +32,4 @@
    <%= render partial: "/layouts/footer" %> - \ No newline at end of file + diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 5e63c00..133a69d 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -75,10 +75,11 @@ -

    <%= f.submit "Save profile", class: "btn blue left", disabled: (!@user.confirmed? && @user.is?(current_user)) %>

    +

    <%= f.submit "Save profile", class: "btn variable-size left", disabled: (!@user.confirmed? && @user.is?(current_user)) %>

    - <%= link_to "Edit login details", edit_login_user_path(@user), class: "btn blue right" %> - <%= link_to "Notification settings", edit_notifications_user_path(@user), class: "btn blue right" %> + <%= link_to "Edit login details", edit_login_user_path(@user), class: "btn variable-size right" %> + <%= link_to "Notification settings", edit_notifications_user_path(@user), class: "btn variable-size right" %> + <%= link_to "Website settings", edit_website_settings_user_path(@user), class: "btn variable-size right" %>

    diff --git a/app/views/users/edit_website_settings.html.erb b/app/views/users/edit_website_settings.html.erb new file mode 100644 index 0000000..2fdeffb --- /dev/null +++ b/app/views/users/edit_website_settings.html.erb @@ -0,0 +1,34 @@ +<% title "Edit Website Settings: #{@user.name}" %> + +<%= link_to @user.name, @user %> → Edit Website Settings +

    Edit Website Settings

    + + +<%= form_for @user do |f| %> + + + + + + + + + + + + + + + +
    Header moves with scrolling (Experimental - do not report bugs) + <%= f.check_box :header_scroll %> +
    Show exact UTC times + <%= f.check_box :utc_time %> +
    Dark theme* + <%= f.check_box :dark %> +
    +

    <%= f.submit "Save changes", class: "btn blue left" %>

    +
    +<% end %> +


    +*Warning: If as a result to enabling this style your eyes get infected with a severe case of eye cancer, we are not reliable for any damage. Please contact your doctor in advance to ensure that in case of infection you will be treated accordingly. Quality theme brought to you by Redempt™. diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000..ea74dfd --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1 @@ +Rails.application.config.assets.precompile += %w( dark.css ) diff --git a/db/migrate/20170320195301_add_utc_time_to_users.rb b/db/migrate/20170320195301_add_utc_time_to_users.rb new file mode 100644 index 0000000..538357c --- /dev/null +++ b/db/migrate/20170320195301_add_utc_time_to_users.rb @@ -0,0 +1,5 @@ +class AddUtcTimeToUsers < ActiveRecord::Migration + def change + add_column :users, :utc_time, :boolean, default: false + end +end diff --git a/db/migrate/20170328100851_add_header_scroll_to_users.rb b/db/migrate/20170328100851_add_header_scroll_to_users.rb new file mode 100644 index 0000000..0db36b1 --- /dev/null +++ b/db/migrate/20170328100851_add_header_scroll_to_users.rb @@ -0,0 +1,5 @@ +class AddHeaderScrollToUsers < ActiveRecord::Migration + def change + add_column :users, :header_scroll, :boolean, default: false + end +end diff --git a/db/migrate/20170515200733_add_dark_to_users.rb b/db/migrate/20170515200733_add_dark_to_users.rb new file mode 100644 index 0000000..c4bf3cc --- /dev/null +++ b/db/migrate/20170515200733_add_dark_to_users.rb @@ -0,0 +1,5 @@ +class AddDarkToUsers < ActiveRecord::Migration + def change + add_column :users, :dark, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 353c482..0a29b6b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170409135858) do +ActiveRecord::Schema.define(version: 20170515200733) do create_table "blogposts", force: :cascade do |t| t.string "title", limit: 191 @@ -133,6 +133,7 @@ ActiveRecord::Schema.define(version: 20170409135858) do t.boolean "confirmed", default: false t.datetime "last_seen" t.integer "role_id", limit: 4, null: false + t.integer "badge_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "mail_own_thread_reply", default: true @@ -140,7 +141,9 @@ ActiveRecord::Schema.define(version: 20170409135858) do t.boolean "mail_own_blogpost_comment", default: true t.boolean "mail_other_blogpost_comment", default: true t.boolean "mail_mention", default: true - t.integer "badge_id" + t.boolean "header_scroll", default: false + t.boolean "utc_time", default: false + t.boolean "dark", default: false end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree diff --git a/db/seeds.rb b/db/seeds.rb index 06c8d10..7b7530d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -36,7 +36,10 @@ deleted_user = User.create!( skype_public: true, last_ip: "0.0.0.0", confirmed: true, - last_seen: Time.utc(0).to_datetime + last_seen: Time.utc(0).to_datetime, + header_scroll: false, + utc_time: false, + dark: false ) deleted_user.update_attribute(:ign, "Steve") @@ -47,46 +50,9 @@ User.create!( password: "123456789", # high seructity! password_confirmation: "123456789", role: Role.get(:superadmin), + header_scroll: false, + utc_time: false, + dark: false badge: Badge.get(:donor), confirmed: true ) -User.create!( - uuid: "7f52491ab5d64c11b4a43806db47a101", - ign: "YummyRedstone", - email: "yummy@example.com", - password: "123456789", # high seructity! - password_confirmation: "123456789", - role: Role.get(:admin), - badge: Badge.get(:lead), - confirmed: true -) -User.create!( - uuid: "d2693e9193e14e3f929ff38e1ce8df03", - ign: "Pepich1851", - email: "pepe@example.com", - password: "123456789", # high seructity! - password_confirmation: "123456789", - role: Role.get(:superadmin), - badge: Badge.get(:retired), - confirmed: true -) -User.create!( - uuid: "c69f8316c60a4f8ca922bda933e01acd", - ign: "Doomblah", - email: "doom@example.com", - password: "123456789", # high seructity! - password_confirmation: "123456789", - role: Role.get(:normal), - badge: Badge.get(:developer), - confirmed: true -) -User.create!( - uuid: "b85a91b558b0474da2a42d5dd025f9e5", - ign: "Futsy", - email: "futsy@example.com", - password: "123456789", # high seructity! - password_confirmation: "123456789", - role: Role.get(:mod), - badge: Badge.get(:none), - confirmed: true -) -- 2.52.0 From 252dc5bdfa0678659c77034fc4d39cc2491b3cda Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 28 May 2017 17:46:54 -0400 Subject: [PATCH 05/24] Added Who's Playing? screen --- app/controllers/statics_controller.rb | 6 ++++++ app/views/layouts/_head.html.erb | 3 +++ app/views/statics/online.html.erb | 17 +++++++++++++++++ config/database.yml | 2 +- config/environments/development.rb | 4 +++- config/routes.rb | 3 ++- 6 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 app/views/statics/online.html.erb diff --git a/app/controllers/statics_controller.rb b/app/controllers/statics_controller.rb index f2891f3..70d3bd8 100644 --- a/app/controllers/statics_controller.rb +++ b/app/controllers/statics_controller.rb @@ -1,5 +1,7 @@ class StaticsController < ApplicationController + caches_action :online, expires_in: 10.seconds + def index if current_user redirect_to blogposts_path @@ -14,4 +16,8 @@ class StaticsController < ApplicationController def donate end + def online + @players = JSON.parse(File.read("/etc/minecraft/redstoner/plugins/JavaUtils/players.json"))["players"] + @players.collect!{ |p| User.find_by(uuid: p["uuid"].tr("-", "")) or User.new(name: p["name"], ign: p["name"], uuid: p["uuid"].tr("-", ""), role: Role.get("normal"), confirmed: true) }.sort_by!(&:role).reverse! + end end diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb index e6b5080..c64fe30 100644 --- a/app/views/layouts/_head.html.erb +++ b/app/views/layouts/_head.html.erb @@ -31,6 +31,9 @@
  • <%= link_to "Donate", donate_statics_path, class: ("active" if con == "statics" && params[:action] == "donate") %>
  • +
  • + <%= link_to "Who's Playing?", online_statics_path, class: ("active" if con == "statics" && params[:action] == "online") %> +
  • diff --git a/app/views/statics/online.html.erb b/app/views/statics/online.html.erb new file mode 100644 index 0000000..8c31182 --- /dev/null +++ b/app/views/statics/online.html.erb @@ -0,0 +1,17 @@ +<% title "Who's Playing?" %> +

    These players are currently playing on Redstoner:

    +
    + <% @players.each do |u| %> +
    + <%= link_to(u.avatar(64), u) %> +
    + <%= render partial: "users/username", locals: { user: u } %>
    + <%= u.ign %> + <% unless u.id %> +
    (Not signed up) + <% end %> +
    +
    + <% end %> +
    + diff --git a/config/database.yml b/config/database.yml index f421bef..db672c6 100644 --- a/config/database.yml +++ b/config/database.yml @@ -24,4 +24,4 @@ test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 - timeout: 5000 \ No newline at end of file + timeout: 5000 diff --git a/config/environments/development.rb b/config/environments/development.rb index 06819fd..bfa0c96 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,6 +6,8 @@ Redstoner::Application.configure do # since you don't have to restart the web server when you make code changes. config.cache_classes = false + config.action_controller.perform_caching = true + # Log error messages when you accidentally call methods on nil. config.whiny_nils = true @@ -43,4 +45,4 @@ Redstoner::Application.configure do password: ENV["GMAIL_PASSWORD"], } -end \ No newline at end of file +end diff --git a/config/routes.rb b/config/routes.rb index 584c94f..f79ab5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,10 +4,11 @@ Redstoner::Application.routes.draw do resources :comments end - resources :statics, only: [:home, :donate], path: '/' do + resources :statics, only: [:home, :donate, :online], path: '/' do collection do get 'donate' get 'home' + get 'online' get 'index' end end -- 2.52.0 From 44392c1df337360da1f5dcf4c27471492ccd5602 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 28 May 2017 18:08:57 -0400 Subject: [PATCH 06/24] Added Searching Features * Added Thread Search Feature * Added User Search Feature * Re-organized searching, added @mention support to author search --- app/controllers/application_controller.rb | 2 +- app/controllers/blogposts_controller.rb | 2 +- app/controllers/forums_controller.rb | 2 +- app/controllers/forumthreads_controller.rb | 23 ++++- app/controllers/users_controller.rb | 13 ++- app/helpers/mailer_helper.rb | 2 +- app/helpers/users_helper.rb | 2 +- app/models/forum.rb | 2 +- app/models/forumthread.rb | 43 ++++++++++ app/models/role.rb | 2 +- app/models/user.rb | 4 + .../application/_md_editor_user.html.erb | 8 ++ app/views/forums/index.html.erb | 4 +- app/views/forums/show.html.erb | 13 ++- app/views/forumthreads/index.html.erb | 84 +++++++++++++++++++ app/views/forumthreads/search.html.erb | 56 +++++++++++++ app/views/users/index.html.erb | 31 +++++-- config/routes.rb | 7 +- .../20170522210610_add_search_indexes.rb | 8 ++ db/schema.rb | 12 ++- 20 files changed, 293 insertions(+), 27 deletions(-) create mode 100644 app/views/application/_md_editor_user.html.erb create mode 100644 app/views/forumthreads/index.html.erb create mode 100644 app/views/forumthreads/search.html.erb create mode 100644 db/migrate/20170522210610_add_search_indexes.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a0e166e..d489611 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -75,4 +75,4 @@ class ApplicationController < ActionController::Base !!(current_user && current_user.confirmed?) end -end \ No newline at end of file +end diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb index 79c9e5d..7a9851d 100644 --- a/app/controllers/blogposts_controller.rb +++ b/app/controllers/blogposts_controller.rb @@ -75,4 +75,4 @@ class BlogpostsController < ApplicationController end end -end \ No newline at end of file +end diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 486d21c..761a86b 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -1,4 +1,5 @@ class ForumsController < ApplicationController + before_filter :check_permission, only: [:show, :edit, :update, :destroy] def index @@ -77,7 +78,6 @@ class ForumsController < ApplicationController redirect_to forums_path end - private def check_permission diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index b1dffd9..e21c6d4 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -3,9 +3,14 @@ class ForumthreadsController < ApplicationController before_filter :check_permission, only: [:show, :edit, :update, :destroy] def index - redirect_to forum_path(@thread.forum.forumgroup, f) + if params[:label] && !Label.where("lower(name) = ?", params[:label].downcase).try(:first) && params[:label].downcase != "no label" + flash[:alert] = "'#{params[:label]}' is not a valid label." + redirect_to forumthreads_path(params.except(:label, :controller, :action)) + return + end + @threads = Forumthread.filter(current_user, params[:title], params[:content], params[:reply], params[:label], User.where("lower(ign) = ?", params[:author].to_s.downcase).try(:first), params[:query], Forum.where(id: params[:id]).try(:first)) + .page(params[:page]).per(30) end - def show if params[:reverse] @replies = @thread.replies.reverse_order.page(params[:page]) @@ -80,6 +85,20 @@ class ForumthreadsController < ApplicationController redirect_to @thread.forum end + def search + end + + def search_redirect + params.each do |key, value| + params[key] = nil if params[key] == "" + end + params[:id] = nil if params[:id] == "Search All Threads" + params[:label] = nil if params[:label] && params[:label].downcase == "label" + params[:author] = params[:author].tr("@ ", "") if params[:author] + params_list = Hash[params.except(:commit, :utf8, :authenticity_token)] + redirect_to forumthreads_path(params_list) + end + private def check_permission diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 16f42d3..6b31d22 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,7 +4,7 @@ class UsersController < ApplicationController include MailerHelper include ERB::Util - before_filter :set_user, except: [:index, :new, :create, :lost_password, :reset_password, :suggestions] + before_filter :set_user, except: [:index, :new, :create, :lost_password, :reset_password, :suggestions, :search_redirect] def index if params[:role] @@ -13,7 +13,7 @@ class UsersController < ApplicationController else if role = Role.get(params[:role]) @users = User.joins(:role).where(role: role) - else + elsif params[:search] == nil flash[:alert] = "role '#{params[:role]}' does not exist!" redirect_to users_path return @@ -30,6 +30,7 @@ class UsersController < ApplicationController else @users = User.joins(:role).where.not(id: User.first.id) #Remove first user end + @users = User.search(@users, params[:search]) if params[:search] @users = @users.order("roles.value desc", "confirmed desc", :name) unless params[:badge] @count = @users.size @users = @users.page(params[:page]).per(100) @@ -339,6 +340,14 @@ class UsersController < ApplicationController end end + def search_redirect + params.each do |key, value| + params[key] = nil if params[key] == "" + end + params_list = Hash[params.except(:commit, :utf8, :authenticity_token)] + redirect_to users_path(params_list) + end + private def validate_token(uuid, email, token) diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index dbacf81..5e5649c 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -24,4 +24,4 @@ module MailerHelper end end end -end \ No newline at end of file +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 2ce1765..7ad99d8 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -52,4 +52,4 @@ module UsersHelper end end -end \ No newline at end of file +end diff --git a/app/models/forum.rb b/app/models/forum.rb index 39e8f2a..a239dbc 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -32,4 +32,4 @@ class Forum < ActiveRecord::Base def to_param [id, to_s.parameterize].join("-") end -end \ No newline at end of file +end diff --git a/app/models/forumthread.rb b/app/models/forumthread.rb index 905e4d3..86823ac 100644 --- a/app/models/forumthread.rb +++ b/app/models/forumthread.rb @@ -65,4 +65,47 @@ class Forumthread < ActiveRecord::Base def to_param [id, to_s.parameterize].join("-") end + + def self.filter (user, title, content, reply, label, author, query, forum) + userid = user.try(:id).to_i + role = user.try(:role).to_i + + can_read = "COALESCE(forum_role_read.value, 0) <= ? AND COALESCE(forumgroup_role_read.value, 0) <= ?" + sticky_can_write = "sticky = true AND (COALESCE(forum_role_write.value, 0) <= ? OR COALESCE(forumgroup_role_write.value, 0) <= ?)" + + threads = forum.try(:forumthreads) || Forumthread + threads = threads.where("forumthreads.user_author_id = ? OR (#{can_read}) OR (#{sticky_can_write})", userid, role, role, role, role) + .joins("LEFT JOIN threadreplies ON forumthreads.id = threadreplies.forumthread_id") + .joins(forum: :forumgroup) + .joins("LEFT JOIN roles as forum_role_read ON forums.role_read_id = forum_role_read.id") + .joins("LEFT JOIN roles as forum_role_write ON forums.role_write_id = forum_role_write.id") + .joins("LEFT JOIN roles as forumgroup_role_read ON forumgroups.role_read_id = forumgroup_role_read.id") + .joins("LEFT JOIN roles as forumgroup_role_write ON forumgroups.role_write_id = forumgroup_role_write.id") + + if [content, title, reply, label, author, query].any? + label_o = Label.find_by(name: label) + if label_o + threads = threads.where(label: label_o) + elsif label.try(:downcase) == "no label" + threads = threads.where(label: nil) + end + + threads = threads.where(user_author: author) if author + + if query + threads = threads.where("MATCH (title, forumthreads.content) AGAINST (?) OR MATCH (threadreplies.content) AGAINST (?)", query, query) + elsif [title, content, reply].any? + query = [title, content, reply].select(&:present?).join(" ") + threads = threads.where("MATCH (title) AGAINST (?)", title) if title + threads = threads.where("MATCH (forumthreads.content) AGAINST (?)", content) if content + threads = threads.where("MATCH (threadreplies.content) AGAINST (?)", reply) if reply + threads = threads.group("threadreplies.id", "forumthreads.id") + threads = threads.order("(MATCH (title, forumthreads.content) AGAINST ('#{query}')) DESC") + end + end + + threads = threads.order("sticky desc", "threadreplies.created_at desc", "forumthreads.created_at desc") if threads.order_values.empty? + + threads + end end diff --git a/app/models/role.rb b/app/models/role.rb index 708fb40..e780b8c 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -53,4 +53,4 @@ class Role < ActiveRecord::Base Role.order(:value).select {|r| r >= from}.select {|r| r <= to} end -end \ No newline at end of file +end diff --git a/app/models/user.rb b/app/models/user.rb index ab7471e..a96410a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -174,4 +174,8 @@ class User < ActiveRecord::Base def set_email_token self.email_token ||= SecureRandom.hex(16) end + + def self.search (users, search) + return users.where("users.name like ? OR ign like ?", "%#{User.send(:sanitize_sql_like, search)}%", "%#{User.send(:sanitize_sql_like, search)}%") + end end diff --git a/app/views/application/_md_editor_user.html.erb b/app/views/application/_md_editor_user.html.erb new file mode 100644 index 0000000..25f63a4 --- /dev/null +++ b/app/views/application/_md_editor_user.html.erb @@ -0,0 +1,8 @@ +
    +
    + <% options = (defined?(options) && options || {}) %> + <% options[:class] = "#{options[:class]} editor_field" %> + <% options[:placeholder] ||= "Enter user's name. Prefix with \"@\" to get suggestions." %> + <%= text_field_tag name, content, options %> +
    +
    diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index f09ea20..0a2fbaf 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -1,5 +1,7 @@ <% title "Forums" %> +<%= link_to "All threads", forumthreads_path(params.except("controller", "action")), class: "btn blue right" %> +
    <% @groups.each do |group| %>
    @@ -56,4 +58,4 @@ <%= link_to "New group", new_forumgroup_path, class: "btn blue" %> <% elsif mod? %> <%= link_to "New group", "#", class: "btn blue", disabled: true %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 60f3185..9dcdad8 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -1,8 +1,15 @@ <%= link_to @forum.group, forumgroup_path(@forum.group) %> → <%= @forum %> -

    <%= title @forum %>

    +

    + <%= title @forum %> + <% params[:id] = params[:id].split("-")[0] %> + <%= link_to "Search Threads", forumthreads_path(params.except("action", "controller")), class: "btn blue right" %> +

    <% if @forum.can_write?(current_user) %> -

    <%= link_to "New thread", new_forumthread_path(forum: @forum), class: "btn blue" %>

    +

    + <%= link_to "New thread", new_forumthread_path(forum: @forum), class: "btn blue" %> + <% params[:id] = params[:id].split("-")[0] %> +

    <% end %> <% if @forum.role_read && @forum.role_write && @forum.role_write < @forum.role_read %> @@ -51,4 +58,4 @@
    <% end %> <%= paginate @threads %> -
    \ No newline at end of file +
    diff --git a/app/views/forumthreads/index.html.erb b/app/views/forumthreads/index.html.erb new file mode 100644 index 0000000..d765cda --- /dev/null +++ b/app/views/forumthreads/index.html.erb @@ -0,0 +1,84 @@ +<%= link_to "Forums", forums_path %> → +<% if params.to_hash.slice("label", "title", "content", "author", "reply").size > 0 %> + <%= link_to "All Threads", forumthreads_path %> → Search Results +<% else %> + <%= "All Threads" %> +<% end %> +<% params_list = params.to_hash.slice("id", "query", "label", "title", "content", "author", "reply") %> +

    + <% if params[:id] %> + <% text = "forum '#{Forum.find(params[:id]).name}'" %> + <% else %> + <% text = "all threads" %> + <% end %> + <% if params_list.size > 0 %> + <%= title "Search results in #{text} (#{@threads.length})" %> + <% else %> + <% if params[:id] %> + <%= title "All threads in #{text}" %> + <% else %> + <%= title "All Threads" %> + <% end %> + <% end %> +
    + <%= link_to "Advanced Search", search_forumthreads_path(params_list), class: "btn right blue" %> + <% if params_list.size > 0 && params[:id] %> + <%= link_to "Show All Threads", forumthreads_path(params_list.except("id")), class: "btn right blue" %> + <% elsif params_list.size > 0 && !params[:id] %> + <%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %> + <% end %> + <% if params[:id] %> + <%= link_to "Go to Forum", forum_path(params[:id]), class: "btn right blue" %> + <% end %> +

    +
    +<%= form_tag({controller: "forumthreads", action: "search_redirect"}, method: :post, style: "margin:0px;height:40px") do %> + <%= text_field_tag "query", nil, placeholder: "Search...", style: "margin:0px;height:40px;width:300px" %> + <% params.each do |key, value| %> + <%= hidden_field_tag key, params[key] if params[key] && params[key] != params[:query] %> + <% end %> + <%= submit_tag "Go", class: "btn blue", style: "margin:0px;height:40px;width:40px" %> +<% end %> + +
    + <% counter = 0 %> + <% @threads.each do |thread| %> + <% counter += 1 %> +
    +
    + <%= link_to(thread.author.avatar(64), thread.author, title: thread.author.ign) %> + <%= render partial: "users/username", locals: { user: thread.author } %> + <%= link_to thread do %> + <%= ago thread.created_at %> + <% end %> + + <%= link_to pluralize(thread.replies.count, "Reply"), thread %> + +
    +
    +
    +
    "> + <%= render partial: "labels/label", locals: {label: thread.label} %><%= link_to truncate(thread.title, length: 60, omission: " …"), forumthread_path(thread), title: thread.title %> +
    + <% if rpl = thread.replies.last %> + <%= rpl.author.name %> + <% + position = thread.replies.count - 1 + page = position / Kaminari.config.default_per_page + 1 + %> + <%= link_to "replied", forumthread_path(thread, page: page) + "#reply-#{rpl.id}" %> + <%= ago rpl.created_at %>. + <% else %> + No replies yet. + <% end %> +
    +
    +
    +
    +
    + <% end %> + <% if counter == 0 %> +

    No results found

    + <% end %> + <%= paginate @threads %> +
    diff --git a/app/views/forumthreads/search.html.erb b/app/views/forumthreads/search.html.erb new file mode 100644 index 0000000..a3c631f --- /dev/null +++ b/app/views/forumthreads/search.html.erb @@ -0,0 +1,56 @@ +<% title "Thread Search" %> +

    Thread Search

    +

    Leave a field blank to ignore that search aspect.

    +<% label = Label.where(name: params[:label]).first %> + + +<%= form_tag({controller: "forumthreads", action: "search_redirect"}, method: :post) do %> + <% + forums = [] + Forum.all.sort_by{ |f| f.forumgroup && f.forumgroup.position || 0 }.each do |f| + if current_user != nil && current_user.role_id > f.role_read_id.to_i || current_user == nil && f.role_read_id == nil + forums << ["#{f.forumgroup.name} → #{f.name}", f.id] if f.forumgroup + end + end + %> + <% label_list = Label.pluck(:name).insert(0, "Label").insert(1, "No Label") %> + + + + + + + + + + + + + + + + + + + + + + + + + +<% end %> + +
    Forum<%= select_tag "id", options_for_select(["Search All Threads"] + forums, params[:id]) %>
    Label + <%= select_tag "label", options_for_select(label_list, params[:label]), class: "auto-width" %> +
    Title + <%= text_field_tag "title", params[:title], placeholder: "Search Titles" %> +
    Content + <%= text_field_tag "content", params[:content], placeholder: "Search Contents" %> +
    Author + <%= render partial: "md_editor_user", locals: {name: "author", content: params[:author]} %> +
    Replies + <%= text_field_tag "reply", params[:reply], placeholder: "Search Replies" %> +
    + <%= submit_tag "Go", class: "btn blue", style: "width:50px" %> +
    diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 95ab480..8df0fd0 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,14 +1,29 @@ +<%= form_tag({controller: "users", action: "search_redirect"}, method: :post, style: "margin:0px;height:40px") do %> + <%= text_field_tag "search", nil, placeholder: "Search for a user", style: "margin:0px;height:40px;width:300px" %> + <%= submit_tag "Go", class: "btn blue", style: "margin:0px;height:40px;width:40px" %> + <%= hidden_field_tag "role", params[:role] %> +<% end %> +

    - <% if params[:role] && !params[:badge]%> - <%= title "All '#{params[:role]}' users" %> - <% elsif params[:badge] && !params[:role] %> - <%= title "All '#{params[:badge]}' users" %> - <% elsif params[:role] && params[:badge] %> - <%= title "All '#{params[:role]}' and '#{params[:badge]}' users" %> + <% + if params[:role] && !params[:badge] + text = "All '#{params[:role]}' users" + elsif params[:badge] && !params[:role] + text = "All '#{params[:badge]}' users" + elsif params[:role] && params[:badge] + text = "All '#{params[:role]}' and '#{params[:badge]}' users" + else + text = "All users" + end + text += " that contain '#{params[:search]}'" if params[:search] + %> + <%= title text %> + <% if params[:search] %> + (<%= @users.select {|u| u.name.downcase.include?(params[:search].downcase) || u.ign.downcase.include?(params[:search].downcase) }.size %>) <% else %> - <%= title "All Users" %> + (<%= @count %>) <% end %> - (<%= @count %>) +

    <%= link_to "show all", users_path if params[:role] || params[:badge] %> diff --git a/config/routes.rb b/config/routes.rb index f79ab5b..4db3f30 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,14 +27,19 @@ Redstoner::Application.routes.draw do get 'lost_password' post 'reset_password' post 'suggestions' + post 'search_redirect' end end resources :forumgroups, path: '/forums/groups' - resources :forums, path: '/forums' resources :forumthreads, path: '/forums/threads' do resources :threadreplies, path: 'replies' + collection do + get 'search' + post 'search_redirect' + end end + resources :forums, path: '/forums' resources :tools do collection do diff --git a/db/migrate/20170522210610_add_search_indexes.rb b/db/migrate/20170522210610_add_search_indexes.rb new file mode 100644 index 0000000..2225d7b --- /dev/null +++ b/db/migrate/20170522210610_add_search_indexes.rb @@ -0,0 +1,8 @@ +class AddSearchIndexes < ActiveRecord::Migration + def change + add_index :forumthreads, [:title, :content], type: :fulltext + add_index :forumthreads, :title, type: :fulltext + add_index :forumthreads, :content, type: :fulltext + add_index :threadreplies, :content, type: :fulltext + end +end diff --git a/db/schema.rb b/db/schema.rb index 0a29b6b..aa35812 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170515200733) do +ActiveRecord::Schema.define(version: 20170522210610) do create_table "blogposts", force: :cascade do |t| t.string "title", limit: 191 @@ -65,6 +65,10 @@ ActiveRecord::Schema.define(version: 20170515200733) do t.integer "label_id", limit: 4 end + add_index "forumthreads", ["content"], name: "index_forumthreads_on_content", type: :fulltext + add_index "forumthreads", ["title", "content"], name: "index_forumthreads_on_title_and_content", type: :fulltext + add_index "forumthreads", ["title"], name: "index_forumthreads_on_title", type: :fulltext + create_table "info", force: :cascade do |t| t.string "title", limit: 191 t.text "content", limit: 65535 @@ -78,8 +82,8 @@ ActiveRecord::Schema.define(version: 20170515200733) do end create_table "register_tokens", force: :cascade do |t| - t.string "uuid", limit: 191, null: false - t.string "token", limit: 191, null: false + t.string "uuid", limit: 32, null: false + t.string "token", limit: 6, null: false t.string "email", limit: 191, null: false end @@ -116,6 +120,8 @@ ActiveRecord::Schema.define(version: 20170515200733) do t.datetime "updated_at" end + add_index "threadreplies", ["content"], name: "index_threadreplies_on_content", type: :fulltext + create_table "users", force: :cascade do |t| t.string "uuid", limit: 191, null: false t.string "name", limit: 191, null: false -- 2.52.0 From 0c3f6b222311b8936f6cdf5f71574666f26f4801 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 19:01:50 +0200 Subject: [PATCH 07/24] fixed action caching --- Gemfile | 2 +- app/controllers/statics_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index a277484..4216fe2 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ gem 'activerecord-session_store' gem 'highlight_js-rails', github: 'RedstonerServer/highlight_js-rails' gem 'kaminari', github: 'jomo/kaminari', branch: 'patch-2' # pagination gem 'jquery-textcomplete-rails', github: 'RedstonerServer/jquery-textcomplete-rails' # @mentions -gem 'actionpack-action_caching' +gem 'actionpack-action_caching', github: 'antulik/actionpack-action_caching', ref: '8c6e52c69315d67437f480da5dce4b7c8737fb32' # Gems used only for assets and not required # in production environments by default. diff --git a/app/controllers/statics_controller.rb b/app/controllers/statics_controller.rb index 70d3bd8..8ea9524 100644 --- a/app/controllers/statics_controller.rb +++ b/app/controllers/statics_controller.rb @@ -1,6 +1,6 @@ class StaticsController < ApplicationController - caches_action :online, expires_in: 10.seconds + caches_action :online, expires_in: 10.seconds, layout: false def index if current_user -- 2.52.0 From 0d5d69ac6efcf1e650452a8a67d2444257bf5ba5 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 19:06:20 +0200 Subject: [PATCH 08/24] Added CSS for index search fields and revised regex for author search --- app/assets/javascripts/editor.js | 42 +++++++++++++++++- app/assets/stylesheets/style.css.scss | 21 +++++++++ app/views/forumthreads/index.html.erb | 63 ++++++++++++++------------- app/views/users/index.html.erb | 17 ++++---- 4 files changed, 104 insertions(+), 39 deletions(-) diff --git a/app/assets/javascripts/editor.js b/app/assets/javascripts/editor.js index 4b35aea..c977571 100644 --- a/app/assets/javascripts/editor.js +++ b/app/assets/javascripts/editor.js @@ -88,5 +88,45 @@ $(function() { }], { debounce: 300 }); + $('.md_editor .field_container_user .editor_field').textcomplete([{ + // match up to 2 words (everything except some special characters) + // each word can have up to 16 characters (up to 32 total) + // words must be separated by a single space + match: /(^|\s)(([^!"§$%&\/()=?.,;+*@\s]{1,16} ?){0,1}[^!"§$%&\/()=?.,;+*@\s]{1,16})$/, + search: function (text, callback, match) { + console.log("Searching " + text); + text = text.toLowerCase(); + $.ajax("/users/suggestions", { + type: "post", + data: {name: text}, + dataType: "json", + headers: { + "X-CSRF-Token": $('meta[name="csrf-token"]').attr("content") + }, + success: function(data) { + callback(data); + }, + error: function(xhr, status, err) { + console.error(err); + callback([]); + } + }); + }, + template: function(user) { + var name = user[0]; + var ign = user[1]; + if (name != ign) { + return name + " (" + ign + ")"; + } else { + return ign; + } + }, + cache: true, + replace: function (word) { + return "$1" + word[1] + " "; + } + }], { + debounce: 300 + }); -}); \ No newline at end of file +}); diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss index 18042ad..73ab11f 100644 --- a/app/assets/stylesheets/style.css.scss +++ b/app/assets/stylesheets/style.css.scss @@ -489,6 +489,10 @@ blockquote p { padding: 4em 1em 1em; } } + .field_container_user { + .editor_field { + } + } } ul.dropdown-menu { @@ -1043,3 +1047,20 @@ nav.pagination { border-radius: 0.2em; text-shadow: none; } + +.searchfield { + margin:0px; + height:40px; + display: inline-block; + + .btn { + margin: 4px 1px 0 0; + padding: 6px; + cursor: default; + color: #fff; + border: none; + font-size: 12px; + line-height: normal; + background: #4096ee; + } +} diff --git a/app/views/forumthreads/index.html.erb b/app/views/forumthreads/index.html.erb index d765cda..f41d43d 100644 --- a/app/views/forumthreads/index.html.erb +++ b/app/views/forumthreads/index.html.erb @@ -1,49 +1,51 @@ <%= link_to "Forums", forums_path %> → -<% if params.to_hash.slice("label", "title", "content", "author", "reply").size > 0 %> +<% params_list = params.to_hash %> +<% if params_list.any? %> <%= link_to "All Threads", forumthreads_path %> → Search Results <% else %> <%= "All Threads" %> <% end %> -<% params_list = params.to_hash.slice("id", "query", "label", "title", "content", "author", "reply") %>

    - <% if params[:id] %> - <% text = "forum '#{Forum.find(params[:id]).name}'" %> - <% else %> - <% text = "all threads" %> - <% end %> - <% if params_list.size > 0 %> - <%= title "Search results in #{text} (#{@threads.length})" %> - <% else %> - <% if params[:id] %> - <%= title "All threads in #{text}" %> - <% else %> - <%= title "All Threads" %> - <% end %> - <% end %> + <% + if params[:id] + text = "forum '#{Forum.find(params[:id]).name}'" + if params_list.any? + text = "Search results in #{text} (#{@threads.length})" + else + text = text.capitalize + end + elsif params_list.any? + text = "Search results (#{@threads.length})" + else + text = "All threads" + end + %> + <%= title text %>
    <%= link_to "Advanced Search", search_forumthreads_path(params_list), class: "btn right blue" %> - <% if params_list.size > 0 && params[:id] %> - <%= link_to "Show All Threads", forumthreads_path(params_list.except("id")), class: "btn right blue" %> - <% elsif params_list.size > 0 && !params[:id] %> - <%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %> + <% if params_list.any? %> + <% if params[:id] %> + <%= link_to "Show All Threads", forumthreads_path(params_list.except("id")), class: "btn right blue" %> + <% else %> + <%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %> + <% end %> <% end %> <% if params[:id] %> <%= link_to "Go to Forum", forum_path(params[:id]), class: "btn right blue" %> <% end %>

    -
    -<%= form_tag({controller: "forumthreads", action: "search_redirect"}, method: :post, style: "margin:0px;height:40px") do %> - <%= text_field_tag "query", nil, placeholder: "Search...", style: "margin:0px;height:40px;width:300px" %> - <% params.each do |key, value| %> - <%= hidden_field_tag key, params[key] if params[key] && params[key] != params[:query] %> +
    + <%= form_tag({controller: "forumthreads", action: "index"}, method: :get, enforce_utf8: nil) do %> + <%= text_field_tag "query", params[:query], placeholder: "Search...", style: "width:300px" %> + <% params_list.compact.except("query").each do |key, value| %> + <%= hidden_field_tag key, params[key] %> + <% end %> + <%= submit_tag "Go", class: "searchfield btn", style: "width:40px", name: nil %> <% end %> - <%= submit_tag "Go", class: "btn blue", style: "margin:0px;height:40px;width:40px" %> -<% end %> +
    - <% counter = 0 %> <% @threads.each do |thread| %> - <% counter += 1 %>
    <%= link_to(thread.author.avatar(64), thread.author, title: thread.author.ign) %> @@ -77,7 +79,8 @@
    <% end %> - <% if counter == 0 %> + <% if @threads.empty? %> +

    No results found

    <% end %> <%= paginate @threads %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 8df0fd0..12e80ad 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,9 +1,11 @@ -<%= form_tag({controller: "users", action: "search_redirect"}, method: :post, style: "margin:0px;height:40px") do %> - <%= text_field_tag "search", nil, placeholder: "Search for a user", style: "margin:0px;height:40px;width:300px" %> - <%= submit_tag "Go", class: "btn blue", style: "margin:0px;height:40px;width:40px" %> - <%= hidden_field_tag "role", params[:role] %> -<% end %> - +
    + <%= form_tag({controller: "users", action: "index"}, method: :get, enforce_utf8: false) do %> + <%= text_field_tag "search", params[:search], placeholder: "Search for a user", style: "width:300px" %> + <%= submit_tag "Go", class: "searchfield btn", style: "width:40px", name: nil %> + <%= hidden_field_tag "role", params[:role] if params[:role] %> + <%= hidden_field_tag "badge", params[:badge] if params[:badge]%> + <% end %> +

    <% if params[:role] && !params[:badge] @@ -19,11 +21,10 @@ %> <%= title text %> <% if params[:search] %> - (<%= @users.select {|u| u.name.downcase.include?(params[:search].downcase) || u.ign.downcase.include?(params[:search].downcase) }.size %>) + (<%= @users.total_count %>) <% else %> (<%= @count %>) <% end %> -

    <%= link_to "show all", users_path if params[:role] || params[:badge] %> -- 2.52.0 From 887263d28ecb78ad49ec684c8dd1e9da252553d4 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 19:14:28 +0200 Subject: [PATCH 09/24] ordered searching to match SQL clauses, moved role&badge filtering to User.search --- app/controllers/forumthreads_controller.rb | 24 +++------ app/controllers/users_controller.rb | 38 ++----------- app/models/forumthread.rb | 63 +++++++++++----------- app/models/user.rb | 16 +++++- app/views/forumthreads/show.html.erb | 6 +-- 5 files changed, 56 insertions(+), 91 deletions(-) diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index e21c6d4..8827f89 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -3,16 +3,15 @@ class ForumthreadsController < ApplicationController before_filter :check_permission, only: [:show, :edit, :update, :destroy] def index - if params[:label] && !Label.where("lower(name) = ?", params[:label].downcase).try(:first) && params[:label].downcase != "no label" - flash[:alert] = "'#{params[:label]}' is not a valid label." - redirect_to forumthreads_path(params.except(:label, :controller, :action)) - return - end - @threads = Forumthread.filter(current_user, params[:title], params[:content], params[:reply], params[:label], User.where("lower(ign) = ?", params[:author].to_s.downcase).try(:first), params[:query], Forum.where(id: params[:id]).try(:first)) + params[:id] = nil if params[:id] && !Forum.find_by(id: params[:id]) + + params.each {|k,v| params[k] = nil if v==""} + + @threads = Forumthread.filter(current_user, params[:title], params[:content], params[:reply], params[:label], User.find_by(ign: params[:author].to_s.strip) || params[:author], params[:query], Forum.find_by(id: params[:id])) .page(params[:page]).per(30) end def show - if params[:reverse] + if params[:reverse] == "true" @replies = @thread.replies.reverse_order.page(params[:page]) else @replies = @thread.replies.page(params[:page]) @@ -88,17 +87,6 @@ class ForumthreadsController < ApplicationController def search end - def search_redirect - params.each do |key, value| - params[key] = nil if params[key] == "" - end - params[:id] = nil if params[:id] == "Search All Threads" - params[:label] = nil if params[:label] && params[:label].downcase == "label" - params[:author] = params[:author].tr("@ ", "") if params[:author] - params_list = Hash[params.except(:commit, :utf8, :authenticity_token)] - redirect_to forumthreads_path(params_list) - end - private def check_permission diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6b31d22..0a308c5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,33 +4,13 @@ class UsersController < ApplicationController include MailerHelper include ERB::Util - before_filter :set_user, except: [:index, :new, :create, :lost_password, :reset_password, :suggestions, :search_redirect] + before_filter :set_user, except: [:index, :new, :create, :lost_password, :reset_password, :suggestions] def index - if params[:role] - if params[:role].downcase == "staff" - @users = User.joins(:role).where("roles.value >= ?", Role.get(:mod).to_i) - else - if role = Role.get(params[:role]) - @users = User.joins(:role).where(role: role) - elsif params[:search] == nil - flash[:alert] = "role '#{params[:role]}' does not exist!" - redirect_to users_path - return - end - end - elsif params[:badge] - if badge = Badge.get(params[:badge]) - @users = User.joins(:badge).where(badge: badge) - else - flash[:alert] = "badge '#{params[:badge]}' does not exist!" - redirect_to users_path - return - end - else - @users = User.joins(:role).where.not(id: User.first.id) #Remove first user - end - @users = User.search(@users, params[:search]) if params[:search] + params[:role] = nil if !Role.find_by(name: params[:role]) + params[:badge] = nil if !Badge.find_by(name: params[:badge]) + + @users = User.search(params[:search], params[:role], params[:badge]) @users = @users.order("roles.value desc", "confirmed desc", :name) unless params[:badge] @count = @users.size @users = @users.page(params[:page]).per(100) @@ -340,14 +320,6 @@ class UsersController < ApplicationController end end - def search_redirect - params.each do |key, value| - params[key] = nil if params[key] == "" - end - params_list = Hash[params.except(:commit, :utf8, :authenticity_token)] - redirect_to users_path(params_list) - end - private def validate_token(uuid, email, token) diff --git a/app/models/forumthread.rb b/app/models/forumthread.rb index 86823ac..9650e28 100644 --- a/app/models/forumthread.rb +++ b/app/models/forumthread.rb @@ -67,45 +67,42 @@ class Forumthread < ActiveRecord::Base end def self.filter (user, title, content, reply, label, author, query, forum) - userid = user.try(:id).to_i - role = user.try(:role).to_i + order_phrase = query || [title, content, reply].select(&:present?).join(" ") + user_id = user.try(:id).to_i + role_value = user.try(:role).to_i + can_read = "COALESCE(forum_role_read.value, 0) <= ? AND COALESCE(forumgroup_role_read.value, 0) <= ?" + # A user can view sticky threads in write-only forums without read permissions. + sticky_can_write = "sticky = true AND (COALESCE(forum_role_write.value, 0) <= ? AND COALESCE(forumgroup_role_write.value, 0) <= ?)" + match = "MATCH (title, forumthreads.content) AGAINST (?) OR MATCH (threadreplies.content) AGAINST (?)" - can_read = "COALESCE(forum_role_read.value, 0) <= ? AND COALESCE(forumgroup_role_read.value, 0) <= ?" - sticky_can_write = "sticky = true AND (COALESCE(forum_role_write.value, 0) <= ? OR COALESCE(forumgroup_role_write.value, 0) <= ?)" + threads = forum.try(:forumthreads) || Forumthread - threads = forum.try(:forumthreads) || Forumthread - threads = threads.where("forumthreads.user_author_id = ? OR (#{can_read}) OR (#{sticky_can_write})", userid, role, role, role, role) - .joins("LEFT JOIN threadreplies ON forumthreads.id = threadreplies.forumthread_id") - .joins(forum: :forumgroup) - .joins("LEFT JOIN roles as forum_role_read ON forums.role_read_id = forum_role_read.id") - .joins("LEFT JOIN roles as forum_role_write ON forums.role_write_id = forum_role_write.id") - .joins("LEFT JOIN roles as forumgroup_role_read ON forumgroups.role_read_id = forumgroup_role_read.id") - .joins("LEFT JOIN roles as forumgroup_role_write ON forumgroups.role_write_id = forumgroup_role_write.id") + threads = threads.select("forumthreads.*", "(MATCH (title, forumthreads.content) AGAINST (#{Forumthread.sanitize(order_phrase)})) AS relevance", "(MATCH (threadreplies.content) AGAINST (#{Forumthread.sanitize(order_phrase)})) AS reply_rel") - if [content, title, reply, label, author, query].any? - label_o = Label.find_by(name: label) - if label_o - threads = threads.where(label: label_o) - elsif label.try(:downcase) == "no label" - threads = threads.where(label: nil) + threads = threads.joins(forum: :forumgroup) + .joins("LEFT JOIN threadreplies ON forumthreads.id = threadreplies.forumthread_id") + .joins("LEFT JOIN roles as forum_role_read ON forums.role_read_id = forum_role_read.id") + .joins("LEFT JOIN roles as forum_role_write ON forums.role_write_id = forum_role_write.id") + .joins("LEFT JOIN roles as forumgroup_role_read ON forumgroups.role_read_id = forumgroup_role_read.id") + .joins("LEFT JOIN roles as forumgroup_role_write ON forumgroups.role_write_id = forumgroup_role_write.id") + + threads = threads.where("forumthreads.user_author_id = ? OR (#{can_read}) OR (#{sticky_can_write})", user_id, role_value, role_value, role_value, role_value) + if query + threads = threads.where("#{match}", query[0..99], query[0..99]) + elsif [title, content, reply].any? + threads = threads.where("MATCH (title) AGAINST (?)", title[0..99]) if title + threads = threads.where("MATCH (forumthreads.content) AGAINST (?)", content[0..99]) if content + threads = threads.where("MATCH (threadreplies.content) AGAINST (?)", reply[0..99]) if reply + end + if label.try(:downcase) == "no label" + threads = threads.where(label: nil) + elsif l = Label.find_by(name: label) && label + threads = threads.where(label: l) end - threads = threads.where(user_author: author) if author - if query - threads = threads.where("MATCH (title, forumthreads.content) AGAINST (?) OR MATCH (threadreplies.content) AGAINST (?)", query, query) - elsif [title, content, reply].any? - query = [title, content, reply].select(&:present?).join(" ") - threads = threads.where("MATCH (title) AGAINST (?)", title) if title - threads = threads.where("MATCH (forumthreads.content) AGAINST (?)", content) if content - threads = threads.where("MATCH (threadreplies.content) AGAINST (?)", reply) if reply - threads = threads.group("threadreplies.id", "forumthreads.id") - threads = threads.order("(MATCH (title, forumthreads.content) AGAINST ('#{query}')) DESC") - end - end + threads = threads.group("forumthreads.id") - threads = threads.order("sticky desc", "threadreplies.created_at desc", "forumthreads.created_at desc") if threads.order_values.empty? - - threads + order_phrase.presence ? threads.order("GREATEST(relevance, reply_rel) DESC") : threads.order("sticky desc", "threadreplies.created_at DESC", "forumthreads.created_at DESC") end end diff --git a/app/models/user.rb b/app/models/user.rb index a96410a..3098cfc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -175,7 +175,19 @@ class User < ActiveRecord::Base self.email_token ||= SecureRandom.hex(16) end - def self.search (users, search) - return users.where("users.name like ? OR ign like ?", "%#{User.send(:sanitize_sql_like, search)}%", "%#{User.send(:sanitize_sql_like, search)}%") + def self.search (search, role, badge) + if role + if role.downcase == "staff" + users = User.joins(:role).where("roles.value >= ?", Role.get(:mod).to_i) + elsif r = Role.get(role) + users = User.joins(:role).where(role: r) + else + end + elsif badge && b = Badge.get(badge) + users = User.joins(:badge).where(badge: b) + else + users = User.joins(:role).where.not(id: User.first.id) #Remove first user + end + return users.where("users.name like ? OR ign like ?", "%#{User.send(:sanitize_sql_like, search.to_s)}%", "%#{User.send(:sanitize_sql_like, search.to_s)}%") end end diff --git a/app/views/forumthreads/show.html.erb b/app/views/forumthreads/show.html.erb index 82f8fb3..b29d29e 100644 --- a/app/views/forumthreads/show.html.erb +++ b/app/views/forumthreads/show.html.erb @@ -1,11 +1,7 @@ <%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %> → <%= link_to @thread.forum, @thread.forum %> → <%=truncate(@thread.title, length: 60, omission: " …") %>

    <%= render partial: "labels/label", locals: {label: @thread.label} %><%= title @thread.title %> - <% if params[:reverse] %> - <%= link_to "Reverse Replies", @thread, class: "btn right blue" %> - <% else %> - <%= link_to "Reverse Replies", forumthread_path(@thread, reverse: true), class: "btn right blue" %> - <% end %> + <%= link_to "Reverse Replies", forumthread_path(@thread, reverse: params[:reverse] != "true"), class: "btn right blue" %>

    -- 2.52.0 From 1398fcc01585c3b728c176640a52576a28fe0b5b Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 19:17:35 +0200 Subject: [PATCH 10/24] Updated find_by methods --- app/models/badge.rb | 4 ++-- app/models/comment.rb | 2 +- app/models/info.rb | 2 +- app/models/label.rb | 2 +- app/models/register_token.rb | 2 +- app/models/role.rb | 8 ++++---- app/models/threadreply.rb | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/models/badge.rb b/app/models/badge.rb index a7ff831..ee3de34 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -4,9 +4,9 @@ class Badge < ActiveRecord::Base def self.get (input) if input.is_a?(String) || input.is_a?(Symbol) - Badge.find_by_name(input) + Badge.find_by(name: input) elsif input.is_a?(Fixnum) - Badge.find_by_id(input) + Badge.find_by(id: input) elsif input.is_a?(Badge) return input end diff --git a/app/models/comment.rb b/app/models/comment.rb index 35a9a60..951d684 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -61,4 +61,4 @@ class Comment < ActiveRecord::Base background_mailer(mails) end -end \ No newline at end of file +end diff --git a/app/models/info.rb b/app/models/info.rb index b900ad0..cbfa1d3 100644 --- a/app/models/info.rb +++ b/app/models/info.rb @@ -11,4 +11,4 @@ class Info < ActiveRecord::Base [id, to_s.parameterize].join("-") end -end \ No newline at end of file +end diff --git a/app/models/label.rb b/app/models/label.rb index ee2fb56..d7cdc30 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -23,4 +23,4 @@ class Label < ActiveRecord::Base end end end -end \ No newline at end of file +end diff --git a/app/models/register_token.rb b/app/models/register_token.rb index 36c0cd1..5b956ff 100644 --- a/app/models/register_token.rb +++ b/app/models/register_token.rb @@ -1,2 +1,2 @@ class RegisterToken < ActiveRecord::Base -end \ No newline at end of file +end diff --git a/app/models/role.rb b/app/models/role.rb index e780b8c..5e5efa5 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -14,14 +14,14 @@ class Role < ActiveRecord::Base end def is? (name) - !!(Role.find_by_name(name) == self) + !!(Role.find_by(name: name) == self) end def self.get (input) if input.is_a?(String) || input.is_a?(Symbol) - Role.find_by_name(input) + Role.find_by(name: input) elsif input.is_a?(Fixnum) - Role.find_by_id(input) + Role.find_by(id: input) elsif input.is_a?(Role) return input end @@ -31,7 +31,7 @@ class Role < ActiveRecord::Base if role.is_a?(Role) self.value - role.value elsif role.is_a?(Symbol) - self <=> Role.find_by_name(role) + self <=> Role.find_by(name: role) else self.to_i <=> role end diff --git a/app/models/threadreply.rb b/app/models/threadreply.rb index 47b0d97..f285073 100644 --- a/app/models/threadreply.rb +++ b/app/models/threadreply.rb @@ -64,4 +64,4 @@ class Threadreply < ActiveRecord::Base end background_mailer(mails) end -end \ No newline at end of file +end -- 2.52.0 From fdc6ceabb6c0875d83d2dcebd886502b91d83a2b Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 19:22:04 +0200 Subject: [PATCH 11/24] removed passing of useless params, updated placeholder for user textcomplete --- app/views/application/_md_editor_user.html.erb | 2 +- app/views/forums/index.html.erb | 2 +- app/views/forums/show.html.erb | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/views/application/_md_editor_user.html.erb b/app/views/application/_md_editor_user.html.erb index 25f63a4..d799fce 100644 --- a/app/views/application/_md_editor_user.html.erb +++ b/app/views/application/_md_editor_user.html.erb @@ -2,7 +2,7 @@
    <% options = (defined?(options) && options || {}) %> <% options[:class] = "#{options[:class]} editor_field" %> - <% options[:placeholder] ||= "Enter user's name. Prefix with \"@\" to get suggestions." %> + <% options[:placeholder] ||= "Enter user's name." %> <%= text_field_tag name, content, options %>
    diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index 0a2fbaf..5d9449d 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -1,6 +1,6 @@ <% title "Forums" %> -<%= link_to "All threads", forumthreads_path(params.except("controller", "action")), class: "btn blue right" %> +<%= link_to "All threads", forumthreads_path, class: "btn blue right" %>
    <% @groups.each do |group| %> diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 9dcdad8..36741d9 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -2,13 +2,12 @@

    <%= title @forum %> - <% params[:id] = params[:id].split("-")[0] %> - <%= link_to "Search Threads", forumthreads_path(params.except("action", "controller")), class: "btn blue right" %> + <% params[:id] = @forum.id %> + <%= link_to "Search Threads", forumthreads_path(params.to_hash), class: "btn blue right" %>

    <% if @forum.can_write?(current_user) %>

    <%= link_to "New thread", new_forumthread_path(forum: @forum), class: "btn blue" %> - <% params[:id] = params[:id].split("-")[0] %>

    <% end %> -- 2.52.0 From 49ab2d07783b6bee96577902224908d52a014821 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 19:25:33 +0200 Subject: [PATCH 12/24] Removed all trace of search_redirect, included blanks for forum and label filters --- app/views/forumthreads/search.html.erb | 16 +++++++--------- app/views/threadreplies/_new.html.erb | 2 +- config/routes.rb | 3 +-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/views/forumthreads/search.html.erb b/app/views/forumthreads/search.html.erb index a3c631f..6db71a4 100644 --- a/app/views/forumthreads/search.html.erb +++ b/app/views/forumthreads/search.html.erb @@ -4,24 +4,22 @@ <% label = Label.where(name: params[:label]).first %> -<%= form_tag({controller: "forumthreads", action: "search_redirect"}, method: :post) do %> +<%= form_tag({controller: "forumthreads", action: "index"}, method: :get, enforce_utf8: false) do %> <% forums = [] - Forum.all.sort_by{ |f| f.forumgroup && f.forumgroup.position || 0 }.each do |f| - if current_user != nil && current_user.role_id > f.role_read_id.to_i || current_user == nil && f.role_read_id == nil - forums << ["#{f.forumgroup.name} → #{f.name}", f.id] if f.forumgroup - end + Forum.select{|f| f.can_read?(current_user)}.sort_by{ |f| f.forumgroup && f.forumgroup.position || 0 }.each do |f| + forums << ["#{f.forumgroup.name} → #{f.name}", f.id] if f.forumgroup end %> - <% label_list = Label.pluck(:name).insert(0, "Label").insert(1, "No Label") %> + <% label_list = Label.pluck(:name).prepend("No Label") %> - + @@ -48,7 +46,7 @@ <% end %> diff --git a/app/views/threadreplies/_new.html.erb b/app/views/threadreplies/_new.html.erb index 9d716d8..d1fc7d2 100644 --- a/app/views/threadreplies/_new.html.erb +++ b/app/views/threadreplies/_new.html.erb @@ -3,7 +3,7 @@ <% nec_msg = "" %> <% forum = Forum.find(reply.thread.forum_id) %> <% if forum.necro_length != nil %> - <% if Threadreply.where(forumthread: reply.thread).count != 0 %> + <% if Threadreply.where(forumthread: reply.thread).any? %> <% prevAgo = Threadreply.where(forumthread: reply.thread).order(:id).last.created_at %> <% if prevAgo <= forum.necro_length.days.ago.utc %> <% nec_msg = "You may be necroposting, as the last reply was made at least #{forum.necro_length} days ago. If you still wish to make this reply, press 'Ok'." %> diff --git a/config/routes.rb b/config/routes.rb index 4db3f30..5b35f95 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,12 +22,12 @@ Redstoner::Application.routes.draw do post 'resend_mail' get 'edit_notifications' put 'update_login' + get 'edit_website_settings' end collection do get 'lost_password' post 'reset_password' post 'suggestions' - post 'search_redirect' end end @@ -36,7 +36,6 @@ Redstoner::Application.routes.draw do resources :threadreplies, path: 'replies' collection do get 'search' - post 'search_redirect' end end resources :forums, path: '/forums' -- 2.52.0 From c20e57665c75e89c2760920c63e2cdf0376b93b7 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 19:31:15 +0200 Subject: [PATCH 13/24] Changed 'no badge' check to be more reliable, added rake task for creating superadmin users --- app/views/users/_username.html.erb | 2 +- db/migrate/20140617183701_create_roles.rb | 2 +- db/migrate/20140617183702_create_users.rb | 2 +- db/schema.rb | 26 +++++++++++------------ db/seeds.rb | 14 ------------ lib/tasks/create_admin_user.rake | 18 ++++++++++++++++ 6 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 lib/tasks/create_admin_user.rake diff --git a/app/views/users/_username.html.erb b/app/views/users/_username.html.erb index 4e78673..724e921 100644 --- a/app/views/users/_username.html.erb +++ b/app/views/users/_username.html.erb @@ -1,4 +1,4 @@
    <%= link_to user.name, user, class: "role #{user.role.name} #{"banned" if user.banned?} #{"disabled" if user.disabled?} #{"unconfirmed" unless user.confirmed?}", title: "#{user.ign} – #{user.role}", style: "color: #{fcolor(user.role.color)}; background-color: #{user.role.color}" %> - <%= link_to user.badge.symbol, users_path(badge: user.badge.name), class: "role badge", title: user.badge.name, style: "color: #{fcolor(user.badge.color)}; background-color: #{user.badge.color}" unless user.badge.value == 0 %> + <%= link_to user.badge.symbol, users_path(badge: user.badge.name), class: "role badge", title: user.badge.name, style: "color: #{fcolor(user.badge.color)}; background-color: #{user.badge.color}" unless user.badge.symbol.blank? %>
    diff --git a/db/migrate/20140617183701_create_roles.rb b/db/migrate/20140617183701_create_roles.rb index 3a25ea7..ad89207 100644 --- a/db/migrate/20140617183701_create_roles.rb +++ b/db/migrate/20140617183701_create_roles.rb @@ -5,4 +5,4 @@ class CreateRoles < ActiveRecord::Migration t.integer :value end end -end \ No newline at end of file +end diff --git a/db/migrate/20140617183702_create_users.rb b/db/migrate/20140617183702_create_users.rb index 1fefaf9..20e8a20 100644 --- a/db/migrate/20140617183702_create_users.rb +++ b/db/migrate/20140617183702_create_users.rb @@ -23,4 +23,4 @@ class CreateUsers < ActiveRecord::Migration t.timestamps null: true end end -end \ No newline at end of file +end diff --git a/db/schema.rb b/db/schema.rb index aa35812..916c41f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,6 +13,12 @@ ActiveRecord::Schema.define(version: 20170522210610) do + create_table "badges", force: :cascade do |t| + t.string "name", limit: 191 + t.string "symbol", limit: 191 + t.string "color", limit: 191 + end + create_table "blogposts", force: :cascade do |t| t.string "title", limit: 191 t.text "content", limit: 65535 @@ -44,7 +50,7 @@ ActiveRecord::Schema.define(version: 20170522210610) do t.integer "role_read_id", limit: 4 t.integer "role_write_id", limit: 4 t.integer "forumgroup_id", limit: 4 - t.integer "necro_length", limit: 4, default: -1 + t.integer "necro_length", limit: 4 end create_table "forums_labels", id: false, force: :cascade do |t| @@ -95,12 +101,6 @@ ActiveRecord::Schema.define(version: 20170522210610) do t.string "color", limit: 191 end - create_table "badges", force: :cascade do |t| - t.string "name" - t.string "symbol" - t.string "color" - end - create_table "sessions", force: :cascade do |t| t.string "session_id", limit: 191, null: false t.text "data", limit: 65535 @@ -132,14 +132,13 @@ ActiveRecord::Schema.define(version: 20170522210610) do t.string "last_ip", limit: 191 t.string "skype", limit: 191 t.boolean "skype_public", default: false - t.string "youtube" - t.string "youtube_channelname" - t.string "twitter" - t.string "email_token" + t.string "youtube", limit: 191 + t.string "youtube_channelname", limit: 191 + t.string "twitter", limit: 191 + t.string "email_token", limit: 191 t.boolean "confirmed", default: false t.datetime "last_seen" t.integer "role_id", limit: 4, null: false - t.integer "badge_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "mail_own_thread_reply", default: true @@ -147,8 +146,9 @@ ActiveRecord::Schema.define(version: 20170522210610) do t.boolean "mail_own_blogpost_comment", default: true t.boolean "mail_other_blogpost_comment", default: true t.boolean "mail_mention", default: true - t.boolean "header_scroll", default: false + t.integer "badge_id", limit: 4, default: 0 t.boolean "utc_time", default: false + t.boolean "header_scroll", default: false t.boolean "dark", default: false end diff --git a/db/seeds.rb b/db/seeds.rb index 7b7530d..926d7b2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -42,17 +42,3 @@ deleted_user = User.create!( dark: false ) deleted_user.update_attribute(:ign, "Steve") - -User.create!( - uuid: "ae795aa86327408e92ab25c8a59f3ba1", - ign: "jomo", - email: "jomo@example.com", - password: "123456789", # high seructity! - password_confirmation: "123456789", - role: Role.get(:superadmin), - header_scroll: false, - utc_time: false, - dark: false - badge: Badge.get(:donor), - confirmed: true -) diff --git a/lib/tasks/create_admin_user.rake b/lib/tasks/create_admin_user.rake new file mode 100644 index 0000000..28b7e9f --- /dev/null +++ b/lib/tasks/create_admin_user.rake @@ -0,0 +1,18 @@ +desc "Creates a superadmin user. Usage: rake create:create_admin_user[uuid, ign, email, pass]" +namespace :create do + task :create_admin_user, [:uuid, :ign, :email, :pass] => :environment do |task, args| + User.create!( + uuid: args.uuid, + ign: args.ign, + email: args.email, + password: args.pass, + password_confirmation: args.pass, + role: Role.get(:superadmin), + header_scroll: false, + utc_time: false, + dark: false, + badge: Badge.get(:donor), + confirmed: true + ) + end +end -- 2.52.0 From 4c0ceb5882ec101474f79a596f44ad3e8993620b Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 19:34:06 +0200 Subject: [PATCH 14/24] badge migration now contains default badges and creation of badge table --- db/migrate/20170319193517_add_badge_id_to_users.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/db/migrate/20170319193517_add_badge_id_to_users.rb b/db/migrate/20170319193517_add_badge_id_to_users.rb index 08328cf..4e9d7ed 100644 --- a/db/migrate/20170319193517_add_badge_id_to_users.rb +++ b/db/migrate/20170319193517_add_badge_id_to_users.rb @@ -1,8 +1,16 @@ class AddBadgeIdToUsers < ActiveRecord::Migration def change - add_column :users, :badge_id, :integer + + create_table "badges", force: :cascade do |t| + t.string "name" + t.string "symbol" + t.string "color" + end + + dbadge = Badge.create!({name: "donor", symbol: "$", color: "#f60"}) + add_column :users, :badge_id, :integer, default: 0 - User.where(donor: true).update_all(badge_id: 1) + User.where(donor: true).update_all(badge_id: dbadge.id) remove_column :users, :donor end end -- 2.52.0 From bdab104ab89d5466d98051f501c51282b99b15e8 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Wed, 31 May 2017 21:44:22 +0200 Subject: [PATCH 15/24] Changed 'Who's Playing' code to handle revised JSON format --- app/controllers/statics_controller.rb | 5 +++-- app/views/statics/online.html.erb | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/statics_controller.rb b/app/controllers/statics_controller.rb index 8ea9524..4b0c911 100644 --- a/app/controllers/statics_controller.rb +++ b/app/controllers/statics_controller.rb @@ -17,7 +17,8 @@ class StaticsController < ApplicationController end def online - @players = JSON.parse(File.read("/etc/minecraft/redstoner/plugins/JavaUtils/players.json"))["players"] - @players.collect!{ |p| User.find_by(uuid: p["uuid"].tr("-", "")) or User.new(name: p["name"], ign: p["name"], uuid: p["uuid"].tr("-", ""), role: Role.get("normal"), confirmed: true) }.sort_by!(&:role).reverse! + json = JSON.parse(File.read("/etc/minecraft/redstoner/plugins/JavaUtils/players.json")) + @players = json["players"].collect!{ |p| User.find_by(uuid: p["UUID"].tr("-", "")) or User.new(name: p["name"], ign: p["name"], uuid: p["UUID"].tr("-", ""), role: Role.get("normal"), badge: Badge.get("none"), confirmed: true) }.sort_by!(&:role).reverse! + @count = json["amount"] end end diff --git a/app/views/statics/online.html.erb b/app/views/statics/online.html.erb index 8c31182..8bacf6f 100644 --- a/app/views/statics/online.html.erb +++ b/app/views/statics/online.html.erb @@ -1,14 +1,15 @@ <% title "Who's Playing?" %> -

    These players are currently playing on Redstoner:

    +

    These players are currently playing on Redstoner (<%= @count %>):

    <% @players.each do |u| %>
    <%= link_to(u.avatar(64), u) %>
    <%= render partial: "users/username", locals: { user: u } %>
    - <%= u.ign %> - <% unless u.id %> -
    (Not signed up) + <% if u.id %> + <%= u.ign %> + <% else %> + (Not signed up) <% end %>
    -- 2.52.0 From a658852e86e04903aed1628870f71c498d46a537 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Wed, 31 May 2017 22:00:22 +0200 Subject: [PATCH 16/24] Added Donator+ perk (/lol id) to the 'Donate' page and fixed spelling error on signup page ('singing' => 'signing') --- app/views/statics/donate.html.erb | 1 + app/views/users/new.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/statics/donate.html.erb b/app/views/statics/donate.html.erb index 774d917..2ca7114 100644 --- a/app/views/statics/donate.html.erb +++ b/app/views/statics/donate.html.erb @@ -19,6 +19,7 @@
  • The warm feeling of donating for a good thing, plus a huge "thank you"!
  • You can have a nickname. See <%= link_to "our nickname guidelines", info_path("12-nickname-guidelines") %>
  • A "$" next to your name (Including website) +
  • Donator+ has access to the in-game command /lol id

  • diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index c482df9..1d8a8c6 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -40,5 +40,5 @@ <%= f.submit "Sign up", class: "btn blue" %> -

    Contact us ingame if you have problems singing up!

    -<% end %> \ No newline at end of file +

    Contact us ingame if you have problems signing up!

    +<% end %> -- 2.52.0 From a1ade53445a7a84f51ff4d1c0f215f8695191e8a Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 02:10:49 +0200 Subject: [PATCH 17/24] moved all search styling to CSS, removed friendly (but slow) URLs, moved WHERE strings into an array --- app/assets/javascripts/editor.js | 2 +- app/assets/stylesheets/style.css.scss | 11 +- app/controllers/#forumthreads_controller.rb# | 106 +++++++++++++++++++ app/controllers/forumthreads_controller.rb | 6 +- app/controllers/users_controller.rb | 6 +- app/models/forumthread.rb | 21 ++-- app/models/user.rb | 17 +-- app/views/forums/show.html.erb | 3 +- app/views/forumthreads/index.html.erb | 44 ++++---- app/views/forumthreads/search.html.erb | 4 +- 10 files changed, 164 insertions(+), 56 deletions(-) create mode 100644 app/controllers/#forumthreads_controller.rb# diff --git a/app/assets/javascripts/editor.js b/app/assets/javascripts/editor.js index c977571..4f4de5d 100644 --- a/app/assets/javascripts/editor.js +++ b/app/assets/javascripts/editor.js @@ -92,7 +92,7 @@ $(function() { // match up to 2 words (everything except some special characters) // each word can have up to 16 characters (up to 32 total) // words must be separated by a single space - match: /(^|\s)(([^!"§$%&\/()=?.,;+*@\s]{1,16} ?){0,1}[^!"§$%&\/()=?.,;+*@\s]{1,16})$/, + match: /(^|\s)([^!"§$%&\/()=?.,;+*@\s]{1,16})$/, search: function (text, callback, match) { console.log("Searching " + text); text = text.toLowerCase(); diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss index 73ab11f..f8d1d8e 100644 --- a/app/assets/stylesheets/style.css.scss +++ b/app/assets/stylesheets/style.css.scss @@ -1049,18 +1049,17 @@ nav.pagination { } .searchfield { - margin:0px; height:40px; display: inline-block; - - .btn { + &.field { + width: 300px; + } + &.btn { margin: 4px 1px 0 0; - padding: 6px; cursor: default; color: #fff; - border: none; font-size: 12px; - line-height: normal; background: #4096ee; + width: 40px; } } diff --git a/app/controllers/#forumthreads_controller.rb# b/app/controllers/#forumthreads_controller.rb# new file mode 100644 index 0000000..1b43f15 --- /dev/null +++ b/app/controllers/#forumthreads_controller.rb# @@ -0,0 +1,106 @@ +class ForumthreadsController < ApplicationController + + before_filter :check_permission, only: [:show, :edit, :update, :destroy] + + def index + params[:id] = nil if params[:id] && !Forum.find_by(id: params[:id]) + + params.each {|k,v| params[k] = nil if v==""} + +c @threads = Forumthread.filter(current_user, params[:title], params[:content], params[:reply], params[:label], User.find_by(ign: params[:author].to_s.strip) || params[:author], params[:query], Forum.find_by(id: params[:id])) + .page(params[:page]).per(30) + end + def show + if params[:reverse] == "true" + @replies = @thread.replies.reverse_order.page(params[:page]) + else + @replies = @thread.replies.page(params[:page]) + end + end + + def edit + unless mod? || @thread.author.is?(current_user) + flash[:alert] = "You are not allowed to edit this thread!" + redirect_to @thread + end + end + + def new + @thread = Forumthread.new(forum: Forum.find(params[:forum])) + unless @thread.forum.can_write?(current_user) + flash[:alert] = "You are not allowed to write in this forum" + redirect_to forums_path + end + end + + def create + @thread = Forumthread.new(mod? ? thread_params([:sticky, :locked, :forum_id, :label_id]) : thread_params([:forum_id, :label_id])) + if @thread.forum.can_write?(current_user) + @thread.user_author = current_user + if @thread.save + @thread.send_new_mention_mail + flash[:notice] = "Thread created!" + redirect_to forumthread_path( @thread) + return + else + flash[:alert] = "Something went wrong while creating your thread." + render action: "new" + return + end + else + flash[:alert] = "You are not allowed to create a thread here!" + redirect_to @thread.forum + end + end + + def update + if mod? || @thread.author.is?(current_user) + @thread.user_editor = current_user + @thread.attributes = (mod? ? thread_params([:sticky, :locked, :forum_id, :label_id]) : thread_params) + old_content = @thread.content_was + if @thread.save + @thread.send_new_mention_mail(old_content) + redirect_to @thread, notice: 'Post has been updated.' + else + flash[:alert] = "There was a problem while updating the post" + render action: "edit" + end + else + flash[:alert] = "You are not allowed to edit this thread!" + redirect_to @thread + end + end + + def destroy + if mod? || @thread.author.is?(current_user) + if @thread.destroy + flash[:notice] = "Thread deleted!" + else + flash[:alert] = "There was a problem while deleting this thread" + end + else + flash[:alert] = "You are not allowed to delete this thread" + end + redirect_to @thread.forum + end + + def search + end + + private + + def check_permission + @thread = Forumthread.find(params[:id]) + unless @thread.can_read?(current_user) + flash[:alert] = "You are not allowed to view this thread" + redirect_to forums_path + end + end + + def thread_params(add = []) + a = [:title, :content] + a << :label_id if @thread && !@thread.locked? + a += add + params.require(:forumthread).permit(a) + end +end diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index 8827f89..81d420a 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -3,11 +3,11 @@ class ForumthreadsController < ApplicationController before_filter :check_permission, only: [:show, :edit, :update, :destroy] def index - params[:id] = nil if params[:id] && !Forum.find_by(id: params[:id]) + params[:forum] = nil if params[:forum] && !Forum.find_by(id: params[:forum]) - params.each {|k,v| params[k] = nil if v==""} + params.delete_if{|k,v| v.blank?} - @threads = Forumthread.filter(current_user, params[:title], params[:content], params[:reply], params[:label], User.find_by(ign: params[:author].to_s.strip) || params[:author], params[:query], Forum.find_by(id: params[:id])) + @threads = Forumthread.filter(current_user, params[:title].try(:slice, 0..255), params[:content].try(:slice, 0..255), params[:reply].try(:slice, 0..255), params[:label], User.find_by(ign: params[:author].to_s.strip) || params[:author], params[:query].try(:slice, 0..255), Forum.find_by(id: params[:forum])) .page(params[:page]).per(30) end def show diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0a308c5..60011a2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,10 +7,10 @@ class UsersController < ApplicationController before_filter :set_user, except: [:index, :new, :create, :lost_password, :reset_password, :suggestions] def index - params[:role] = nil if !Role.find_by(name: params[:role]) - params[:badge] = nil if !Badge.find_by(name: params[:badge]) + role = Role.find_by(name: params[:role]) unless role.try(:downcase) == "staff" + badge = Badge.find_by(name: params[:badge]) - @users = User.search(params[:search], params[:role], params[:badge]) + @users = User.search(params[:search], role, badge) @users = @users.order("roles.value desc", "confirmed desc", :name) unless params[:badge] @count = @users.size @users = @users.page(params[:page]).per(100) diff --git a/app/models/forumthread.rb b/app/models/forumthread.rb index 9650e28..f8efe97 100644 --- a/app/models/forumthread.rb +++ b/app/models/forumthread.rb @@ -73,11 +73,11 @@ class Forumthread < ActiveRecord::Base can_read = "COALESCE(forum_role_read.value, 0) <= ? AND COALESCE(forumgroup_role_read.value, 0) <= ?" # A user can view sticky threads in write-only forums without read permissions. sticky_can_write = "sticky = true AND (COALESCE(forum_role_write.value, 0) <= ? AND COALESCE(forumgroup_role_write.value, 0) <= ?)" - match = "MATCH (title, forumthreads.content) AGAINST (?) OR MATCH (threadreplies.content) AGAINST (?)" + match = ["MATCH (title, forumthreads.content) AGAINST (#{Forumthread.sanitize(order_phrase)})", "MATCH (threadreplies.content) AGAINST (#{Forumthread.sanitize(order_phrase)})", "MATCH (title, forumthreads.content) AGAINST (?) OR MATCH (threadreplies.content) AGAINST (?)", "MATCH (title) AGAINST (?)", "MATCH (forumthreads.content) AGAINST (?)", "MATCH (threadreplies.content) AGAINST (?)"] threads = forum.try(:forumthreads) || Forumthread - threads = threads.select("forumthreads.*", "(MATCH (title, forumthreads.content) AGAINST (#{Forumthread.sanitize(order_phrase)})) AS relevance", "(MATCH (threadreplies.content) AGAINST (#{Forumthread.sanitize(order_phrase)})) AS reply_rel") + threads = threads.select("forumthreads.*", "#{match[0]} AS relevance", "#{match[1]} AS reply_rel") threads = threads.joins(forum: :forumgroup) .joins("LEFT JOIN threadreplies ON forumthreads.id = threadreplies.forumthread_id") @@ -88,21 +88,26 @@ class Forumthread < ActiveRecord::Base threads = threads.where("forumthreads.user_author_id = ? OR (#{can_read}) OR (#{sticky_can_write})", user_id, role_value, role_value, role_value, role_value) if query - threads = threads.where("#{match}", query[0..99], query[0..99]) + threads = threads.where("#{match[2]}", query[0..99], query[0..99]) elsif [title, content, reply].any? - threads = threads.where("MATCH (title) AGAINST (?)", title[0..99]) if title - threads = threads.where("MATCH (forumthreads.content) AGAINST (?)", content[0..99]) if content - threads = threads.where("MATCH (threadreplies.content) AGAINST (?)", reply[0..99]) if reply + threads = threads.where("#{match[3]}", title[0..99]) if title + threads = threads.where("#{match[4]}", content[0..99]) if content + threads = threads.where("#{match[5]}", reply[0..99]) if reply end if label.try(:downcase) == "no label" threads = threads.where(label: nil) - elsif l = Label.find_by(name: label) && label + elsif label && l = Label.find_by(name: label) threads = threads.where(label: l) end threads = threads.where(user_author: author) if author threads = threads.group("forumthreads.id") - order_phrase.presence ? threads.order("GREATEST(relevance, reply_rel) DESC") : threads.order("sticky desc", "threadreplies.created_at DESC", "forumthreads.created_at DESC") + if order_phrase.present? + threads = threads.order("GREATEST(relevance, reply_rel) DESC") + else + threads = threads.order("sticky desc", "threadreplies.created_at DESC", "forumthreads.created_at DESC") + end + threads end end diff --git a/app/models/user.rb b/app/models/user.rb index 3098cfc..ff09c70 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -177,17 +177,18 @@ class User < ActiveRecord::Base def self.search (search, role, badge) if role - if role.downcase == "staff" + if role.try(:downcase) == "staff" users = User.joins(:role).where("roles.value >= ?", Role.get(:mod).to_i) - elsif r = Role.get(role) - users = User.joins(:role).where(role: r) else + users = User.joins(:role).where(role: role) end - elsif badge && b = Badge.get(badge) - users = User.joins(:badge).where(badge: b) - else - users = User.joins(:role).where.not(id: User.first.id) #Remove first user end - return users.where("users.name like ? OR ign like ?", "%#{User.send(:sanitize_sql_like, search.to_s)}%", "%#{User.send(:sanitize_sql_like, search.to_s)}%") + if badge + users = User.joins(:badge).where(badge: badge) + else + users = User.joins(:role).all.where.not(id: User.first.id) + end + search_san = User.send(:sanitize_sql_like, search.to_s) + users.where("users.name like ? OR ign like ?", "%#{search_san}%", "%#{search_san}%") end end diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 36741d9..b232292 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -2,8 +2,7 @@

    <%= title @forum %> - <% params[:id] = @forum.id %> - <%= link_to "Search Threads", forumthreads_path(params.to_hash), class: "btn blue right" %> + <%= link_to "Search Threads", forumthreads_path(forum: @forum.id), class: "btn blue right" %>

    <% if @forum.can_write?(current_user) %>

    diff --git a/app/views/forumthreads/index.html.erb b/app/views/forumthreads/index.html.erb index f41d43d..3a0493b 100644 --- a/app/views/forumthreads/index.html.erb +++ b/app/views/forumthreads/index.html.erb @@ -7,8 +7,8 @@ <% end %>

    <% - if params[:id] - text = "forum '#{Forum.find(params[:id]).name}'" + if params[:forum] + text = "forum '#{Forum.find(params[:forum]).name}'" if params_list.any? text = "Search results in #{text} (#{@threads.length})" else @@ -21,29 +21,27 @@ end %> <%= title text %> -
    - <%= link_to "Advanced Search", search_forumthreads_path(params_list), class: "btn right blue" %> - <% if params_list.any? %> - <% if params[:id] %> - <%= link_to "Show All Threads", forumthreads_path(params_list.except("id")), class: "btn right blue" %> - <% else %> - <%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %> - <% end %> - <% end %> - <% if params[:id] %> - <%= link_to "Go to Forum", forum_path(params[:id]), class: "btn right blue" %> - <% end %>

    -
    - <%= form_tag({controller: "forumthreads", action: "index"}, method: :get, enforce_utf8: nil) do %> - <%= text_field_tag "query", params[:query], placeholder: "Search...", style: "width:300px" %> - <% params_list.compact.except("query").each do |key, value| %> - <%= hidden_field_tag key, params[key] %> - <% end %> - <%= submit_tag "Go", class: "searchfield btn", style: "width:40px", name: nil %> +
    +<%= form_tag(forumthreads_path, method: :get) do %> + <%= text_field_tag "query", params[:query], placeholder: "Search...", class: "searchfield field" %> + <%= submit_tag "Go", class: "searchfield btn" %> + <% params.slice(:title, :content, :reply, :label, :author).each do |key, value| %> + <%= hidden_field_tag key, params[key] %> <% end %> -
    - +<% end %> +<%= link_to "Advanced Search", search_forumthreads_path(params_list), class: "btn right blue" %> +<% if params_list.any? %> + <% if params[:forum] %> + <%= link_to "Show All Threads", forumthreads_path(params_list.except("forum")), class: "btn right blue" %> + <% elsif params_list.except(:controller, :action).any? %> + <%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %> + <% end %> +<% end %> +<% if params[:forum] %> + <%= link_to "Go to Forum", forum_path(params[:forum]), class: "btn right blue" %> +<% end %> +
    <% @threads.each do |thread| %>
    diff --git a/app/views/forumthreads/search.html.erb b/app/views/forumthreads/search.html.erb index 6db71a4..125868a 100644 --- a/app/views/forumthreads/search.html.erb +++ b/app/views/forumthreads/search.html.erb @@ -4,7 +4,7 @@ <% label = Label.where(name: params[:label]).first %>
    Forum<%= select_tag "id", options_for_select(["Search All Threads"] + forums, params[:id]) %><%= select_tag "id", options_for_select(forums, params[:id]), include_blank: "Search All Threads" %>
    Label - <%= select_tag "label", options_for_select(label_list, params[:label]), class: "auto-width" %> + <%= select_tag "label", options_for_select(label_list, params[:label]), include_blank: "Label" %>
    - <%= submit_tag "Go", class: "btn blue", style: "width:50px" %> + <%= submit_tag "Go", class: "btn blue", style: "width:50px", name: nil %>
    -<%= form_tag({controller: "forumthreads", action: "index"}, method: :get, enforce_utf8: false) do %> +<%= form_tag(forumthreads_path, method: :get) do %> <% forums = [] Forum.select{|f| f.can_read?(current_user)}.sort_by{ |f| f.forumgroup && f.forumgroup.position || 0 }.each do |f| @@ -14,7 +14,7 @@ <% label_list = Label.pluck(:name).prepend("No Label") %> - + -- 2.52.0 From 7d3ad5cde6b9c3662830656e5efd387adc6a8e46 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 18:19:06 +0200 Subject: [PATCH 18/24] allowed role and badge filtering, made User.search take Role and Badge as params --- app/controllers/users_controller.rb | 5 ++--- app/models/user.rb | 12 +++++++++--- app/views/users/index.html.erb | 14 ++++++-------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 60011a2..dd12a98 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,11 +7,10 @@ class UsersController < ApplicationController before_filter :set_user, except: [:index, :new, :create, :lost_password, :reset_password, :suggestions] def index - role = Role.find_by(name: params[:role]) unless role.try(:downcase) == "staff" + role = Role.find_by(name: params[:role]) badge = Badge.find_by(name: params[:badge]) - @users = User.search(params[:search], role, badge) - @users = @users.order("roles.value desc", "confirmed desc", :name) unless params[:badge] + @users = User.search(params[:search], role, badge, params[:staff]) @count = @users.size @users = @users.page(params[:page]).per(100) end diff --git a/app/models/user.rb b/app/models/user.rb index ff09c70..24e7a2d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -151,6 +151,10 @@ class User < ActiveRecord::Base self.role ||= Role.get(:normal) end + def set_badge + self.badge ||= Badge.get(:none) + end + def set_uuid if !self.uuid.present? # idk @@ -175,9 +179,9 @@ class User < ActiveRecord::Base self.email_token ||= SecureRandom.hex(16) end - def self.search (search, role, badge) + def self.search (search, role, badge, staff) if role - if role.try(:downcase) == "staff" + if staff users = User.joins(:role).where("roles.value >= ?", Role.get(:mod).to_i) else users = User.joins(:role).where(role: role) @@ -189,6 +193,8 @@ class User < ActiveRecord::Base users = User.joins(:role).all.where.not(id: User.first.id) end search_san = User.send(:sanitize_sql_like, search.to_s) - users.where("users.name like ? OR ign like ?", "%#{search_san}%", "%#{search_san}%") + users = users.where("users.name like ? OR ign like ?", "%#{search_san}%", "%#{search_san}%") + users = users.order("roles.value desc", "confirmed desc", :name) unless badge + users end end diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 12e80ad..05e9249 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,11 +1,9 @@ -
    - <%= form_tag({controller: "users", action: "index"}, method: :get, enforce_utf8: false) do %> - <%= text_field_tag "search", params[:search], placeholder: "Search for a user", style: "width:300px" %> - <%= submit_tag "Go", class: "searchfield btn", style: "width:40px", name: nil %> - <%= hidden_field_tag "role", params[:role] if params[:role] %> - <%= hidden_field_tag "badge", params[:badge] if params[:badge]%> - <% end %> -
    +<%= form_tag(users_path, method: :get) do %> + <%= text_field_tag "search", params[:search], placeholder: "Search for a user", class: "searchfield field" %> + <%= submit_tag "Go", class: "searchfield btn", name: nil %> + <%= hidden_field_tag "role", params[:role] if params[:role] %> + <%= hidden_field_tag "badge", params[:badge] if params[:badge]%> +<% end %>

    <% if params[:role] && !params[:badge] -- 2.52.0 From 00254ebf51298acd75d0d6f32344bab57fbefad3 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 18:26:48 +0200 Subject: [PATCH 19/24] Addded default badge 'none' and enforced badges --- app/models/user.rb | 2 +- db/migrate/20170319193517_add_badge_id_to_users.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 24e7a2d..52b7130 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,7 +9,7 @@ class User < ActiveRecord::Base has_secure_password - before_validation :strip_whitespaces, :set_uuid, :set_name, :set_email_token, :set_role + before_validation :strip_whitespaces, :set_uuid, :set_name, :set_email_token, :set_role, :set_badge validates_presence_of :password, :password_confirmation, :email_token, on: :create validates_presence_of :name, :email, :ign diff --git a/db/migrate/20170319193517_add_badge_id_to_users.rb b/db/migrate/20170319193517_add_badge_id_to_users.rb index 4e9d7ed..19b58de 100644 --- a/db/migrate/20170319193517_add_badge_id_to_users.rb +++ b/db/migrate/20170319193517_add_badge_id_to_users.rb @@ -7,6 +7,7 @@ class AddBadgeIdToUsers < ActiveRecord::Migration t.string "color" end + Badge.create!({name: "none", symbol: "", color: "#000"}) dbadge = Badge.create!({name: "donor", symbol: "$", color: "#f60"}) add_column :users, :badge_id, :integer, default: 0 -- 2.52.0 From b73b4cd1bc75768e15a96b2102c79addc6086f62 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 18:30:51 +0200 Subject: [PATCH 20/24] Made the default badge of 'create_admin_user' none --- lib/tasks/create_admin_user.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/create_admin_user.rake b/lib/tasks/create_admin_user.rake index 28b7e9f..22dceb3 100644 --- a/lib/tasks/create_admin_user.rake +++ b/lib/tasks/create_admin_user.rake @@ -11,7 +11,7 @@ namespace :create do header_scroll: false, utc_time: false, dark: false, - badge: Badge.get(:donor), + badge: Badge.get(:none), confirmed: true ) end -- 2.52.0 From d4159d886f5d78193ab56873df20f7c8935906c0 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 2 Jun 2017 18:39:20 +0200 Subject: [PATCH 21/24] removed '#forumthreads_controller.rb#' --- app/controllers/#forumthreads_controller.rb# | 106 ------------------- 1 file changed, 106 deletions(-) delete mode 100644 app/controllers/#forumthreads_controller.rb# diff --git a/app/controllers/#forumthreads_controller.rb# b/app/controllers/#forumthreads_controller.rb# deleted file mode 100644 index 1b43f15..0000000 --- a/app/controllers/#forumthreads_controller.rb# +++ /dev/null @@ -1,106 +0,0 @@ -class ForumthreadsController < ApplicationController - - before_filter :check_permission, only: [:show, :edit, :update, :destroy] - - def index - params[:id] = nil if params[:id] && !Forum.find_by(id: params[:id]) - - params.each {|k,v| params[k] = nil if v==""} - -c @threads = Forumthread.filter(current_user, params[:title], params[:content], params[:reply], params[:label], User.find_by(ign: params[:author].to_s.strip) || params[:author], params[:query], Forum.find_by(id: params[:id])) - .page(params[:page]).per(30) - end - def show - if params[:reverse] == "true" - @replies = @thread.replies.reverse_order.page(params[:page]) - else - @replies = @thread.replies.page(params[:page]) - end - end - - def edit - unless mod? || @thread.author.is?(current_user) - flash[:alert] = "You are not allowed to edit this thread!" - redirect_to @thread - end - end - - def new - @thread = Forumthread.new(forum: Forum.find(params[:forum])) - unless @thread.forum.can_write?(current_user) - flash[:alert] = "You are not allowed to write in this forum" - redirect_to forums_path - end - end - - def create - @thread = Forumthread.new(mod? ? thread_params([:sticky, :locked, :forum_id, :label_id]) : thread_params([:forum_id, :label_id])) - if @thread.forum.can_write?(current_user) - @thread.user_author = current_user - if @thread.save - @thread.send_new_mention_mail - flash[:notice] = "Thread created!" - redirect_to forumthread_path( @thread) - return - else - flash[:alert] = "Something went wrong while creating your thread." - render action: "new" - return - end - else - flash[:alert] = "You are not allowed to create a thread here!" - redirect_to @thread.forum - end - end - - def update - if mod? || @thread.author.is?(current_user) - @thread.user_editor = current_user - @thread.attributes = (mod? ? thread_params([:sticky, :locked, :forum_id, :label_id]) : thread_params) - old_content = @thread.content_was - if @thread.save - @thread.send_new_mention_mail(old_content) - redirect_to @thread, notice: 'Post has been updated.' - else - flash[:alert] = "There was a problem while updating the post" - render action: "edit" - end - else - flash[:alert] = "You are not allowed to edit this thread!" - redirect_to @thread - end - end - - def destroy - if mod? || @thread.author.is?(current_user) - if @thread.destroy - flash[:notice] = "Thread deleted!" - else - flash[:alert] = "There was a problem while deleting this thread" - end - else - flash[:alert] = "You are not allowed to delete this thread" - end - redirect_to @thread.forum - end - - def search - end - - private - - def check_permission - @thread = Forumthread.find(params[:id]) - unless @thread.can_read?(current_user) - flash[:alert] = "You are not allowed to view this thread" - redirect_to forums_path - end - end - - def thread_params(add = []) - a = [:title, :content] - a << :label_id if @thread && !@thread.locked? - a += add - params.require(:forumthread).permit(a) - end -end -- 2.52.0 From aff7deb310d500ee703c6f69d0e4d8a292a2d8d8 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 18 Jun 2017 18:51:01 +0200 Subject: [PATCH 22/24] removed user 'donor?' method and changed default badge_id from 0 to 1 --- app/models/user.rb | 4 ---- db/migrate/20170319193517_add_badge_id_to_users.rb | 2 +- db/schema.rb | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 52b7130..d755646 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -30,10 +30,6 @@ class User < ActiveRecord::Base self == user end - def donor? - !!self.donor - end - def confirmed? !!self.confirmed end diff --git a/db/migrate/20170319193517_add_badge_id_to_users.rb b/db/migrate/20170319193517_add_badge_id_to_users.rb index 19b58de..4738e11 100644 --- a/db/migrate/20170319193517_add_badge_id_to_users.rb +++ b/db/migrate/20170319193517_add_badge_id_to_users.rb @@ -10,7 +10,7 @@ class AddBadgeIdToUsers < ActiveRecord::Migration Badge.create!({name: "none", symbol: "", color: "#000"}) dbadge = Badge.create!({name: "donor", symbol: "$", color: "#f60"}) - add_column :users, :badge_id, :integer, default: 0 + add_column :users, :badge_id, :integer, default: 1 User.where(donor: true).update_all(badge_id: dbadge.id) remove_column :users, :donor end diff --git a/db/schema.rb b/db/schema.rb index 916c41f..f2d73de 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -88,8 +88,8 @@ ActiveRecord::Schema.define(version: 20170522210610) do end create_table "register_tokens", force: :cascade do |t| - t.string "uuid", limit: 32, null: false - t.string "token", limit: 6, null: false + t.string "uuid", limit: 191, null: false + t.string "token", limit: 191, null: false t.string "email", limit: 191, null: false end -- 2.52.0 From 8a2dfae6a4899774d00bb88fbeac2ddbe801c4e5 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 18 Jun 2017 18:54:04 +0200 Subject: [PATCH 23/24] made some small aesthetic changes --- app/views/forums/index.html.erb | 2 +- app/views/forumthreads/index.html.erb | 28 +++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index 5d9449d..532484b 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -1,7 +1,7 @@ <% title "Forums" %> <%= link_to "All threads", forumthreads_path, class: "btn blue right" %> - +
    <% @groups.each do |group| %>
    diff --git a/app/views/forumthreads/index.html.erb b/app/views/forumthreads/index.html.erb index 3a0493b..18b9ef4 100644 --- a/app/views/forumthreads/index.html.erb +++ b/app/views/forumthreads/index.html.erb @@ -1,5 +1,5 @@ <%= link_to "Forums", forums_path %> → -<% params_list = params.to_hash %> +<% params_list = params.except(:controller, :action) %> <% if params_list.any? %> <%= link_to "All Threads", forumthreads_path %> → Search Results <% else %> @@ -9,7 +9,7 @@ <% if params[:forum] text = "forum '#{Forum.find(params[:forum]).name}'" - if params_list.any? + if params_list.except(:forum).any? text = "Search results in #{text} (#{@threads.length})" else text = text.capitalize @@ -26,21 +26,21 @@ <%= form_tag(forumthreads_path, method: :get) do %> <%= text_field_tag "query", params[:query], placeholder: "Search...", class: "searchfield field" %> <%= submit_tag "Go", class: "searchfield btn" %> - <% params.slice(:title, :content, :reply, :label, :author).each do |key, value| %> + <%= link_to "Advanced Search", search_forumthreads_path(params_list), class: "btn right blue" %> + <% if params_list.any? %> + <% if params[:forum] %> + <%= link_to "Show All Threads", forumthreads_path(params_list.except("forum")), class: "btn right blue" %> + <% elsif params_list.except(:controller, :action).any? %> + <%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %> + <% end %> + <% end %> + <% if params[:forum] %> + <%= link_to "Go to Forum", forum_path(params[:forum]), class: "btn right blue" %> + <% end %> + <% params.slice(:forum, :title, :content, :reply, :label, :author).each do |key, value| %> <%= hidden_field_tag key, params[key] %> <% end %> <% end %> -<%= link_to "Advanced Search", search_forumthreads_path(params_list), class: "btn right blue" %> -<% if params_list.any? %> - <% if params[:forum] %> - <%= link_to "Show All Threads", forumthreads_path(params_list.except("forum")), class: "btn right blue" %> - <% elsif params_list.except(:controller, :action).any? %> - <%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %> - <% end %> -<% end %> -<% if params[:forum] %> - <%= link_to "Go to Forum", forum_path(params[:forum]), class: "btn right blue" %> -<% end %>
    <% @threads.each do |thread| %> -- 2.52.0 From 4e83948909af029ed2359074d017e7d3cc36da46 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 18 Jun 2017 18:54:50 +0200 Subject: [PATCH 24/24] Added action_caching gem to Gemfile.lock --- Gemfile.lock | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 1e638b9..c04ca64 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,6 +14,14 @@ GIT railties (>= 3.2.0) sass-rails (>= 3.2.0) +GIT + remote: git://github.com/antulik/actionpack-action_caching.git + revision: 8c6e52c69315d67437f480da5dce4b7c8737fb32 + ref: 8c6e52c69315d67437f480da5dce4b7c8737fb32 + specs: + actionpack-action_caching (1.2.0) + actionpack (>= 4.0.0, < 6) + GIT remote: git://github.com/jomo/kaminari.git revision: e49066e94d77a6abb03a0819f3c4b0cc6923cb70 @@ -223,6 +231,7 @@ PLATFORMS ruby DEPENDENCIES + actionpack-action_caching! activerecord-session_store bcrypt better_errors -- 2.52.0

    Forum<%= select_tag "id", options_for_select(forums, params[:id]), include_blank: "Search All Threads" %><%= select_tag "forum", options_for_select(forums, params[:forum]), include_blank: "Search All Threads" %>
    Label