From 668c9a296021d37b0d1b0b2c040f2829e9213a59 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 7 Jul 2017 05:33:39 +0200 Subject: [PATCH 1/5] Added mastodon and mastodon_instance settings to user profiles --- app/controllers/users_controller.rb | 4 +- app/models/user.rb | 2 + app/views/users/edit.html.erb | 7 ++ app/views/users/show.html.erb | 11 +++ .../20170707012441_add_mastodon_to_users.rb | 6 ++ db/schema.rb | 75 +++++++++---------- 6 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 db/migrate/20170707012441_add_mastodon_to_users.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3d49591..3380482 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -137,9 +137,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, :header_scroll, :utc_time, :dark]) + userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :mastodon, :mastodon_instance, :about, :role, :badge, :confirmed, :header_scroll, :utc_time, :dark]) else - userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about, :header_scroll, :utc_time, :dark]) + userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :mastodon, :mastodon_instance, :about, :header_scroll, :utc_time, :dark]) end if userdata[:role] role = Role.get(userdata[:role]) diff --git a/app/models/user.rb b/app/models/user.rb index b996978..a4539ac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -167,6 +167,8 @@ class User < ActiveRecord::Base self.email.strip! if self.email self.about.strip! if self.about self.skype.strip! if self.skype + self.mastodon.strip! if self.mastodon + self.mastodon_instance.strip! if self.mastodon_instance self.youtube.strip! if self.youtube self.twitter.strip! if self.twitter end diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 133a69d..edcd33c 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -54,6 +54,13 @@ <%= f.select :skype_public, [["Staff only", false], ["All users", true]], {}, { disabled: !can_edit? } %> + + Mastodon + + <%= f.text_field :mastodon, placeholder: "Mastodon username", disabled: !(@user.is?(current_user) && confirmed? || (mod? && current_user.role >= @user.role)), style: "width:49%;float:left;margin-right:2%" %> + <%= f.text_field :mastodon_instance, placeholder: "Mastodon instance", disabled: !(@user.is?(current_user) && confirmed? || (mod? && current_user.role >= @user.role)), style: "width:49%" %> + + YouTube Channel ID diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index e371a09..fbf848c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -58,6 +58,17 @@ <%= link_to @user.skype, "skype:#{@user.skype}?chat", target: "_blank" %> <% end %> + <% if !@user.mastodon.blank? %> + + Mastodon + + <% if @user.mastodon_instance %> + <%= link_to "@#{@user.mastodon}", "https://#{CGI.escape(@user.mastodon_instance)}/@#{CGI.escape(@user.mastodon)}", :target => "_blank" %> + <% else %> + <%= @user.mastodon %> + <% end %> + + <% end %> <% if !@user.youtube.blank? && !@user.youtube_channelname.blank? %> YouTube diff --git a/db/migrate/20170707012441_add_mastodon_to_users.rb b/db/migrate/20170707012441_add_mastodon_to_users.rb new file mode 100644 index 0000000..3401f1b --- /dev/null +++ b/db/migrate/20170707012441_add_mastodon_to_users.rb @@ -0,0 +1,6 @@ +class AddMastodonToUsers < ActiveRecord::Migration + def change + add_column :users, :mastodon, :string + add_column :users, :mastodon_instance, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 5849cf5..b32988a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,18 +11,17 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170703003647) do +ActiveRecord::Schema.define(version: 20170707012441) do 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 +29,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 +38,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 +59,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 +72,47 @@ 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 "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 +124,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 "uuid", limit: 191, 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 "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 +147,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 "mastodon", limit: 191 + t.string "mastodon_instance", limit: 191 end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree -- 2.52.0 From 2289d37e6985220a775402490f436aab12b3de0e Mon Sep 17 00:00:00 2001 From: MrYummy Date: Fri, 7 Jul 2017 19:41:28 +0200 Subject: [PATCH 2/5] combined mastodon and mastodon_instance columns into a single mastodon column --- app/controllers/users_controller.rb | 4 ++++ app/models/user.rb | 1 - app/views/users/edit.html.erb | 5 +++-- app/views/users/show.html.erb | 7 ++++--- db/migrate/20170707012441_add_mastodon_to_users.rb | 1 - db/schema.rb | 1 - 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3380482..c228857 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -153,6 +153,10 @@ class UsersController < ApplicationController if userdata[:badge] userdata[:badge] = Badge.get(userdata[:badge]) end + unless userdata[:mastodon].blank? + userdata[:mastodon] = "#{userdata[:mastodon].gsub("@", "")}#{("@" + userdata[:mastodon_instance].gsub("@", "")) unless userdata[:mastodon_instance].blank?}" + end + userdata.delete(:mastodon_instance) if @user.youtube != userdata[:youtube] youtube = get_youtube(userdata[:youtube]) userdata[:youtube] = youtube[:channel] diff --git a/app/models/user.rb b/app/models/user.rb index a4539ac..a724f20 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -168,7 +168,6 @@ class User < ActiveRecord::Base self.about.strip! if self.about self.skype.strip! if self.skype self.mastodon.strip! if self.mastodon - self.mastodon_instance.strip! if self.mastodon_instance self.youtube.strip! if self.youtube self.twitter.strip! if self.twitter end diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index edcd33c..24bdba8 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -57,8 +57,9 @@ Mastodon - <%= f.text_field :mastodon, placeholder: "Mastodon username", disabled: !(@user.is?(current_user) && confirmed? || (mod? && current_user.role >= @user.role)), style: "width:49%;float:left;margin-right:2%" %> - <%= f.text_field :mastodon_instance, placeholder: "Mastodon instance", disabled: !(@user.is?(current_user) && confirmed? || (mod? && current_user.role >= @user.role)), style: "width:49%" %> + <% mstdn_array = @user.mastodon.split("@") if @user.mastodon %> + <%= f.text_field :mastodon, value: (mstdn_array[0] if mstdn_array), placeholder: "Mastodon username", disabled: !(@user.is?(current_user) && confirmed? || (mod? && current_user.role >= @user.role)), style: "width:49%;float:left;margin-right:2%" %> + <%= f.text_field :mastodon_instance, value: (mstdn_array[1] if mstdn_array), placeholder: "Mastodon instance", disabled: !(@user.is?(current_user) && confirmed? || (mod? && current_user.role >= @user.role)), style: "width:49%" %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index fbf848c..db51258 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -62,10 +62,11 @@ Mastodon - <% if @user.mastodon_instance %> - <%= link_to "@#{@user.mastodon}", "https://#{CGI.escape(@user.mastodon_instance)}/@#{CGI.escape(@user.mastodon)}", :target => "_blank" %> + <% mstdn_array = @user.mastodon.split("@") %> + <% if mstdn_array.length > 1 %> + <%= link_to "@#{mstdn_array[0]}", "https://#{CGI.escape(mstdn_array[1])}/@#{CGI.escape(mstdn_array[0])}", :target => "_blank" %> <% else %> - <%= @user.mastodon %> + <%= "@" + @user.mastodon %> <% end %> <% end %> diff --git a/db/migrate/20170707012441_add_mastodon_to_users.rb b/db/migrate/20170707012441_add_mastodon_to_users.rb index 3401f1b..e620741 100644 --- a/db/migrate/20170707012441_add_mastodon_to_users.rb +++ b/db/migrate/20170707012441_add_mastodon_to_users.rb @@ -1,6 +1,5 @@ class AddMastodonToUsers < ActiveRecord::Migration def change add_column :users, :mastodon, :string - add_column :users, :mastodon_instance, :string end end diff --git a/db/schema.rb b/db/schema.rb index b32988a..9c42e9b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -152,7 +152,6 @@ ActiveRecord::Schema.define(version: 20170707012441) do t.boolean "header_scroll", default: false t.boolean "dark", default: false t.string "mastodon", limit: 191 - t.string "mastodon_instance", limit: 191 end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree -- 2.52.0 From 1be5acb86f184c77e9006a8bd53a3d738e472160 Mon Sep 17 00:00:00 2001 From: Logan Fick Date: Wed, 11 Oct 2017 22:34:30 -0400 Subject: [PATCH 3/5] Added Mastodon handle validation. --- app/models/user.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index a724f20..3b70cb8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,6 +22,8 @@ class User < ActiveRecord::Base validates :email, uniqueness: {case_sensitive: false}, format: {with: /\A.+@(.+\..{2,}|\[(IPv6)?[0-9a-f:.]+\])\z/i, message: "That doesn't look like an email address."} validates :ign, uniqueness: {case_sensitive: false}, format: {with: /\A[a-z\d_]+\z/i, message: "Username is invalid (a-z, 0-9, _)."} + validates :mastodon, uniqueness: {case_sensitive: false}, format: {with: /\A.+@(.+\..{2,}|\[(IPv6)?[0-9a-f:.]+\])\z/i, message: "That doesn't look like a valid Mastodon handle."} + has_many :blogposts has_many :comments -- 2.52.0 From b07830fc7a84f683c7e19fc6d09e92222883a66d Mon Sep 17 00:00:00 2001 From: Logan Fick Date: Sun, 15 Oct 2017 16:41:57 -0400 Subject: [PATCH 4/5] Made Mastodon field optional. --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 3b70cb8..99eae6d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,7 +22,7 @@ class User < ActiveRecord::Base validates :email, uniqueness: {case_sensitive: false}, format: {with: /\A.+@(.+\..{2,}|\[(IPv6)?[0-9a-f:.]+\])\z/i, message: "That doesn't look like an email address."} validates :ign, uniqueness: {case_sensitive: false}, format: {with: /\A[a-z\d_]+\z/i, message: "Username is invalid (a-z, 0-9, _)."} - validates :mastodon, uniqueness: {case_sensitive: false}, format: {with: /\A.+@(.+\..{2,}|\[(IPv6)?[0-9a-f:.]+\])\z/i, message: "That doesn't look like a valid Mastodon handle."} + validates :mastodon, uniqueness: {case_sensitive: false}, format: {with: /\A(.+@(.+\..{2,}|\[(IPv6)?[0-9a-f:.]+\]))?\z/i, message: "That doesn't look like a valid Mastodon handle."} has_many :blogposts has_many :comments -- 2.52.0 From e0ca82324573a4340b4bf29e39fbd6e6fbcfab92 Mon Sep 17 00:00:00 2001 From: Logan Fick Date: Sun, 15 Oct 2017 17:07:51 -0400 Subject: [PATCH 5/5] Combined Mastodon username and instance fields into one field. --- app/controllers/users_controller.rb | 8 ++------ app/views/users/edit.html.erb | 6 ++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c228857..f00d703 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -137,9 +137,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, :mastodon, :mastodon_instance, :about, :role, :badge, :confirmed, :header_scroll, :utc_time, :dark]) + userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :mastodon, :about, :role, :badge, :confirmed, :header_scroll, :utc_time, :dark]) else - userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :mastodon, :mastodon_instance, :about, :header_scroll, :utc_time, :dark]) + userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :mastodon, :about, :header_scroll, :utc_time, :dark]) end if userdata[:role] role = Role.get(userdata[:role]) @@ -153,10 +153,6 @@ class UsersController < ApplicationController if userdata[:badge] userdata[:badge] = Badge.get(userdata[:badge]) end - unless userdata[:mastodon].blank? - userdata[:mastodon] = "#{userdata[:mastodon].gsub("@", "")}#{("@" + userdata[:mastodon_instance].gsub("@", "")) unless userdata[:mastodon_instance].blank?}" - end - userdata.delete(:mastodon_instance) if @user.youtube != userdata[:youtube] youtube = get_youtube(userdata[:youtube]) userdata[:youtube] = youtube[:channel] diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 24bdba8..97229de 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -56,10 +56,8 @@ Mastodon - - <% mstdn_array = @user.mastodon.split("@") if @user.mastodon %> - <%= f.text_field :mastodon, value: (mstdn_array[0] if mstdn_array), placeholder: "Mastodon username", disabled: !(@user.is?(current_user) && confirmed? || (mod? && current_user.role >= @user.role)), style: "width:49%;float:left;margin-right:2%" %> - <%= f.text_field :mastodon_instance, value: (mstdn_array[1] if mstdn_array), placeholder: "Mastodon instance", disabled: !(@user.is?(current_user) && confirmed? || (mod? && current_user.role >= @user.role)), style: "width:49%" %> + + <%= f.text_field :mastodon, placeholder: "Mastodon username", disabled: !(@user.is?(current_user) && confirmed? || (mod? && current_user.role >= @user.role)) %> -- 2.52.0