Refactor for authorization sanity
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
class Employee
|
||||
include SimplyStored::Couch
|
||||
include ActiveModel::SerializerSupport
|
||||
DEFAULT_SETTINGS = {
|
||||
'manager' => false,
|
||||
'active' => true
|
||||
}
|
||||
attr_accessor *DEFAULT_SETTINGS.keys
|
||||
attr_reader :settings
|
||||
|
||||
view :by_confirmation_token, key: :confirmation_token # devise confirmable
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
|
||||
@@ -15,6 +21,9 @@ class Employee
|
||||
def count_by_email(email)
|
||||
database.view by_email(key: email, reduce: true)
|
||||
end
|
||||
def default_settings
|
||||
DEFAULT_SETTINGS
|
||||
end
|
||||
end
|
||||
|
||||
#validates :email, email: true
|
||||
@@ -22,4 +31,15 @@ class Employee
|
||||
has_many :orders
|
||||
has_and_belongs_to_many :lists, storing_keys: false
|
||||
|
||||
def enrich_with_settings(settings)
|
||||
@settings = settings
|
||||
settings.settings.each do |attribute, value|
|
||||
public_send "#{attribute}=", value
|
||||
end
|
||||
settings
|
||||
end
|
||||
|
||||
def settings
|
||||
@settings || SupplierEmployeesSettings.new(Supplier.new).for_employee(self)
|
||||
end
|
||||
end
|
||||
|
||||
+2
-2
@@ -150,7 +150,7 @@ class List
|
||||
set_price # should not be needed, but extra secure
|
||||
orders.map(&:close!) # close the connected orders
|
||||
self.state = 'closed'
|
||||
self.is_helped! if needs_help?
|
||||
self.mark_helped! if needs_help?
|
||||
self.needs_payment = false
|
||||
self.user_requests_closing = false # if a user requested closing, not needed anymore
|
||||
self.closed_at = Time.now
|
||||
@@ -173,7 +173,7 @@ class List
|
||||
end
|
||||
end
|
||||
|
||||
def is_helped!
|
||||
def mark_helped!
|
||||
self.needs_help = false
|
||||
if save
|
||||
broadcast_users 'list_helped', id: id
|
||||
|
||||
+10
-1
@@ -42,6 +42,11 @@ class Supplier
|
||||
has_many :sections, dependent: :destroy
|
||||
has_and_belongs_to_many :employees, storing_keys: true
|
||||
|
||||
alias_method :non_enriced_employees, :employees
|
||||
def employees
|
||||
non_enriced_employees.tap { |es| es.each{ |e| e.enrich_with_settings(settings_for(e) ) }}
|
||||
end
|
||||
|
||||
after_create :add_section_on_create
|
||||
|
||||
validates :name, presence: true
|
||||
@@ -66,7 +71,11 @@ class Supplier
|
||||
end
|
||||
|
||||
def employee_settings
|
||||
SupplierEmployeesSettings.new(self)
|
||||
@employee_settings ||= SupplierEmployeesSettings.new(self)
|
||||
end
|
||||
|
||||
def settings_for(employee)
|
||||
employee_settings.for_employee(employee)
|
||||
end
|
||||
|
||||
def active_orders(options = {})
|
||||
|
||||
Reference in New Issue
Block a user