-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,5 @@ gem 'country_select' | |
gem 'devise' | ||
gem 'devise-i18n' | ||
gem 'omniauth-facebook' | ||
gem 'cancancan' | ||
gem 'rolify' |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Ability | ||
include CanCan::Ability | ||
|
||
def initialize(user) | ||
# Define abilities for the passed in user here. For example: | ||
# | ||
user ||= User.new # guest user (not logged in) | ||
if user.is_admin? | ||
can :manage, :all | ||
else | ||
can :read, :all | ||
# can :read, Forum | ||
# can :write, Forum if user.has_role?(:moderator, Forum) | ||
# can :write, Forum, :id => Forum.with_role(:moderator, user).pluck(:id) | ||
end | ||
# | ||
# The first argument to `can` is the action you are giving the user | ||
# permission to do. | ||
# If you pass :manage it will apply to every action. Other common actions | ||
# here are :read, :create, :update and :destroy. | ||
# | ||
# The second argument is the resource the user can perform the action on. | ||
# If you pass :all it will apply to every resource. Otherwise pass a Ruby | ||
# class of the resource. | ||
# | ||
# The third argument is an optional hash of conditions to further filter the | ||
# objects. | ||
# For example, here the user can only update published articles. | ||
# | ||
# can :update, Article, :published => true | ||
# | ||
# See the wiki for details: | ||
# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities | ||
end | ||
end |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Role < ApplicationRecord | ||
has_and_belongs_to_many :users, :join_table => :users_roles | ||
|
||
belongs_to :resource, | ||
:polymorphic => true, | ||
:optional => true | ||
|
||
validates :resource_type, | ||
:inclusion => { :in => Rolify.resource_types }, | ||
:allow_nil => true | ||
|
||
scopify | ||
end |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Rolify.configure do |config| | ||
# By default ORM adapter is ActiveRecord. uncomment to use mongoid | ||
# config.use_mongoid | ||
|
||
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false | ||
config.use_dynamic_shortcuts | ||
end |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class RolifyCreateRoles < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table(:roles) do |t| | ||
t.string :name | ||
t.references :resource, :polymorphic => true | ||
|
||
t.timestamps | ||
end | ||
|
||
create_table(:users_roles, :id => false) do |t| | ||
t.references :user | ||
t.references :role | ||
end | ||
|
||
add_index(:roles, :name) | ||
add_index(:roles, [ :name, :resource_type, :resource_id ]) | ||
add_index(:users_roles, [ :user_id, :role_id ]) | ||
end | ||
end |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
# This model initially had no columns defined. If you add columns to the | ||
# model remove the '{}' from the fixture names and add the columns immediately | ||
# below each fixture, per the syntax in the comments below | ||
# | ||
one: {} | ||
# column: value | ||
# | ||
two: {} | ||
# column: value |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class RoleTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |