Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Mar 1, 2024
1 parent 8ad5780 commit 4b15c43
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ApplicationController < ActionController::Base
before_action :authenticate_auth_user!

def check_admin
def render_unauthorized
return false if helpers.admin?

render 'unauthorized', status: :unauthorized
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/skills_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class SkillsController < CrudController
include ExportController

before_action :check_admin, except: %i[index show unrated_by_person]
before_action :render_unauthorized, except: %i[index show unrated_by_person]

self.permitted_attrs = %i[title radar portfolio default_set category_id]

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/auth_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module AuthHelper
def session_path(_scope)
new_person_session_path
new_auth_user_session_path
end

def admin?
Expand Down
6 changes: 3 additions & 3 deletions app/models/auth_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class AuthUser < ApplicationRecord

devise :omniauthable, omniauth_providers: [:keycloak_openid]


class << self
def from_omniauth(auth)
person = where(email: auth.info.email).first_or_create do |user|
person = where(uid: auth.uid).first_or_create do |user|
user.name = auth.info.name

user.email = auth.info.email
end
person.last_login = Time.zone.now
set_admin(person, auth)
end

Expand Down
29 changes: 0 additions & 29 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,4 @@ def picture_size

errors.add(:picture, 'grösse kann maximal 10MB sein')
end

class << self
def from_omniauth(auth) # rubocop:disable Metrics/AbcSize
person = where(email: auth.info.email).first_or_create do |user|
user.name = auth.info.name
user.birthdate = DateTime.new(2020, 1, 1)
user.nationality = 'CH'
user.location = 'Schweiz'
user.title = 'Software Engineer'
user.marital_status = :single
user.company = Company.first
end
set_admin(person, auth)
end

private

def set_admin(person, auth)
person.is_admin = admin?(auth)
person.save
person
end

def admin?(auth)
resources = auth.extra.raw_info.resource_access[AuthConfig.client_id]
resources.roles.include? AuthConfig.admin_role
end

end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
%pzsh-icon.scale-icon-08.text-gray(name="question-circle")
%li.d-flex.align-items-center.cursor-pointer.border-start.border-end.h-100.ps-2.pe-2
- if auth_user_signed_in?
=link_to "Logout", destroy_person_session_path, data: { "turbo-method": :delete}
=link_to "Logout", destroy_auth_user_session_path, data: { "turbo-method": :delete}
- elsif devise_mapping.omniauthable?
=button_to "Login", omniauth_authorize_path(resource_name, resource_class.omniauth_providers.first), {data: { "turbo": false}, class: "btn btn-link"}
%div
Expand Down
5 changes: 0 additions & 5 deletions db/migrate/20240229093827_add_is_admin_to_people.rb

This file was deleted.

1 change: 0 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
t.string "email"
t.integer "department_id"
t.string "shortname"
t.boolean "is_admin", default: false, null: false
t.index ["company_id"], name: "index_people_on_company_id"
end

Expand Down
2 changes: 0 additions & 2 deletions db/seeds/support/person_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def seed_people(names)
person.projects.each do |project|
seed_project_technology(project.id)
end
person.is_admin = false
end
end

Expand Down Expand Up @@ -103,7 +102,6 @@ def seed_person(name)
p.competence_notes = competence_notes
p.email = Faker::Internet.email
p.department_id = Department.all.pluck(:id).sample
p.is_admin = false
end
end

Expand Down

0 comments on commit 4b15c43

Please sign in to comment.