diff --git a/app/components/app_tab_panel.rb b/app/components/app_tab_panel.rb index 41188a5..faf4bc8 100644 --- a/app/components/app_tab_panel.rb +++ b/app/components/app_tab_panel.rb @@ -36,7 +36,8 @@ class AppTabPanel < Netzke::Basepack::TabPanel { layout: :fit, wrappedComponent: :transactions_border, title: "Transactions"}, - :logs] + :logs, + :user_roles] end @@app_tab_panel_items.each do |item| diff --git a/app/components/user_roles.rb b/app/components/user_roles.rb new file mode 100644 index 0000000..4de2383 --- /dev/null +++ b/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 diff --git a/app/models/user.rb b/app/models/user.rb index b55c290..9b67e65 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,7 +14,7 @@ class User < ActiveRecord::Base has_many :user_profiles accepts_nested_attributes_for :user_profiles, allow_destroy: false - belongs_to :user_role + has_one :user_role belongs_to :bike validates :first_name, :presence => true @@ -24,6 +24,10 @@ class User < ActiveRecord::Base "#{first_name} #{last_name}" end + def full_name + to_s + end + def role user_role.role end diff --git a/app/models/user_role.rb b/app/models/user_role.rb index 371ff0a..5a9452f 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -1,7 +1,7 @@ class UserRole < ActiveRecord::Base attr_accessible :role - has_many :users + belongs_to :user self.per_page = 15 diff --git a/db/migrate/20130419010051_add_ends_to_user_roles.rb b/db/migrate/20130419010051_add_ends_to_user_roles.rb new file mode 100644 index 0000000..fe5352a --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index abb82cf..fcb1f7c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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| t.string "action", :limit => 128, :null => false @@ -152,6 +152,8 @@ ActiveRecord::Schema.define(:version => 20130405012238) do t.string "role" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.datetime "ends" + t.integer "user_id" end create_table "users", :force => true do |t| diff --git a/db/seed/fixtures/user_roles.yml b/db/seed/fixtures/user_roles.yml deleted file mode 100644 index 46f26fc..0000000 --- a/db/seed/fixtures/user_roles.yml +++ /dev/null @@ -1,9 +0,0 @@ -user: - id: 1 - role: user -staff: - id: 2 - role: staff -admin: - id: 3 - role: admin diff --git a/db/seeds.rb b/db/seeds.rb index 7222d33..6d1f3c2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -21,10 +21,11 @@ end if Rails.env.development? #create default admin user - if User.all.empty? + if UserRole.all.empty? and User.all.empty? FactoryGirl.create(:user) FactoryGirl.create(:staff) FactoryGirl.create(:admin) + FactoryGirl.create(:bike_admin) FactoryGirl.create(:user_profile) end diff --git a/spec/factories/user_roles.rb b/spec/factories/user_roles.rb new file mode 100644 index 0000000..ac4d2f3 --- /dev/null +++ b/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 diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 9d74847..53c85a8 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -5,17 +5,22 @@ FactoryGirl.define do password_confirmation { password } first_name 'Michael' last_name 'Scott' - user_role_id 1 sequence(:bike_id) { |n| n } + association :user_role, factory: :role_user factory :staff do first_name 'Staff' - user_role_id 2 + association :user_role, factory: :role_staff end factory :admin do 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