From 5decb702f2c27b624632310f2da20d1f376c40e9 Mon Sep 17 00:00:00 2001
From: Riccardo Graziosi <31478034+riggraz@users.noreply.github.com>
Date: Sat, 7 Sep 2024 18:10:45 +0200
Subject: [PATCH] Increase user full_name max length to 64 characters (#403)
---
app/controllers/o_auths_controller.rb | 1 +
app/javascript/components/TenantSignUp/TenantSignUpP.tsx | 2 +-
app/javascript/components/TenantSignUp/UserSignUpForm.tsx | 6 ++++--
app/models/user.rb | 2 +-
app/views/layouts/_header.html.erb | 2 +-
spec/models/user_spec.rb | 6 +++---
6 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/app/controllers/o_auths_controller.rb b/app/controllers/o_auths_controller.rb
index e5068955..6ec35a31 100644
--- a/app/controllers/o_auths_controller.rb
+++ b/app/controllers/o_auths_controller.rb
@@ -94,6 +94,7 @@ class OAuthsController < ApplicationController
@user_email = query_path_from_object(user_profile, @o_auth.json_user_email_path)
if not @o_auth.json_user_name_path.blank?
@user_name = query_path_from_object(user_profile, @o_auth.json_user_name_path)
+ @user_name = @user_name || I18n.t('defaults.user_full_name')
end
@o_auth_login_completed = (not @user_email.blank?)
diff --git a/app/javascript/components/TenantSignUp/TenantSignUpP.tsx b/app/javascript/components/TenantSignUp/TenantSignUpP.tsx
index 8dd84087..b16035e9 100644
--- a/app/javascript/components/TenantSignUp/TenantSignUpP.tsx
+++ b/app/javascript/components/TenantSignUp/TenantSignUpP.tsx
@@ -73,7 +73,7 @@ const TenantSignUpP = ({
const [goneBack, setGoneBack] = useState(false);
const [userData, setUserData] = useState({
- fullName: oAuthLoginCompleted ? oauthUserName : '',
+ fullName: (oAuthLoginCompleted && oauthUserName) ? oauthUserName.slice(0, 64) : '',
email: oAuthLoginCompleted ? oauthUserEmail : '',
password: '',
passwordConfirmation: '',
diff --git a/app/javascript/components/TenantSignUp/UserSignUpForm.tsx b/app/javascript/components/TenantSignUp/UserSignUpForm.tsx
index d5d431a6..48e8f8a1 100644
--- a/app/javascript/components/TenantSignUp/UserSignUpForm.tsx
+++ b/app/javascript/components/TenantSignUp/UserSignUpForm.tsx
@@ -102,13 +102,15 @@ const UserSignUpForm = ({
- {errors.fullName && getValidationMessage('required', 'user', 'full_name')}
+ {errors.fullName?.type === 'required' && getValidationMessage('required', 'user', 'full_name')}
+ {errors.fullName?.type === 'minLength' && (getLabel('user', 'full_name') + ' ' + I18n.t('activerecord.errors.messages.too_short', { count: 2 }))}
+ {errors.fullName?.type === 'maxLength' && (getLabel('user', 'full_name') + ' ' + I18n.t('activerecord.errors.messages.too_long', { count: 64 }))}
diff --git a/app/models/user.rb b/app/models/user.rb
index f9278da9..a2e85059 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -17,7 +17,7 @@ class User < ApplicationRecord
after_initialize :set_default_role, if: :new_record?
after_initialize :set_default_status, if: :new_record?
- validates :full_name, presence: true, length: { in: 2..32 }
+ validates :full_name, presence: true, length: { in: 2..64 }
validates :email,
presence: true,
uniqueness: { scope: :tenant_id, case_sensitive: false },
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb
index 95a4a8c8..70ae85e5 100644
--- a/app/views/layouts/_header.html.erb
+++ b/app/views/layouts/_header.html.erb
@@ -43,7 +43,7 @@
<%= image_tag(current_user.gravatar_url, class: 'gravatar', alt: current_user.full_name, size: 24) %>
- <%= current_user.full_name %>
+ <%= current_user.full_name.truncate(24) %>
<% if current_user.moderator? && Post.pending.length > 0 %>
<%= Post.pending.length %>
<% end %>
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 979e2312..758d1237 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -52,11 +52,11 @@ RSpec.describe User, type: :model do
expect(empty_name_user).to be_invalid
end
- it 'has a full name between 2 and 32 characters' do
+ it 'has a full name between 2 and 64 characters' do
too_short_user = FactoryBot.build(:user, full_name: 'a' * 1)
short_user = FactoryBot.build(:user, full_name: 'a' * 2)
- long_user = FactoryBot.build(:user, full_name: 'a' * 32)
- too_long_user = FactoryBot.build(:user, full_name: 'a' * 33)
+ long_user = FactoryBot.build(:user, full_name: 'a' * 64)
+ too_long_user = FactoryBot.build(:user, full_name: 'a' * 65)
expect(too_short_user).to be_invalid
expect(short_user).to be_valid