diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 53d1cf01a78b3d303de0fa30ac32ec19130c64e0..c964fdea1e943936cb295e287256ea03b2a8ea89 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:invitation_token]) devise_parameter_sanitizer.permit(:account_update) do |u| - u.permit(:name, :email, :password, :password_confirmation, :avatar_color, :telegram_username, :current_password) + u.permit(:name, :email, :password, :password_confirmation, :avatar_color, :languages_from, :languages_to, :telegram_username, :current_password) end end diff --git a/app/models/user.rb b/app/models/user.rb index 867e3ad47b76822e6d1ae16aa0c361c6ee5788a5..29a0fb24b48ba0c17919c09a4b468b449290c513 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,6 +7,12 @@ class User < ApplicationRecord validates :name, uniqueness: { case_sensitive: false, message: "already in use" }, allow_nil: false validates :email, uniqueness: { case_sensitive: false, message: "already in use" }, allow_nil: true, allow_blank: true + validates :languages_from, format: { with: /\A([a-z][a-z])(,[a-z][a-z])*\z/, message: "please use comma-separated two-letter codes"}, allow_blank: true + validates :languages_from, length: { maximum: 14 } + + validates :languages_to, format: { with: /\A([a-z][a-z])(,[a-z][a-z])*\z/, message: "please use comma-separated two-letter codes"}, allow_blank: true + validates :languages_to, length: { maximum: 14 } + validates :invitation_token, presence: true, on: :create validate :valid_invitation_token, on: :create diff --git a/app/views/assignments/_user_avatar.html.erb b/app/views/assignments/_user_avatar.html.erb index a22856edc9601909d4cf88525706a5894a68b045..1ed52596f4a94b6ab4f31d13ce0dd388e7434b9b 100644 --- a/app/views/assignments/_user_avatar.html.erb +++ b/app/views/assignments/_user_avatar.html.erb @@ -11,3 +11,10 @@ <% end %> </button> </span> +<% if user.languages_from || user.languages_to %> +<small class="text-2xs uppercase font-light bg-black/10 rounded-sm p-1 mr-1" aria-label="Languages <%= user.name %> can translate" title="Languages <%= user.name %> can translate"> + <%= user.languages_from %> + <span aria-label="to">→</span> + <%= user.languages_to %> +</small> +<% end %> diff --git a/app/views/candidates/_user_avatar.html.erb b/app/views/candidates/_user_avatar.html.erb index 382cef8dddc6bb9b8b7c61d6c5b8664218197d5f..0197fff9ab32f03aec0274d4e7b260e73800a5bd 100644 --- a/app/views/candidates/_user_avatar.html.erb +++ b/app/views/candidates/_user_avatar.html.erb @@ -12,6 +12,13 @@ <% end %> </button> </span> +<% if user.languages_from || user.languages_to %> +<small class="text-2xs uppercase font-light bg-black/10 rounded-sm p-1 ml-1"> + <%= user.languages_from %> + <% if user.languages_from && user.languages_to %>→<% end %> + <%= user.languages_to %> +</small> +<% end %> <% if candidate.note %> <span class="relative ml-1.5"><span class="max-w-60 max-h-14 overflow-scroll bg-gray-600 text-white text-xs font-medium px-2 py-1 rounded-md relative inline-block"><%= candidate.note %></span><span class="w-0 h-0 border-t-[6px] border-t-transparent border-b-[6px] border-b-transparent border-r-[6px] border-r-gray-600 absolute left-[-5px] top-[20%] transform -translate-y-1/2"></span> </span> <% end %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 17dc3c45fe0f46fc8e6601996130d5c4702e9174..b517dde8e4bb763aedfffe5731ba39fa3ea5e9b0 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -43,6 +43,22 @@ <%= f.text_field :telegram_username %> </div> +<fieldset class="border border-gray-300 p-4 rounded-md"> + <legend class="text-lg font-semibold">More Languages Team Only</legend> + <i class="block">Please use comma-separated two-letter codes.</i> + <i class="block">Leave empty unless you are with the more languages team.</i> + + <div class="field"> + <%= f.label :languages_from %> + <%= f.text_field :languages_from, placeholder: "de,en" %> + </div> + + <div class="field"> + <%= f.label :languages_to %> + <%= f.text_field :languages_to, placeholder: "jp,es" %> + </div> + </fieldset> + <div class="field"> <%= f.label :current_password %> <i class="block">(we need your current password to confirm your changes)</i> diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c349ae5e37433af7fd8c4ced3b219e710a368c3..23e7f5b0a21458e6559c660ed4c582961945d2d3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -29,3 +29,10 @@ en: hello: "Hello world" + +en: + activerecord: + attributes: + user: + languages_from: "Languages you can translate from" + languages_to: "Languages you can translate to" diff --git a/db/migrate/20241222215716_add_languages_to_users.rb b/db/migrate/20241222215716_add_languages_to_users.rb new file mode 100644 index 0000000000000000000000000000000000000000..1f07c8acae394dd6965a87a7ce01f0f525c4a7b0 --- /dev/null +++ b/db/migrate/20241222215716_add_languages_to_users.rb @@ -0,0 +1,6 @@ +class AddLanguagesToUsers < ActiveRecord::Migration[7.1] + def change + add_column :users, :languages_from, :string + add_column :users, :languages_to, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 8a993e726cf15f3a5dc9fdbc8a68dd096be2c1f2..d3627a455be68900b67ab2e2fa0e07ebf0cefea6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_12_20_212328) do +ActiveRecord::Schema[7.1].define(version: 2024_12_22_215716) do create_table "assignments", force: :cascade do |t| t.integer "user_id", null: false t.integer "session_id", null: false @@ -279,6 +279,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_12_20_212328) do t.datetime "remember_created_at" t.boolean "shiftcoordinator", default: false, null: false t.string "invitation_token" + t.string "languages_from" + t.string "languages_to" end add_foreign_key "assignments", "sessions"