From 684a612b934ac3dde0838f004a68d2d0c6f01e9c Mon Sep 17 00:00:00 2001 From: Maikel Arcia Carrazana Date: Tue, 17 May 2022 15:16:26 -0400 Subject: [PATCH 1/3] Delete | Legacy user attrs --- app/models/user.rb | 18 ++++-------------- config/initializers/_cenit.rb | 2 -- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 2f7af124a..7ce329ca3 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,7 +13,7 @@ class User inspect_fields :name, :given_name, :family_name, :picture, :encrypted_password, - :account_id, :api_account_id, :code_theme, :time_zone + :account_id, :api_account_id, :time_zone rolify @@ -74,9 +74,6 @@ class User field :family_name, type: String field :picture_url, type: String - #UI options - field :code_theme, type: String - field :super_admin_enabled, type: Mongoid::Boolean def inspecting_fields @@ -90,13 +87,11 @@ def check_attributes end end - validates_inclusion_of :code_theme, in: ->(user) { user.code_theme_enum } - before_create do self.role_ids = ((role_ids || []) + ::Role.default_ids(self.class.empty?)).uniq self.account ||= accounts.first || member_accounts.first || Account.current || Account.new_for_create(owner_id: id) unless owns?(account) - errors.add(:account, 'is sealed and can not be inspected') if account && account.sealed? + errors.add(:account, 'is sealed and can not be inspected') if account&.sealed? end unless owns?(api_account) self.api_account = owns?(account) ? account : accounts.first @@ -141,15 +136,10 @@ def picture_url(size = 50) custom_picture_url(size) || read_attribute(:picture_url) || gravatar_or_identicon_url(size) end - def custom_picture_url(size) + def custom_picture_url(_size) picture.present? && picture.url end - def code_theme_enum - [nil, ''] + - %w(3024-day 3024-night abcdef ambiance-mobile ambiance base16-dark base16-light bespin blackboard cobalt colorforth dracula eclipse elegant erlang-dark hopscotch icecoder isotope lesser-dark liquibyte material mbo mdn-like midnight monokai neat neo night panda-syntax paraiso-dark paraiso-light pastel-on-dark railscasts rubyblue seti solarized the-matrix tomorrow-night-bright tomorrow-night-eighties ttcn twilight vibrant-ink xq-dark xq-light yeti zenburn) - end - def user self end @@ -227,7 +217,7 @@ def identicon(size = 50) end def gravatar_or_identicon_url(size = 50) - if gravatar() + if gravatar "//gravatar.com/avatar/#{Digest::MD5.hexdigest avatar_id.to_s}?s=#{size}" else identicon size diff --git a/config/initializers/_cenit.rb b/config/initializers/_cenit.rb index e4ebf7234..de8c04176 100644 --- a/config/initializers/_cenit.rb +++ b/config/initializers/_cenit.rb @@ -56,8 +56,6 @@ delay_tasks ENV['DELAY_TASKS'].to_b - default_code_theme 'monokai' - request_timeout ENV['REQUEST_TIMEOUT'] || 300 using_accounts_dbs ENV['USING_ACCOUNTS_DBS'] From 4a521f11a412d3bf43ea467d1076ef2b9b3cd7bb Mon Sep 17 00:00:00 2001 From: Maikel Arcia Carrazana Date: Tue, 17 May 2022 15:18:50 -0400 Subject: [PATCH 2/3] Add | Need password reset option --- app/models/user.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 7ce329ca3..09c1e1451 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,7 +19,7 @@ class User build_in_data_type .on_origin(:admin) - .with(:email, :name, :account, :roles, :super_admin_enabled) + .with(:email, :name, :account, :roles, :super_admin_enabled, :need_password_reset) .and( label: '{{name}} ({{email}})', properties: { @@ -76,6 +76,8 @@ class User field :super_admin_enabled, type: Mongoid::Boolean + field :need_password_reset, type: Mongoid::Boolean + def inspecting_fields super + (has_role?(:super_admin) ? [:super_admin_enabled] : []) end @@ -85,6 +87,9 @@ def check_attributes if attributes['name'] && attributes['given_name'].present? && attributes['family_name'].present? remove_attribute(:name) end + if !new_record? && changed_attributes.key?('encrypted_password') + remove_attribute(:need_password_reset) + end end before_create do From 35d0071f452b415f7d64173fa5e4ae3c2c2f5ebc Mon Sep 17 00:00:00 2001 From: Maikel Arcia Carrazana Date: Tue, 17 May 2022 15:23:03 -0400 Subject: [PATCH 3/3] Add | Send reset password instructions --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index b9f3ee29c..9bd124638 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: https://github.com/cenit-io/cenit-admin.git - revision: c90addcdb12ec7a0a55a7a333cc16bcd0a470ca3 + revision: a73b378fe6e69ed4ac80a7fc04f023ee78190ea7 specs: cenit-admin (0.0.1)