Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
[#45] added a bunch of roles for exec positions, moved from applicati…
Browse files Browse the repository at this point in the history
…on.yml to role.rb; misc other changes
  • Loading branch information
Patrick Stoica committed Apr 18, 2014
1 parent f0a0d75 commit 20aabb1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 22 deletions.
44 changes: 44 additions & 0 deletions app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@
#

class Role < ActiveRecord::Base
# these are generated with `rake db:seed`
DEFAULT_ROLES = [
{ name: "general_manager",
full_name: "General Manager"},
{ name: "operations_manager",
full_name: "Operations Manager"},
{ name: "contest_director",
full_name: "Contest Director"},
{ name: "psa_director",
full_name: "PSA Director"},
{ name: "sports_director",
full_name: "Sports Director"},
{ name: "faculty_advisor",
full_name: "Faculty Advisor"},
{ name: "chief_engineer",
full_name: "Chief Engineer"},
{ name: "assistant_chief_engineer",
full_name: "Assistant Chief Engineer"},
{ name: "music_director",
full_name: "Music Director"},
{ name: "public_affairs_director",
full_name: "Public Affairs Director"},
{ name: "business_manager",
full_name: "Business Manager"},
{ name: "live_sound_director",
full_name: "Live Sound Director"},
{ name: "automation_czar",
full_name: "Automation Czar"},
{ name: "studio_director",
full_name: "Studio Director"},
{ name: "news_director",
full_name: "News Director"},
{ name: "traffic_director",
full_name: "Traffic Director"},
{ name: "media_director",
full_name: "Student Media Marketing and Advertising Director"},
{ name: "program_director",
full_name: "Program Director"},
{ name: "it_director",
full_name: "IT Director"},
{ name: "historian",
full_name: "Historian"},
]

has_and_belongs_to_many :users, join_table: :users_roles
belongs_to :resource, polymorphic: true

Expand Down
7 changes: 6 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def admin?
self.admin
end

def exec_staff?
self.exec_staff
end

# FIXME: these role methods should probably be refactored
def exec?(roles = [:contest_director, :psa_director])
roles = [roles] unless roles.kind_of? Array

Expand Down Expand Up @@ -156,7 +161,7 @@ def get_ldap_data
self.last_name ||= result.try(:sn).try(:first)
self.display_name ||= result.try(:displayName).try(:first)
self.status ||= result.try(:employeeType).try(:first) || "potential"
self.email ||= result.try(:mail).try(:first) || "#{username}@wrek.org"
self.email ||= result.try(:mail).try(:first) || "#{username}@fake.me"
end
end
end
Expand Down
1 change: 0 additions & 1 deletion config/application.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ ADMIN_LAST_NAME: Burdell
ADMIN_USERNAME: gpb
ADMIN_EMAIL: [email protected]
ADMIN_PASSWORD: password
ROLES: exec,contest_director,psa_director
USE_LDAP: false
14 changes: 13 additions & 1 deletion db/migrate/20140418182825_add_exec_staff_to_user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
class AddExecStaffToUser < ActiveRecord::Migration
def change
def up
add_column :users, :exec_staff, :boolean

User.with_role(:exec).each do |user|
user.remove_role :exec
user.exec_staff = true
user.save
end

Role.find_by(name: "exec").destroy
end

def down
remove_column :users, :exec_staff
end
end
32 changes: 18 additions & 14 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
# Environment variables (ENV['...']) are set in the file config/application.yml.
# See http://railsapps.github.io/rails-environment-variables.html
puts 'ROLES'
ENV['ROLES'].split(',').each do |role|
Role.find_or_create_by_name(role)
puts 'role: ' << role
Role::DEFAULT_ROLES.each do |role|
r = Role.find_or_initialize_by_name(role[:name])
r.full_name = role[:full_name]
r.save

puts "role: #{r.full_name}"
end

puts 'DEFAULT USERS'
user = User.find_by(email: '[email protected]') || User.new
user.email = '[email protected]'
user.first_name = 'George'
user.last_name = 'Burdell'
user.username = 'gpb'
user.password = 'password'
user.password_confirmation = 'password'
user.admin = true
user.save
unless Rails.env.production?
puts 'DEFAULT USERS'
user = User.find_or_initialize_by_email('[email protected]')
user.first_name = 'George'
user.last_name = 'Burdell'
user.username = 'gpb'
user.password = 'password'
user.password_confirmation = 'password'
user.admin = true
user.save

puts 'user: ' << user.name
puts 'user: ' << user.name
end
10 changes: 5 additions & 5 deletions lib/tasks/sync_from_staff.rake
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ task :sync_from_staff => :environment do |t, args|
user.admin = true
end

user.save!

# add appropriate roles

# exec is a reserved word, can't be a method name
is_exec = staff.read_attribute(:exec)
if is_exec.present? and is_exec.downcase == "y" and not user.has_role? :exec
user.add_role :exec
user.exec_staff = true
end

user.save!

# add appropriate roles here
end
end

0 comments on commit 20aabb1

Please sign in to comment.