Skip to content

Commit

Permalink
Merge pull request #2969 from cenit-io/develop
Browse files Browse the repository at this point in the history
Add | Need password reset option
  • Loading branch information
macarci authored May 17, 2022
2 parents 0f3b804 + 93b883f commit e702ced
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
25 changes: 10 additions & 15 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ 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

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: {
Expand Down Expand Up @@ -74,11 +74,10 @@ 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

field :need_password_reset, type: Mongoid::Boolean

def inspecting_fields
super + (has_role?(:super_admin) ? [:super_admin_enabled] : [])
end
Expand All @@ -88,15 +87,16 @@ 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

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
Expand Down Expand Up @@ -141,15 +141,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
Expand Down Expand Up @@ -227,7 +222,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
Expand Down
2 changes: 0 additions & 2 deletions config/initializers/_cenit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit e702ced

Please sign in to comment.