Skip to content

Instantly share code, notes, and snippets.

View rvanlieshout's full-sized avatar

Rene van Lieshout rvanlieshout

View GitHub Profile
class User < ActiveRecord::Base
ROLES = [
'admin',
'manager',
'branch_manager',
'planner',
'employee',
'customer'
].freeze
class User < ActiveRecord::Base
composed_of :roles, :class_name => 'Array',
:mapping => %w(roles to_json),
:constructor => Proc.new { |roles| roles.nil? ? [] : JSON.parse(roles) },
:converter => Proc.new { |roles| roles.class == Array ? roles : [] }
ROLES = [
'admin',
'manager',
'branch_manager',
class Registration < ActiveRecord::Base
# Database Relationships
belongs_to :person
belongs_to :event
# Validations
validates_presence_of :event_id
validates_presence_of :person_id
validates_uniqueness_of :person_id, :scope => :event_id, :message => "is already signed in or registered."
def create
@user = User.find(params[:responsibility][:user_id])
@company = Company.find(params[:company_id])
# create an array of responsibilities that we want to save
responsibilities = params[:responsibility][:division_ids].collect do |division_id|
Responsibility.new(:division_id => division_id, :user_id => @user.id)
end
# get a list of invalid responsibilities
def create
@user = User.find(params[:responsibility][:user_id])
@company = Company.find(params[:company_id])
# create an array of responsibilities that we want to save
responsibilities = params[:responsibility][:division_ids].collect do |division_id|
Responsibility.new(:division_id => division_id, :user_id => @user.id)
end
# get a list of invalid responsibilities
def sign_in_and_redirect(resource_or_scope, resource=nil, skip=false)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless skip
if current_user && current_user.is_customer_contact?
session[:customer_id] = current_user.customers.first.id
end
redirect_to :controller => 'dashboard', :locale => (current_user && current_user.language.to_s != "" ? current_user.language : I18n.locale)
ROLES = [
'admin',
'manager',
'branch_manager',
'planner',
'employee',
'customer'
].freeze
# Define a method for each role: user.admin?, user.manager?, ...
# Include this module in your ActiveRecord model to gain a filter scope
# Filter applies the supplied query to given attributes (or all attributes if none are given)
#
# example:
#
# User.filter('Bob', [:first_name, :last_name])
#
# returns all users with 'bob' in their first or last name
module Lico
module FilterScope
def initialize(user)
if !user.nil? && !user.role.nil?
# internal employee
if user.company_id == 1
can :manage, :all
# consumer
else
user.permissions.each do |permission|
if permission.is_internal?
<tbody>
<% products.each do |product| %>
<tr>
<td><%= link_to product.name, product %></td>
<td><%= truncate(strip_tags(product.description), :length => 80) %></td>
<td><%= product.price %></td>
</tr>
<% end %>
</tbody>