Browse Source

WIP adding user roles view; adding end datetime to user roles

denney-disable-on-select
John N. Milner 12 years ago
parent
commit
a3fcdec10c
  1. 3
      app/components/app_tab_panel.rb
  2. 15
      app/components/user_roles.rb
  3. 6
      app/models/user.rb
  4. 2
      app/models/user_role.rb
  5. 7
      db/migrate/20130419010051_add_ends_to_user_roles.rb
  6. 4
      db/schema.rb
  7. 9
      db/seed/fixtures/user_roles.yml
  8. 3
      db/seeds.rb
  9. 19
      spec/factories/user_roles.rb
  10. 11
      spec/factories/users.rb

3
app/components/app_tab_panel.rb

@ -36,7 +36,8 @@ class AppTabPanel < Netzke::Basepack::TabPanel
{ layout: :fit, { layout: :fit,
wrappedComponent: :transactions_border, wrappedComponent: :transactions_border,
title: "Transactions"}, title: "Transactions"},
:logs] :logs,
:user_roles]
end end
@@app_tab_panel_items.each do |item| @@app_tab_panel_items.each do |item|

15
app/components/user_roles.rb

@ -0,0 +1,15 @@
class UserRoles < Netzke::Basepack::Grid
def configure(c)
super
c.model = "UserRole"
c.title = "User Roles"
c.columns = [ :role, :created_at, :updated_at, :ends ]
end
#override with nil to remove actions
def default_bbar
[ :apply, :add_in_form, :search ]
end
end

6
app/models/user.rb

@ -14,7 +14,7 @@ class User < ActiveRecord::Base
has_many :user_profiles has_many :user_profiles
accepts_nested_attributes_for :user_profiles, allow_destroy: false accepts_nested_attributes_for :user_profiles, allow_destroy: false
belongs_to :user_role has_one :user_role
belongs_to :bike belongs_to :bike
validates :first_name, :presence => true validates :first_name, :presence => true
@ -24,6 +24,10 @@ class User < ActiveRecord::Base
"#{first_name} #{last_name}" "#{first_name} #{last_name}"
end end
def full_name
to_s
end
def role def role
user_role.role user_role.role
end end

2
app/models/user_role.rb

@ -1,7 +1,7 @@
class UserRole < ActiveRecord::Base class UserRole < ActiveRecord::Base
attr_accessible :role attr_accessible :role
has_many :users belongs_to :user
self.per_page = 15 self.per_page = 15

7
db/migrate/20130419010051_add_ends_to_user_roles.rb

@ -0,0 +1,7 @@
class AddEndsToUserRoles < ActiveRecord::Migration
def change
add_column(:user_roles, :ends, :timestamp)
add_column(:user_roles, :user_id, :integer)
remove_column(:users, :role_id)
end
end

4
db/schema.rb

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130405012238) do ActiveRecord::Schema.define(:version => 20130419010051) do
create_table "bike_actions", :force => true do |t| create_table "bike_actions", :force => true do |t|
t.string "action", :limit => 128, :null => false t.string "action", :limit => 128, :null => false
@ -152,6 +152,8 @@ ActiveRecord::Schema.define(:version => 20130405012238) do
t.string "role" t.string "role"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.datetime "ends"
t.integer "user_id"
end end
create_table "users", :force => true do |t| create_table "users", :force => true do |t|

9
db/seed/fixtures/user_roles.yml

@ -1,9 +0,0 @@
user:
id: 1
role: user
staff:
id: 2
role: staff
admin:
id: 3
role: admin

3
db/seeds.rb

@ -21,10 +21,11 @@ end
if Rails.env.development? if Rails.env.development?
#create default admin user #create default admin user
if User.all.empty? if UserRole.all.empty? and User.all.empty?
FactoryGirl.create(:user) FactoryGirl.create(:user)
FactoryGirl.create(:staff) FactoryGirl.create(:staff)
FactoryGirl.create(:admin) FactoryGirl.create(:admin)
FactoryGirl.create(:bike_admin)
FactoryGirl.create(:user_profile) FactoryGirl.create(:user_profile)
end end

19
spec/factories/user_roles.rb

@ -0,0 +1,19 @@
FactoryGirl.define do
factory :user_role do
factory :role_staff do
role 'staff'
end
factory :role_admin do
role 'admin'
end
factory :role_bike_admin do
role 'bike_admin'
end
factory :role_user do
role 'user'
end
end
end

11
spec/factories/users.rb

@ -5,17 +5,22 @@ FactoryGirl.define do
password_confirmation { password } password_confirmation { password }
first_name 'Michael' first_name 'Michael'
last_name 'Scott' last_name 'Scott'
user_role_id 1
sequence(:bike_id) { |n| n } sequence(:bike_id) { |n| n }
association :user_role, factory: :role_user
factory :staff do factory :staff do
first_name 'Staff' first_name 'Staff'
user_role_id 2 association :user_role, factory: :role_staff
end end
factory :admin do factory :admin do
first_name 'Admin' first_name 'Admin'
user_role_id 3 association :user_role, factory: :role_admin
end
factory :bike_admin do
first_name 'BikeAdmin'
association :user_role, factory: :role_bike_admin
end end
end end

Loading…
Cancel
Save