Commit 03b6030
app/models/scim/user.rb
@@ -4,10 +4,11 @@ module SCIM
class User
include ActiveModel::Model
attr_accessor :id, :schemas, :userName, :name, :locale, :timezone, :password
+ UUID_REGEX = /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
validate :must_be_user_schema
- validates :id, format: { with: /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/ }, if: proc { |x| x.id.present? }
- validates :locale, presence: true, inclusion: I18n.available_locales.map(&:to_s)
+ validates :id, format: { with: UUID_REGEX }, if: proc { |x| x.id.present? }
+ validates :locale, presence: true, inclusion: ::User::VALID_LOCALES
validates :timezone, presence: true, inclusion: ::User::VALID_TIMEZONES
validates :userName, presence: true, email: true
@@ -30,7 +31,8 @@ module SCIM
end
def ensure_password_update_is_allowed!(user)
- raise StandardError.new(I18n.t('.password_update_not_permitted')) unless Current.user == user
+ error = I18n.t('.password_update_not_permitted')
+ raise StandardError.new(error) unless Current.user == user
end
def to_h(extra = {})
app/models/user.rb
@@ -2,6 +2,7 @@
class User < ApplicationRecord
VALID_TIMEZONES = ActiveSupport::TimeZone::MAPPING.values
+ VALID_LOCALES = I18n.available_locales.map(&:to_s)
has_secure_password
has_many :sessions, foreign_key: "user_id", class_name: UserSession.name
@@ -9,7 +10,7 @@ class User < ApplicationRecord
case_sensitive: false
}
validates :timezone, inclusion: VALID_TIMEZONES
- validates :locale, inclusion: { in: proc { I18n.available_locales.map(&:to_s) } }
+ validates :locale, inclusion: VALID_LOCALES
after_initialize do
self.uuid = SecureRandom.uuid unless uuid
db/schema.rb
@@ -12,14 +12,6 @@
ActiveRecord::Schema.define(version: 2018_09_22_211216) do
- create_table "authentications", force: :cascade do |t|
- t.integer "user_id"
- t.string "type", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["user_id"], name: "index_authentications_on_user_id"
- end
-
create_table "authorizations", force: :cascade do |t|
t.integer "user_id"
t.integer "client_id"