-
-
Save simonlehmann/a4f07b9e80eb42ce05da4157552f99b0 to your computer and use it in GitHub Desktop.
Revisions
-
simonlehmann revised this gist
Mar 3, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ def initialize_group Group.current = Group.find(params[:group_id]) if params.has_key?(:group_id) end # we find user role for group that he is managing and we store data in class ( cattr_accessor :current_role ) def initialize_user_role User.current_role = Unity.where(group_id: Group.current.id, user_id: current_user.id).first.role.name unless Group.current.nil? end -
simonlehmann revised this gist
Mar 3, 2017 . 8 changed files with 24 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,15 +4,19 @@ class Ability def initialize(user) user ||= User.new # This is used for not logged user if you have a need for it case user.current_role when 'admin' can :manage, :all when 'moderator' can :read, Products can :update, Products cannot :destroy, Products cannot :create, Products cannot :manage, Client # ... other roles and abilities ... end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ class ApplicationController < ActionController::Base before_filter :initialize_group, :initialize_user_role # we find group that user currently uses and we store data in class ( cattr_accessor :current) def initialize_group Group.current = Group.find(params[:group_id]) if params.has_key?(:group_id) end # we find user role for companie that he is managing and we store data in class ( cattr_accessor :current_role ) def initialize_user_role User.current_role = Unity.where(group_id: Group.current.id, user_id: current_user.id).first.role.name unless Group.current.nil? end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ class Group < ActiveRecord::Base has_many :unities has_many :users, through: :unities has_many :roles, through: :unities cattr_accessor :current # here I added a current group, so I can check wich group is active I will use that later. end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ create_table :unities do |t| t.integer :role_id t.integer :user_id t.integer :group_id t.timestamps end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ class Role < ActiveRecord::Base has_many :unities has_many :users, through: :unities has_many :groups, through: :unities end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ class Unity < ActiveRecord::Base belongs_to :role belongs_to :group belongs_to :user attr_accessible :role_id, :user_id, :group_id end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ class User < ActiveRecord::Base has_many :unities has_many :roles, through: :unities has_many :groups, through: :unities cattr_accessor :current_role # I added current_role so I can check which role does user haves on a group that he is on but I will get to that later end -
simonlehmann revised this gist
Mar 3, 2017 . 3 changed files with 6 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,7 @@ class Company < ActiveRecord::Base has_many :unities has_many :users, through: :unities has_many :roles, through: :unities cattr_accessor :current # here I added a current company, so I can check wich company is active I will use that later. end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ class Unity < ActiveRecord::Base belongs_to :role belongs_to :company belongs_to :user attr_accessible :role_id, :user_id, :company_id end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ class User < ActiveRecord::Base rolify has_many :unities has_many :roles, through: :unities has_many :companies, through: :unities cattr_accessor :current_role # I added current_role so I can check which role does user haves on a company that he is on but I will get to that later end -
simonlehmann revised this gist
Mar 3, 2017 . 6 changed files with 26 additions and 40 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,22 +2,17 @@ class Ability include CanCan::Ability def initialize(user) user ||= User.new # This is used for not logged user if you have a need for it case user.current_role when 'admin' can :manage, :all when 'moderator' can :read, Products can :update, Products cannot :destroy, Products cannot :create, Products cannot :manage, Client # ... other roles and abilities ... end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,13 @@ class ApplicationController < ActionController::Base before_filter :initialize_company, :initialize_user_role # we find company that user currently uses and we store data in class ( cattr_accessor :current) def initialize_company Company.current = Company.find(params[:company_id]) if params.has_key?(:company_id) end # we find user role for companie that he is managing and we store data in class ( cattr_accessor :current_role ) def initialize_user_role User.current_role = Unity.where(company_id: Company.current.id, user_id: current_user.id).first.role.name unless Company.current.nil? end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,5 +3,5 @@ create_table :unities do |t| t.integer :user_id t.integer :company_id t.timestamps end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ class Role < ActiveRecord::Base has_many :unities has_many :users, through: :unities has_many :companies, through: :unities end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,7 @@ class Unity < ActiveRecord::Base attr_accessible :role_id, :user_id, :company_id belongs_to :role belongs_to :company belongs_to :user end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,5 +6,4 @@ class User < ActiveRecord::Base has_many :unities has_many :roles, through: :unities has_many :companies, through: :unities end -
vmarcetic created this gist
Jul 21, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ class Ability include CanCan::Ability def initialize(user) user ||= User.new # This is used for not logged user if you have a need for it if User.current_role == 'admin' # From ApplicationController we can get current_role and check it up against the role we want. can :manage, :all else if User.current_role == 'moderator' can :read, Products can :update, Products cannot :destroy, Products cannot :create, Products cannot :manage, Client end can :read, :all end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ class ApplicationController < ActionController::Base before_filter :initialize_company, :initialize_user_role # we find company that user currently uses and we store data in class ( cattr_accessor :current) def initialize_company Company.current = Company.find(params[:company_id]) if params.has_key?(:company_id) end # we find user role for companie that he is managing and we store data in class ( cattr_accessor :current_role ) def initialize_user_role User.current_role = Unity.where(company_id: Company.current.id, user_id: current_user.id).first.role.name unless Company.current.nil? end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ class Company < ActiveRecord::Base cattr_accessor :current # here I added a current company, so I can check wich company is active I will use that later. has_many :unities has_many :users, through: :unities has_many :roles, through: :unities end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ create_table :unities do |t| t.integer :role_id t.integer :user_id t.integer :company_id t.timestamps end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ class Role < ActiveRecord::Base has_many :unities has_many :users, through: :unities has_many :companies, through: :unities end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ class Unity < ActiveRecord::Base attr_accessible :role_id, :user_id, :company_id belongs_to :role belongs_to :company belongs_to :user end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ class User < ActiveRecord::Base rolify cattr_accessor :current_role # I added current_role so I can check which role does user haves on a company that he is on but I will get to that later has_many :unities has_many :roles, through: :unities has_many :companies, through: :unities end