From 97a4926c24fba2b7902242ca3b8486a433930c4a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 15 Jan 2019 18:07:26 -0600 Subject: [PATCH 01/14] require usernames to be 1-20 characters --- app/models/user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/user.rb b/app/models/user.rb index 02a72777..dfc47b5b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,7 @@ class User < ApplicationRecord include Authority::UserAbilities validates_uniqueness_of :username, allow_nil: true, allow_blank: true + validates :username, length: { in: 1..20 } has_many :subscriptions, dependent: :destroy has_many :billing_plans, through: :subscriptions From d75cc4b07ff7ccafa176418aeff58b000156df05 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 15 Jan 2019 18:11:26 -0600 Subject: [PATCH 02/14] require usernames to be alphanumeric --- app/models/user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/user.rb b/app/models/user.rb index dfc47b5b..caf95de0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,6 +13,7 @@ class User < ApplicationRecord validates_uniqueness_of :username, allow_nil: true, allow_blank: true validates :username, length: { in: 1..20 } + validates :username, with: /^[A-Za-z0-9]+$/ has_many :subscriptions, dependent: :destroy has_many :billing_plans, through: :subscriptions From cd0dc21e5de7c707073f79ebf50ba4ee953f5d02 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 15 Jan 2019 18:20:01 -0600 Subject: [PATCH 03/14] allow accessing profile by /@andrew --- app/controllers/users_controller.rb | 10 ++++++++-- app/models/user.rb | 2 +- app/views/users/profile/_public_pages.html.erb | 2 +- app/views/users/show.html.erb | 2 +- config/routes.rb | 2 ++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 94379ecf..f1612ee3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,8 +5,8 @@ class UsersController < ApplicationController def show @sidenav_expansion = 'my account' - - @user = User.find_by(id: params[:id]) + + @user = User.find_by(user_params) return redirect_to(root_path, notice: 'That user does not exist.') if @user.nil? @content = @user.public_content.select { |type, list| list.any? } @@ -70,4 +70,10 @@ class UsersController < ApplicationController notifier.ping ":bomb: :bomb: :bomb: #{user.email.split('@').first}@ (##{user.id}) just deleted their account." end + + private + + def user_params + params.permit(:id, :username) + end end diff --git a/app/models/user.rb b/app/models/user.rb index caf95de0..6c88a336 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,8 +12,8 @@ class User < ApplicationRecord include Authority::UserAbilities validates_uniqueness_of :username, allow_nil: true, allow_blank: true + validates_format_of :username, with: /\A[A-Za-z0-9]+\z/ validates :username, length: { in: 1..20 } - validates :username, with: /^[A-Za-z0-9]+$/ has_many :subscriptions, dependent: :destroy has_many :billing_plans, through: :subscriptions diff --git a/app/views/users/profile/_public_pages.html.erb b/app/views/users/profile/_public_pages.html.erb index 1a26f6e4..8af92018 100644 --- a/app/views/users/profile/_public_pages.html.erb +++ b/app/views/users/profile/_public_pages.html.erb @@ -7,7 +7,7 @@ <% @tabs.each do |tab| %> <% content_type_class = @user.send(tab).build.class %> - <%= link_to send("#{tab}_user_path"), class: "collection-item #{content_type_class.color}-text" do %> + <%= link_to send("#{tab}_user_path", { id: @user.id }), class: "collection-item #{content_type_class.color}-text" do %> <%= pluralize @content[tab].length, tab.to_s.singularize %> <%= content_type_class.icon %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 7376faeb..0fc9ba2d 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -5,7 +5,7 @@ image_src: @user.image_url(120) content_jsonld = { - '@id': user_url, + '@id': user_url(id: @user.id), '@type': 'http://schema.org/Person', 'http://schema.org/name': @user.name, 'http://schema.org/description': "#{@user.name}’s profile on notebook.ai", diff --git a/config/routes.rb b/config/routes.rb index dd50f289..54339224 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,6 +12,8 @@ Rails.application.routes.draw do get content_type.name.downcase.pluralize.to_sym, on: :member end end + get '/@:username', to: 'users#show' + scope '/my' do get '/content', to: 'main#dashboard', as: :dashboard get '/content/recent', to: 'main#recent_content', as: :recent_content From 398c4d0661ad982b687bf82509f49307c88b7471 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 15 Jan 2019 18:23:33 -0600 Subject: [PATCH 04/14] expose username link on profile --- app/views/users/profile/_info.html.erb | 2 +- config/routes.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/users/profile/_info.html.erb b/app/views/users/profile/_info.html.erb index d3107644..1cacbdb8 100644 --- a/app/views/users/profile/_info.html.erb +++ b/app/views/users/profile/_info.html.erb @@ -28,7 +28,7 @@ Username
- <%= link_to "@#{@user.username}", thredded_path %> + <%= link_to "@#{@user.username}", profile_by_username_path(username: @user.username) %>

<% end %> diff --git a/config/routes.rb b/config/routes.rb index 54339224..5af4e715 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ Rails.application.routes.draw do get content_type.name.downcase.pluralize.to_sym, on: :member end end - get '/@:username', to: 'users#show' + get '/@:username', to: 'users#show', as: :profile_by_username scope '/my' do get '/content', to: 'main#dashboard', as: :dashboard From 8a2fe077304630656683ac485f4c352342d2620d Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 15 Jan 2019 18:52:32 -0600 Subject: [PATCH 05/14] use new username path when available --- app/models/user.rb | 8 ++++++++ .../devise/registrations/panes/_information.html.erb | 1 + app/views/layouts/_sidenav.html.erb | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 6c88a336..2c6bd652 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -190,6 +190,14 @@ class User < ApplicationRecord found_key.user end + def profile_url + if self.username.present? + Rails.application.routes.url_helpers.profile_by_username_path(username: self.username) + else + Rails.application.routes.url_helpers.user_path(id: self.id) + end + end + private # Attributes that are non-public, and should be blacklisted from any public diff --git a/app/views/devise/registrations/panes/_information.html.erb b/app/views/devise/registrations/panes/_information.html.erb index 98dfc1a9..f511168e 100644 --- a/app/views/devise/registrations/panes/_information.html.erb +++ b/app/views/devise/registrations/panes/_information.html.erb @@ -16,6 +16,7 @@
<%= f.label 'Username (users can @mention you with your username on the forums)' %>
<%= f.text_field :username %> + Your profile will also be available at https://www.notebook.ai/@username.
diff --git a/app/views/layouts/_sidenav.html.erb b/app/views/layouts/_sidenav.html.erb index 46c786ed..9ec94cec 100644 --- a/app/views/layouts/_sidenav.html.erb +++ b/app/views/layouts/_sidenav.html.erb @@ -135,7 +135,7 @@
  • - <%= link_to current_user, class: 'waves-effect' do %> + <%= link_to current_user.profile_url, class: 'waves-effect' do %> person Profile <% end %> From 14981516788e513d9ca470830697b192d9be5f3e Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 15 Jan 2019 19:01:40 -0600 Subject: [PATCH 06/14] double length limit --- 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 2c6bd652..e06474f0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,7 +13,7 @@ class User < ApplicationRecord validates_uniqueness_of :username, allow_nil: true, allow_blank: true validates_format_of :username, with: /\A[A-Za-z0-9]+\z/ - validates :username, length: { in: 1..20 } + validates :username, length: { in: 1..40 } has_many :subscriptions, dependent: :destroy has_many :billing_plans, through: :subscriptions From 1d506d005b02633ecb84891ffacb8b81e36a970f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 15 Jan 2019 19:07:57 -0600 Subject: [PATCH 07/14] allow - and _ in usernames --- 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 e06474f0..10caeba9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,7 +12,7 @@ class User < ApplicationRecord include Authority::UserAbilities validates_uniqueness_of :username, allow_nil: true, allow_blank: true - validates_format_of :username, with: /\A[A-Za-z0-9]+\z/ + validates_format_of :username, with: /\A[A-Za-z0-9\-_]+\z/ validates :username, length: { in: 1..40 } has_many :subscriptions, dependent: :destroy From adfd8e9d6a3549366c083e45c671b067c272c737 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 15 Jan 2019 19:42:15 -0600 Subject: [PATCH 08/14] allow most symbols in RFC 1738 --- 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 10caeba9..ab7a2e6b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,7 +12,7 @@ class User < ApplicationRecord include Authority::UserAbilities validates_uniqueness_of :username, allow_nil: true, allow_blank: true - validates_format_of :username, with: /\A[A-Za-z0-9\-_]+\z/ + validates_format_of :username, with: /\A[A-Za-z0-9\-_\$\+\!\*\(\)]+\z/ validates :username, length: { in: 1..40 } has_many :subscriptions, dependent: :destroy From 86927d604376c6abf6de7257a3e7d85925901668 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 11 Mar 2019 14:26:19 -0500 Subject: [PATCH 09/14] update missed url --- app/views/main/dashboard.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/main/dashboard.html.erb b/app/views/main/dashboard.html.erb index 3aeeed09..a03d8f51 100644 --- a/app/views/main/dashboard.html.erb +++ b/app/views/main/dashboard.html.erb @@ -40,7 +40,7 @@
- <%= link_to current_user do %> + <%= link_to current_user.profile_url do %>
From 79158425f47ba33bbf2d8ab71b226d073984eea2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 11 Mar 2019 14:50:40 -0500 Subject: [PATCH 10/14] mildly cleaner user#edit error messages --- app/models/user.rb | 4 ++-- app/views/devise/registrations/edit.html.erb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index ab7a2e6b..7b2f281f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,8 +12,8 @@ class User < ApplicationRecord include Authority::UserAbilities validates_uniqueness_of :username, allow_nil: true, allow_blank: true - validates_format_of :username, with: /\A[A-Za-z0-9\-_\$\+\!\*\(\)]+\z/ - validates :username, length: { in: 1..40 } + validates_format_of :username, with: /\A[A-Za-z0-9\-_\$\+\!\*]+\z/, message: 'must be between 1 and 40 alphanumeric characters (-, _, $, +, !, and * also accepted)' + validates :username, length: { in: 0..40, message: 'must be between 1 and 40 alphanumeric characters (-, _, $, +, !, and * also accepted)' } has_many :subscriptions, dependent: :destroy has_many :billing_plans, through: :subscriptions diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 9b5387c2..a2328d78 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,5 +1,7 @@ <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> - <%= devise_error_messages! %> +
+ <%= devise_error_messages! %> +
From 2f17b8294b6c0944e52f3ce934751d3d14dee47c Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 11 Mar 2019 14:59:28 -0500 Subject: [PATCH 11/14] help text in form --- app/views/devise/registrations/panes/_information.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/devise/registrations/panes/_information.html.erb b/app/views/devise/registrations/panes/_information.html.erb index f511168e..e89911a3 100644 --- a/app/views/devise/registrations/panes/_information.html.erb +++ b/app/views/devise/registrations/panes/_information.html.erb @@ -16,7 +16,8 @@
<%= f.label 'Username (users can @mention you with your username on the forums)' %>
<%= f.text_field :username %> - Your profile will also be available at https://www.notebook.ai/@username. + Your Notebook.ai profile will be available at https://www.notebook.ai/@username.
+ Up to 40 numbers, letters, and/or the following symbols are allowed: - _ $ + ! *
From a6ee9f8ab175d52dc7d256083ed46d1e0ea6a0ff Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 11 Mar 2019 15:05:34 -0500 Subject: [PATCH 12/14] update thredded and i18n --- Gemfile.lock | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 60802fc5..630c57fb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,7 +58,7 @@ GEM ast (2.4.0) authority (3.3.0) activesupport (>= 3.0.0) - autoprefixer-rails (9.4.5) + autoprefixer-rails (9.4.10.2) execjs aws-eventstream (1.0.1) aws-partitions (1.131.0) @@ -123,7 +123,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.4) + concurrent-ruby (1.1.5) connection_pool (2.2.2) crack (0.4.3) safe_yaml (~> 1.0.0) @@ -174,7 +174,7 @@ GEM railties (>= 3.0.0) faraday (0.15.4) multipart-post (>= 1.2, < 3) - ffi (1.9.25) + ffi (1.10.0) filesize (0.2.0) flamegraph (0.9.5) font-awesome-rails (4.7.0.4) @@ -209,7 +209,7 @@ GEM activesupport (>= 2) nokogiri (>= 1.4) htmlentities (4.3.4) - i18n (1.5.2) + i18n (1.6.0) concurrent-ruby (~> 1.0) inline_svg (1.3.1) activesupport (>= 3.0) @@ -235,7 +235,9 @@ GEM activerecord kaminari-core (= 1.1.1) kaminari-core (1.1.1) - kramdown (1.17.0) + kramdown (2.1.0) + kramdown-parser-gfm (1.0.1) + kramdown (~> 2.0) libv8 (6.7.288.46.1) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) @@ -285,7 +287,7 @@ GEM notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) - onebox (1.8.76) + onebox (1.8.82) htmlentities (~> 4.3) moneta (~> 1.0) multi_json (~> 1.11) @@ -313,7 +315,7 @@ GEM puma (3.12.0) puma-heroku (1.0.0) puma (~> 3.0) - pundit (2.0.0) + pundit (2.0.1) activesupport (>= 3.0.0) rack (2.0.6) rack-mini-profiler (1.0.1) @@ -389,7 +391,7 @@ GEM responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) - rinku (2.0.4) + rinku (2.0.5) rmagick (2.16.0) rspec (3.8.0) rspec-core (~> 3.8.0) @@ -443,8 +445,8 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.0.0) - ffi (~> 1.9.6) + sassc (2.0.1) + ffi (~> 1.9) rake sassc-rails (2.1.0) railties (>= 4.0.0) @@ -494,7 +496,7 @@ GEM climate_control (>= 0.0.3, < 1.0) thor (0.20.3) thread_safe (0.3.6) - thredded (0.16.4) + thredded (0.16.9) active_record_union (>= 1.3.0) autoprefixer-rails db_text_search (~> 0.3.0) @@ -503,7 +505,8 @@ GEM htmlentities inline_svg kaminari - kramdown (>= 1.17.0) + kramdown (>= 2.0.0) + kramdown-parser-gfm nokogiri onebox (~> 1.8, >= 1.8.48) pundit (>= 1.1.0) @@ -619,4 +622,4 @@ RUBY VERSION ruby 2.5.1p57 BUNDLED WITH - 1.16.4 + 1.17.3 From 83ea63754576874977a69d22538d34ad17a53bf5 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 11 Mar 2019 15:23:24 -0500 Subject: [PATCH 13/14] aside-posts --- app/views/thredded/posts/_post.html.erb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/views/thredded/posts/_post.html.erb diff --git a/app/views/thredded/posts/_post.html.erb b/app/views/thredded/posts/_post.html.erb new file mode 100644 index 00000000..00147364 --- /dev/null +++ b/app/views/thredded/posts/_post.html.erb @@ -0,0 +1,20 @@ +<% post, content = post_and_content if local_assigns.key?(:post_and_content) %> + +<% + muted_post = post.present? && post.to_model.content.split("\n").reject(&:empty?).all? { |paragraph| paragraph.strip.start_with?('(') && paragraph.strip.end_with?(')') } + muted_post_classes = 'grey lighten-4 grey-text text-darken-2' +%> + +<%= render 'thredded/posts_common/before_first_unread_post', post: post if post.first_unread_in_page? %> +<%= content_tag :article, id: dom_id(post), class: "thredded--post thredded--#{post.read_state}--post #{muted_post_classes if muted_post}" do %> + <%= render 'thredded/posts_common/actions', post: post, actions: local_assigns[:actions] %> + <%= render 'thredded/posts_common/header', post: post %> + <%= content || render('thredded/posts/content', post: post) %> + <% if post.pending_moderation? && !Thredded.content_visible_while_pending_moderation %> +

<%= t 'thredded.posts.pending_moderation_notice' %>

+ <% elsif post.blocked? && post.can_moderate? %> +

+ <%= render 'thredded/shared/content_moderation_blocked_state', moderation_record: post.last_moderation_record %> +

+ <% end %> +<% end %> From 7136981f2ecea53431dd571deee85615078281c2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 11 Mar 2019 15:30:42 -0500 Subject: [PATCH 14/14] emphasize non-muted posts more --- app/views/thredded/posts/_post.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/thredded/posts/_post.html.erb b/app/views/thredded/posts/_post.html.erb index 00147364..48127ee4 100644 --- a/app/views/thredded/posts/_post.html.erb +++ b/app/views/thredded/posts/_post.html.erb @@ -6,7 +6,7 @@ %> <%= render 'thredded/posts_common/before_first_unread_post', post: post if post.first_unread_in_page? %> -<%= content_tag :article, id: dom_id(post), class: "thredded--post thredded--#{post.read_state}--post #{muted_post_classes if muted_post}" do %> +<%= content_tag :article, id: dom_id(post), class: "thredded--post thredded--#{post.read_state}--post #{muted_post ? muted_post_classes : 'card'}" do %> <%= render 'thredded/posts_common/actions', post: post, actions: local_assigns[:actions] %> <%= render 'thredded/posts_common/header', post: post %> <%= content || render('thredded/posts/content', post: post) %>