Skip to content

Commit

Permalink
Merge branch 'master' into ics
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianAppDev authored Jul 12, 2024
2 parents 99503b0 + 77873eb commit a17e905
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
7 changes: 0 additions & 7 deletions app/controllers/external_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ def create_user

user = User.find_by(external_id: credentials['uid'], provider:)

# Fallback mechanism to search by email
if user.blank?
user = User.find_by(email: credentials['info']['email'], provider:)
# Update the user's external id to the latest value to avoid using the fallback
user.update(external_id: credentials['uid']) if user.present? && credentials['uid'].present?
end

new_user = user.blank?

registration_method = SettingGetter.new(setting_name: 'RegistrationMethod', provider: current_provider).call
Expand Down
29 changes: 18 additions & 11 deletions app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Role < ApplicationRecord
has_many :role_permissions, dependent: :destroy
has_many :permissions, through: :role_permissions

validates :name, presence: true, uniqueness: { scope: :provider }
validates :name, presence: true, uniqueness: { case_sensitive: false, scope: :provider }

validates :provider, presence: true

before_validation :set_role_color, on: :create
Expand Down Expand Up @@ -59,15 +60,21 @@ def create_role_permissions
private

def set_role_color
self.color = case name
when 'Administrator'
'#228B22'
when 'User'
'#4169E1'
when 'Guest'
'#FFA500'
else
"##{SecureRandom.hex(3)}"
end
color = case name
when 'Administrator'
'#228B22'
when 'User'
'#4169E1'
when 'Guest'
'#FFA500'
else
"##{SecureRandom.hex(3)}"
end

raise if Role.exists?(color:) # Ensure uniqueness

self.color = color
rescue StandardError
retry
end
end

0 comments on commit a17e905

Please sign in to comment.