mirror of
https://github.com/fspc/BikeShed-1.git
synced 2026-09-16 08:31:36 -04:00
Changing UserRole to UserRoleJoin
Beware, this breaks the view for some reason
This commit is contained in:
@@ -37,7 +37,8 @@ class AppTabPanel < Netzke::Basepack::TabPanel
|
||||
wrappedComponent: :transactions_border,
|
||||
title: "Transactions"},
|
||||
:logs,
|
||||
:user_roles]
|
||||
:user_roles
|
||||
]
|
||||
end
|
||||
|
||||
@@app_tab_panel_items.each do |item|
|
||||
|
||||
@@ -53,7 +53,7 @@ class UserLogs < Netzke::Basepack::Grid
|
||||
bike_store = Bike.all.map { |b| [b.id, b.shop_id] }
|
||||
current_user ||= User.find_by_id(session[:selected_user_id]) || controller.current_user
|
||||
bike_id = current_user.bike.nil? ? nil : current_user.bike.id
|
||||
action_id = current_user.user_role.id
|
||||
action_id = ::ActsAsLoggable::UserAction.all.first.id
|
||||
[
|
||||
{ :name => :start_date},
|
||||
{ :name => :end_date},
|
||||
|
||||
@@ -2,9 +2,9 @@ class UserRoles < Netzke::Basepack::Grid
|
||||
|
||||
def configure(c)
|
||||
super
|
||||
c.model = "UserRole"
|
||||
c.model = "UserRoleJoin"
|
||||
c.title = "User Roles"
|
||||
c.columns = [ :role, :created_at, :updated_at, :ends ]
|
||||
#c.columns = [ :user__first_name, :role__role, :created_at, :updated_at, :ends ]
|
||||
end
|
||||
|
||||
#override with nil to remove actions
|
||||
|
||||
@@ -9,7 +9,6 @@ class Users < Netzke::Basepack::Grid
|
||||
:last_name,
|
||||
:nickname,
|
||||
:email,
|
||||
:user_role__role,
|
||||
:bike__shop_id
|
||||
]
|
||||
end
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
class Ability
|
||||
include CanCan::Ability
|
||||
|
||||
|
||||
def initialize(current_user)
|
||||
@current_user = current_user
|
||||
self.send(current_user.role.to_sym)
|
||||
self.send(current_user.role.role.to_sym)
|
||||
end
|
||||
|
||||
def admin
|
||||
can :manage, :all
|
||||
end
|
||||
end
|
||||
|
||||
def staff
|
||||
can :manage, :all
|
||||
@@ -21,7 +21,7 @@ class Ability
|
||||
|
||||
def user
|
||||
can :read, :all
|
||||
can :update, Bike, :id => @current_user.bike_id unless @current_user.bike.nil?
|
||||
can :manage, Bike, :id => @current_user.bike_id unless @current_user.bike.nil?
|
||||
can :manage, ::ActsAsLoggable::Log, { :loggable_type => "Bike", :loggable_id => @current_user.bike_id }
|
||||
can :manage, ::ActsAsLoggable::Log, { :loggable_type => "User", :loggable_id => @current_user.id }
|
||||
end
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
class Role < ActiveRecord::Base
|
||||
attr_accessible :role
|
||||
|
||||
has_many :user_role_joins
|
||||
has_many :users, through: :user_role_joins
|
||||
validates_uniqueness_of :role
|
||||
|
||||
|
||||
def to_s
|
||||
self.role
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
self.role == other.role
|
||||
end
|
||||
end
|
||||
+8
-7
@@ -7,14 +7,16 @@ class User < ActiveRecord::Base
|
||||
|
||||
# Setup accessible (or protected) attributes for your model
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me,
|
||||
:first_name, :last_name, :nickname, :user_role_id, :bike_id,
|
||||
:first_name, :last_name, :nickname, :bike_id,
|
||||
:user_profiles_attributes
|
||||
|
||||
has_many :transactions
|
||||
has_many :user_profiles
|
||||
accepts_nested_attributes_for :user_profiles, allow_destroy: false
|
||||
|
||||
has_one :user_role
|
||||
has_many :user_role_joins
|
||||
has_many :roles, through: :user_role_joins
|
||||
|
||||
belongs_to :bike
|
||||
|
||||
validates :first_name, :presence => true
|
||||
@@ -28,12 +30,11 @@ class User < ActiveRecord::Base
|
||||
to_s
|
||||
end
|
||||
|
||||
def role
|
||||
user_role.role
|
||||
end
|
||||
|
||||
def role?(role)
|
||||
user_role.to_s == role.to_s
|
||||
if role.kind_of?(String) or role.kind_of?(Symbol)
|
||||
role = Role.find_by_role(role.to_s)
|
||||
end
|
||||
roles.include?(role)
|
||||
end
|
||||
|
||||
def total_hours
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
class UserRole < ActiveRecord::Base
|
||||
attr_accessible :role
|
||||
|
||||
belongs_to :user
|
||||
|
||||
self.per_page = 15
|
||||
|
||||
def to_s
|
||||
self.role
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class UserRoleJoin < ActiveRecord::Base
|
||||
#set_table_name :user_role_joins
|
||||
attr_accessible :role_id, :user_id
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :role
|
||||
|
||||
validate :role_id, presence: true, numericality: true
|
||||
validate :user_id, presence: true, numericality: true
|
||||
validates_uniqueness_of :user_id, :scope => :role_id
|
||||
|
||||
self.per_page = 15
|
||||
end
|
||||
Reference in New Issue
Block a user