From 0cebefa406d49d05e069d2e1bac66e7f297478b9 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Mon, 10 Jul 2017 21:26:15 +0200 Subject: [PATCH 1/3] Added permissions to badges --- app/controllers/forumgroups_controller.rb | 18 ++++ app/controllers/forums_controller.rb | 18 ++++ app/models/.forum.rb.swp | Bin 0 -> 12288 bytes app/models/badge.rb | 1 + app/models/badgeassociation.rb | 7 ++ app/models/forum.rb | 8 +- app/models/forumgroup.rb | 7 +- app/models/forumthread.rb | 4 +- app/views/forumgroups/edit.html.erb | 18 +++- app/views/forumgroups/new.html.erb | 18 +++- app/views/forums/edit.html.erb | 16 +++ app/views/forums/new.html.erb | 16 +++ ...20170710141543_create_badgeassociations.rb | 10 ++ db/schema.rb | 94 ++++++++++-------- 14 files changed, 187 insertions(+), 48 deletions(-) create mode 100644 app/models/.forum.rb.swp create mode 100644 app/models/badgeassociation.rb create mode 100644 db/migrate/20170710141543_create_badgeassociations.rb diff --git a/app/controllers/forumgroups_controller.rb b/app/controllers/forumgroups_controller.rb index fe359af..7b166f7 100644 --- a/app/controllers/forumgroups_controller.rb +++ b/app/controllers/forumgroups_controller.rb @@ -19,6 +19,19 @@ class ForumgroupsController < ApplicationController def update if admin? @group = Forumgroup.find(params[:id]) + group_badges = Badgeassociation.where(forumgroup: @group) + ["read-", "write-"].each_with_index do |p,i| + current_badges = group_badges.where(permission: i+1).pluck(:badge_id) + params.select{|k,v| k.start_with? p}.each do |k,v| + name = k.gsub(p, "") + if current_badges.include? (bid = Badge.find_by(name: name).id) + current_badges.delete bid + else + Badgeassociation.create!(badge: Badge.find_by(name: name), forumgroup: @group, permission: i+1) + end + end + current_badges.each {|b| Badgeassociation.find_by(badge_id: b, forumgroup: @group, permission: i+1).delete} + end if @group.update_attributes(group_params) flash[:notice] = "Forum group updated" redirect_to @group @@ -43,6 +56,11 @@ class ForumgroupsController < ApplicationController def create if admin? @group = Forumgroup.new(group_params) + ["read-", "write-"].each_with_index do |p,i| + params.select{|k,v| k.start_with? p}.each do |k,v| + Badgeassociation.create!(badge: Badge.find_by(name: k.gsub(p, "")), forumgroup: @group, permission: i+1) + end + end if @group.save flash[:notice] = "Forum group created." redirect_to @group diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 206f01f..2dd3f78 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -35,6 +35,19 @@ class ForumsController < ApplicationController def update if admin? + forum_badges = Badgeassociation.where(forum: @forum) + ["read-", "write-"].each_with_index do |p,i| + current_badges = forum_badges.where(permission: i+1).pluck(:badge_id) + params.select{|k,v| k.start_with? p}.each do |k,v| + name = k.gsub(p, "") + if current_badges.include? (bid = Badge.find_by(name: name).id) + current_badges.delete bid + else + Badgeassociation.create!(badge: Badge.find_by(name: name), forum: @forum, permission: i+1) + end + end + current_badges.each {|b| Badgeassociation.find_by(badge_id: b, forum: @forum, permission: i+1).delete} + end if @forum.update_attributes(forum_params) flash[:notice] = "Forum updated" redirect_to @forum @@ -50,6 +63,11 @@ class ForumsController < ApplicationController def create if admin? @forum = Forum.new(forum_params([:forumgroup_id])) + ["read-", "write-"].each_with_index do |p,i| + params.select{|k,v| k.start_with? p}.each do |k,v| + Badgeassociation.create!(badge: Badge.find_by(name: k.gsub(p, "")), forum: @forum, permission: i+1) + end + end if @forum.save flash[:notice] = "Forum created." redirect_to @forum diff --git a/app/models/.forum.rb.swp b/app/models/.forum.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..07c5d02937d854d51714cf5549d14747e658954a GIT binary patch literal 12288 zcmeI2PiqrF6u_rmwJPcdm`11xq?@+>gQZ%nf51XLR4quU%VhT@nYz2P&TLv!3&peI z!K)WfdeN(%yb7K?_yPPXzL{*yHb`wjgu+|+Wq04anVt8W$suH$(<^tD_+{?`!{a1l zi{HbCw=UjgKdv#>>n2Ih#{Y8M2b13ey#abSiq5@h;zkxY~)@)~)Gyg+u43|U7cvWhGs zH<2626!LtWv1iB@5+Yyl`Ja(b$XnzoqLC*^6PZIUA$FcK2pwdA43GgbKnBPF86X2> zfDHT(1CU0H^ZqC2t1_zdTm{CG=@rM{s^0}UdY zuXYXS8sFaLHngc_4n?f!ZNnQ9HV4ttAZ@L>nK#;xPfqfxRx$KP^HLel+wrRt_EG&? zOmR0hjbFXOhv_zRK}2m3#;8z=T&mP-$utU@y=v1o`2DW#y3XDE%04#`x9U6tok(M_ zi_d3kwSj=q8J0!38tjyZ#gx7LuEhrTUy99kQvXRQGrKA&O|M*t6Ongps~IeOaaUS0 zm*q+=a{AY$j1+g$pg-;{`-qM(fv_t8u}a$}zzvm%w8#BeV8}jg*uwqcTGn|O<1z+z zNS{}haj`3I#Xz>x;4$= role_read)) + group && group.can_read?(user) && (role_read.nil? || (!user.nil? && user.role >= role_read) || Badgeassociation.find_by(badge: user.badge, forum: self, permission: 1)) end def can_write?(user) - group.can_write?(user) && (role_write.nil? || (!user.nil? && user.role >= role_write)) + group.can_write?(user) && (role_write.nil? || (!user.nil? && user.role >= role_write || Badgeassociation.find_by(badge: user.badge, forum: self, permission: 2))) end def can_view?(user) diff --git a/app/models/forumgroup.rb b/app/models/forumgroup.rb index f9d156c..c946f3b 100644 --- a/app/models/forumgroup.rb +++ b/app/models/forumgroup.rb @@ -4,7 +4,8 @@ class Forumgroup < ActiveRecord::Base belongs_to :role_write, class_name: "Role", foreign_key: "role_write_id" accepts_nested_attributes_for :forums - + has_many :badgeassociations + has_many :badges, through: :badgeassociations validates_presence_of :name, :position validates_length_of :name, in: 2..20 @@ -14,11 +15,11 @@ class Forumgroup < ActiveRecord::Base end def can_read?(user) - role_read.nil? || (!user.nil? && user.role >= role_read) + role_read.nil? || (!user.nil? && user.role >= role_read) || Badgeassociation.find_by(badge: user.badge, forumgroup: self, permission: 1) end def can_write?(user) - !user.nil? && user.confirmed? && (role_write.nil? || user.role >= role_write) + !user.nil? && user.confirmed? && (role_write.nil? || user.role >= role_write) || Badgeassociation.find_by(badge: user.badge, forumgroup: self, permission: 2) end def can_view?(user) diff --git a/app/models/forumthread.rb b/app/models/forumthread.rb index fd8d3c1..f7712b5 100644 --- a/app/models/forumthread.rb +++ b/app/models/forumthread.rb @@ -70,7 +70,7 @@ class Forumthread < ActiveRecord::Base 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) <= ?" + 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 (#{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 (?)"] @@ -86,7 +86,7 @@ class Forumthread < ActiveRecord::Base .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) + threads = threads.where("forumthreads.user_author_id = ? OR (#{can_read}) OR (#{sticky_can_write}) OR (?)", user_id, role_value, role_value, role_value, role_value, Forum.find(forum).can_read?(user)) if query threads = threads.where("#{match[2]}", query[0..99], query[0..99]) elsif [title, content, reply].any? diff --git a/app/views/forumgroups/edit.html.erb b/app/views/forumgroups/edit.html.erb index bb3bf5a..4a79f90 100644 --- a/app/views/forumgroups/edit.html.erb +++ b/app/views/forumgroups/edit.html.erb @@ -29,12 +29,28 @@ <%= f.label :role_read_id, "Min. read role" %> <%= f.select :role_read_id, role_selection, include_blank: "None" %> + + Badges with read permission + + <% Badge.where("name != 'none'").each do |b| %> + <%=b%><%= check_box_tag "read-#{b}", nil, Badgeassociation.find_by(badge: b, forumgroup: @group, permission: 1) %> + <% end %> + + <%= f.label :role_write_id, "Min. write role" %> <%= f.select :role_write_id, role_selection, include_blank: false %> + + Badges with write permission + + <% Badge.where("name != 'none'").each do |b| %> + <%=b%><%= check_box_tag "write-#{b}", nil, Badgeassociation.find_by(badge: b, forumgroup: @group, permission: 2) %> + <% end %> + +

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

<% end %>

<%= button_to "Delete group", @group, :method => "delete", data: {confirm: "Delete group?\nForums + Threads will not be accessible!"}, class: "btn red right" %>

-
\ No newline at end of file +
diff --git a/app/views/forumgroups/new.html.erb b/app/views/forumgroups/new.html.erb index 9802260..4731522 100644 --- a/app/views/forumgroups/new.html.erb +++ b/app/views/forumgroups/new.html.erb @@ -16,11 +16,27 @@ <%= f.label :role_read_id, "Min. read role" %> <%= f.select :role_read_id, role_selection, include_blank: "None" %> + + Badges with read permission + + <% Badge.where("name != 'none'").each do |b| %> + <%=b%><%= check_box_tag "read-#{b}" %> + <% end %> + + <%= f.label :role_write_id, "Min. write role" %> <%= f.select :role_write_id, role_selection, include_blank: false %> + + Badges with write permission + + <% Badge.where("name != 'none'").each do |b| %> + <%=b%><%= check_box_tag "write-#{b}" %> + <% end %> + +

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

-<% 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 571b3b7..d6d9d13 100644 --- a/app/views/forums/edit.html.erb +++ b/app/views/forums/edit.html.erb @@ -17,10 +17,26 @@ <%= f.label :role_read_id, "Min. read role" %> <%= f.select :role_read_id, role_selection, include_blank: "None" %> + + Badges with read permission + + <% Badge.where("name != 'none'").each do |b| %> + <%=b%><%= check_box_tag "read-#{b}", nil, Badgeassociation.find_by(badge: b, forum: @forum, permission: 1) %> + <% end %> + + <%= f.label :role_write_id, "Min. write role" %> <%= f.select :role_write_id, role_selection, include_blank: false %> + + Badges with write permission + + <% Badge.where("name != 'none'").each do |b| %> + <%=b%><%= check_box_tag "write-#{b}", nil, Badgeassociation.find_by(badge: b, forum: @forum, permission: 2) %> + <% end %> + + <%= f.label :necro_length, "Necropost warning delay (in days)" %> <%= f.number_field :necro_length, placeholder: "Warning Delay (leave blank for no warning)" %> diff --git a/app/views/forums/new.html.erb b/app/views/forums/new.html.erb index 836a9b2..9bf308b 100644 --- a/app/views/forums/new.html.erb +++ b/app/views/forums/new.html.erb @@ -17,10 +17,26 @@ <%= f.label :role_read_id, "Min. read role" %> <%= f.select :role_read_id, role_selection, include_blank: "None" %> + + Badges with read permission + + <% Badge.where("name != 'none'").each do |b| %> + <%=b%><%= check_box_tag "read-#{b}" %> + <% end %> + + <%= f.label :role_write_id, "Min. write role" %> <%= f.select :role_write_id, role_selection, include_blank: false %> + + Badges with write permission + + <% Badge.where("name != 'none'").each do |b| %> + <%=b%><%= check_box_tag "write-#{b}" %> + <% end %> + + <%= f.label :necro_length, "Necropost warning delay (in days)" %> <%= f.number_field :necro_length, placeholder: "Warning Delay (leave blank for no warning)" %> diff --git a/db/migrate/20170710141543_create_badgeassociations.rb b/db/migrate/20170710141543_create_badgeassociations.rb new file mode 100644 index 0000000..cbd5ae0 --- /dev/null +++ b/db/migrate/20170710141543_create_badgeassociations.rb @@ -0,0 +1,10 @@ +class CreateBadgeassociations < ActiveRecord::Migration + def change + create_table :badgeassociations do |t| + t.references :badge + t.references :forum + t.references :forumgroup + t.integer :permission #1 = read, 2 = write + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5849cf5..a0a4b6f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,18 +11,24 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170703003647) do +ActiveRecord::Schema.define(version: 20170710141543) do + + create_table "badgeassociations", force: :cascade do |t| + t.integer "badge_id", limit: 4 + t.integer "forum_id", limit: 4 + t.integer "forumgroup_id", limit: 4 + t.integer "permission", limit: 4 + end create_table "badges", force: :cascade do |t| - t.string "name", limit: 191 - t.string "symbol", limit: 191 - t.string "color", limit: 191 - t.integer "value", limit: 4 + 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: 255 - t.text "content", limit: 16777215 + t.string "title", limit: 191 + t.text "content", limit: 65535 t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 t.datetime "created_at" @@ -30,7 +36,7 @@ ActiveRecord::Schema.define(version: 20170703003647) do end create_table "comments", force: :cascade do |t| - t.text "content", limit: 16777215 + t.text "content", limit: 65535 t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 t.integer "blogpost_id", limit: 4 @@ -39,14 +45,14 @@ ActiveRecord::Schema.define(version: 20170703003647) do end create_table "forumgroups", force: :cascade do |t| - t.string "name", limit: 255 + 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", limit: 255 + t.string "name", limit: 191 t.integer "position", limit: 4 t.integer "role_read_id", limit: 4 t.integer "role_write_id", limit: 4 @@ -60,10 +66,10 @@ ActiveRecord::Schema.define(version: 20170703003647) do end create_table "forumthreads", force: :cascade do |t| - t.string "title", limit: 255 - t.text "content", limit: 16777215 - t.boolean "sticky", default: false - t.boolean "locked", default: false + t.string "title", limit: 191 + t.text "content", limit: 65535 + t.boolean "sticky", default: false + t.boolean "locked", default: false t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 t.integer "forum_id", limit: 4 @@ -73,49 +79,57 @@ ActiveRecord::Schema.define(version: 20170703003647) do end add_index "forumthreads", ["content"], name: "index_forumthreads_on_content", type: :fulltext - add_index "forumthreads", ["title", "content"], name: "forumthreads_title_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: 255 - t.text "content", limit: 16777215 + 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", limit: 255 - t.string "color", limit: 255 + t.string "name", limit: 191 + t.string "color", limit: 191 + end + + create_table "notifications", force: :cascade do |t| + t.string "user_token", limit: 191 + t.string "message_type", limit: 191, null: false + t.integer "user_message_id", limit: 4 + t.text "content", limit: 65535 + t.string "content_path", limit: 191 + t.datetime "created_at" + t.datetime "updated_at" 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 "email", limit: 191 + t.string "email", limit: 191, null: false end - add_index "register_tokens", ["email"], name: "index_register_tokens_on_email", unique: true, using: :btree 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", limit: 255 + t.string "name", limit: 191 t.integer "value", limit: 4 - t.string "color", limit: 255 + t.string "color", limit: 191 end create_table "sessions", force: :cascade do |t| - t.string "session_id", limit: 255, null: false - t.text "data", limit: 16777215 + t.string "session_id", limit: 191, null: false + t.text "data", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end - add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", length: {"session_id"=>191}, using: :btree + add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree create_table "threadreplies", force: :cascade do |t| - t.text "content", limit: 16777215 + t.text "content", limit: 65535 t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 t.integer "forumthread_id", limit: 4 @@ -127,19 +141,19 @@ ActiveRecord::Schema.define(version: 20170703003647) do add_index "threadreplies", ["forumthread_id"], name: "index_threadreplies_on_forumthread_id", using: :btree create_table "users", force: :cascade do |t| - t.string "uuid", limit: 255, null: false - t.string "name", limit: 191 - t.string "password_digest", limit: 255, null: false - t.string "ign", limit: 255, null: false - t.string "email", limit: 191 + 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", limit: 255 - t.string "skype", limit: 255 + t.string "last_ip", limit: 191 + t.string "skype", limit: 191 t.boolean "skype_public", default: false - t.string "youtube", limit: 255 - t.string "youtube_channelname", limit: 255 - t.string "twitter", limit: 255 - t.string "email_token", limit: 255 + 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 @@ -150,10 +164,12 @@ ActiveRecord::Schema.define(version: 20170703003647) 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", limit: 4, default: 0 + t.integer "badge_id", limit: 4, default: 1 t.boolean "utc_time", default: false t.boolean "header_scroll", default: false t.boolean "dark", default: false + t.string "notification_token", limit: 191, null: false + t.integer "notification_type", limit: 4, default: 1, null: false end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree -- 2.45.2 From 626ba221e0704f7eba76a686c4198f0c2148c2b5 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Tue, 11 Jul 2017 03:38:17 +0200 Subject: [PATCH 2/3] Removed swap file --- app/models/.forum.rb.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/models/.forum.rb.swp diff --git a/app/models/.forum.rb.swp b/app/models/.forum.rb.swp deleted file mode 100644 index 07c5d02937d854d51714cf5549d14747e658954a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2PiqrF6u_rmwJPcdm`11xq?@+>gQZ%nf51XLR4quU%VhT@nYz2P&TLv!3&peI z!K)WfdeN(%yb7K?_yPPXzL{*yHb`wjgu+|+Wq04anVt8W$suH$(<^tD_+{?`!{a1l zi{HbCw=UjgKdv#>>n2Ih#{Y8M2b13ey#abSiq5@h;zkxY~)@)~)Gyg+u43|U7cvWhGs zH<2626!LtWv1iB@5+Yyl`Ja(b$XnzoqLC*^6PZIUA$FcK2pwdA43GgbKnBPF86X2> zfDHT(1CU0H^ZqC2t1_zdTm{CG=@rM{s^0}UdY zuXYXS8sFaLHngc_4n?f!ZNnQ9HV4ttAZ@L>nK#;xPfqfxRx$KP^HLel+wrRt_EG&? zOmR0hjbFXOhv_zRK}2m3#;8z=T&mP-$utU@y=v1o`2DW#y3XDE%04#`x9U6tok(M_ zi_d3kwSj=q8J0!38tjyZ#gx7LuEhrTUy99kQvXRQGrKA&O|M*t6Ongps~IeOaaUS0 zm*q+=a{AY$j1+g$pg-;{`-qM(fv_t8u}a$}zzvm%w8#BeV8}jg*uwqcTGn|O<1z+z zNS{}haj`3I#Xz>x;4$ Date: Sun, 6 Aug 2017 13:29:03 +0200 Subject: [PATCH 3/3] removed unneeded parentheses and text limits --- app/models/forumthread.rb | 2 +- db/schema.rb | 94 ++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 56 deletions(-) diff --git a/app/models/forumthread.rb b/app/models/forumthread.rb index f7712b5..d695f9b 100644 --- a/app/models/forumthread.rb +++ b/app/models/forumthread.rb @@ -70,7 +70,7 @@ class Forumthread < ActiveRecord::Base 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) <= ?)" + 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 (#{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 (?)"] diff --git a/db/schema.rb b/db/schema.rb index a0a4b6f..5849cf5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,24 +11,18 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170710141543) do - - create_table "badgeassociations", force: :cascade do |t| - t.integer "badge_id", limit: 4 - t.integer "forum_id", limit: 4 - t.integer "forumgroup_id", limit: 4 - t.integer "permission", limit: 4 - end +ActiveRecord::Schema.define(version: 20170703003647) do create_table "badges", force: :cascade do |t| - t.string "name", limit: 191 - t.string "symbol", limit: 191 - t.string "color", limit: 191 + t.string "name", limit: 191 + t.string "symbol", limit: 191 + t.string "color", limit: 191 + t.integer "value", limit: 4 end create_table "blogposts", force: :cascade do |t| - t.string "title", limit: 191 - t.text "content", limit: 65535 + t.string "title", limit: 255 + t.text "content", limit: 16777215 t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 t.datetime "created_at" @@ -36,7 +30,7 @@ ActiveRecord::Schema.define(version: 20170710141543) do end create_table "comments", force: :cascade do |t| - t.text "content", limit: 65535 + t.text "content", limit: 16777215 t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 t.integer "blogpost_id", limit: 4 @@ -45,14 +39,14 @@ ActiveRecord::Schema.define(version: 20170710141543) do end create_table "forumgroups", force: :cascade do |t| - t.string "name", limit: 191 + t.string "name", limit: 255 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", limit: 191 + t.string "name", limit: 255 t.integer "position", limit: 4 t.integer "role_read_id", limit: 4 t.integer "role_write_id", limit: 4 @@ -66,10 +60,10 @@ ActiveRecord::Schema.define(version: 20170710141543) do end create_table "forumthreads", force: :cascade do |t| - t.string "title", limit: 191 - t.text "content", limit: 65535 - t.boolean "sticky", default: false - t.boolean "locked", default: false + t.string "title", limit: 255 + t.text "content", limit: 16777215 + t.boolean "sticky", default: false + t.boolean "locked", default: false t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 t.integer "forum_id", limit: 4 @@ -79,57 +73,49 @@ ActiveRecord::Schema.define(version: 20170710141543) do end add_index "forumthreads", ["content"], name: "index_forumthreads_on_content", type: :fulltext + add_index "forumthreads", ["title", "content"], name: "forumthreads_title_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 + t.string "title", limit: 255 + t.text "content", limit: 16777215 t.datetime "created_at" t.datetime "updated_at" end create_table "labels", force: :cascade do |t| - t.string "name", limit: 191 - t.string "color", limit: 191 - end - - create_table "notifications", force: :cascade do |t| - t.string "user_token", limit: 191 - t.string "message_type", limit: 191, null: false - t.integer "user_message_id", limit: 4 - t.text "content", limit: 65535 - t.string "content_path", limit: 191 - t.datetime "created_at" - t.datetime "updated_at" + t.string "name", limit: 255 + t.string "color", limit: 255 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 "email", limit: 191, null: false + t.string "email", limit: 191 end + add_index "register_tokens", ["email"], name: "index_register_tokens_on_email", unique: true, using: :btree 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", limit: 191 + t.string "name", limit: 255 t.integer "value", limit: 4 - t.string "color", limit: 191 + t.string "color", limit: 255 end create_table "sessions", force: :cascade do |t| - t.string "session_id", limit: 191, null: false - t.text "data", limit: 65535 + t.string "session_id", limit: 255, null: false + t.text "data", limit: 16777215 t.datetime "created_at" t.datetime "updated_at" end - add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree + add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", length: {"session_id"=>191}, using: :btree add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree create_table "threadreplies", force: :cascade do |t| - t.text "content", limit: 65535 + t.text "content", limit: 16777215 t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 t.integer "forumthread_id", limit: 4 @@ -141,19 +127,19 @@ ActiveRecord::Schema.define(version: 20170710141543) do add_index "threadreplies", ["forumthread_id"], name: "index_threadreplies_on_forumthread_id", using: :btree create_table "users", force: :cascade do |t| - 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.string "uuid", limit: 255, null: false + t.string "name", limit: 191 + t.string "password_digest", limit: 255, null: false + t.string "ign", limit: 255, null: false + t.string "email", limit: 191 t.text "about", limit: 65535 - t.string "last_ip", limit: 191 - t.string "skype", limit: 191 + t.string "last_ip", limit: 255 + t.string "skype", limit: 255 t.boolean "skype_public", default: false - t.string "youtube", limit: 191 - t.string "youtube_channelname", limit: 191 - t.string "twitter", limit: 191 - t.string "email_token", limit: 191 + t.string "youtube", limit: 255 + t.string "youtube_channelname", limit: 255 + t.string "twitter", limit: 255 + t.string "email_token", limit: 255 t.boolean "confirmed", default: false t.datetime "last_seen" t.integer "role_id", limit: 4, null: false @@ -164,12 +150,10 @@ ActiveRecord::Schema.define(version: 20170710141543) 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", limit: 4, default: 1 + 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 - t.string "notification_token", limit: 191, null: false - t.integer "notification_type", limit: 4, default: 1, null: false end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree -- 2.45.2