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
|
||||
|
||||
Reference in New Issue
Block a user