Class: Ability

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability
Defined in:
app/models/ability.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, course = nil, course_user = nil, session = nil) ⇒ Ability

Initialize the ability of user.

or user is not part of the course

Parameters:

  • user (User|nil)

    The current user. This can be nil if the no user is logged in.

  • course (Course|nil) (defaults to: nil)

    The current course. This can be nil if not inside a course.

  • course_user (CourseUser|nil) (defaults to: nil)

    The current course_user. This can be nil if not inside a course

  • session (ActionDispatch::Request::Session) (defaults to: nil)

    The browser session


19
20
21
22
23
24
25
26
27
# File 'app/models/ability.rb', line 19

def initialize(user, course = nil, course_user = nil, session = nil)
  @user = user
  @course = course
  @course_user = course_user
  @session = session
  can :manage, :all if user&.administrator?

  define_permissions
end

Instance Attribute Details

#courseObject (readonly)

Returns the value of attribute course


5
6
7
# File 'app/models/ability.rb', line 5

def course
  @course
end

#course_userObject (readonly)

Returns the value of attribute course_user


6
7
8
# File 'app/models/ability.rb', line 6

def course_user
  @course_user
end

#sessionObject (readonly)

Returns the value of attribute session


7
8
9
# File 'app/models/ability.rb', line 7

def session
  @session
end

#userObject (readonly)

Returns the value of attribute user


4
5
6
# File 'app/models/ability.rb', line 4

def user
  @user
end

Instance Method Details

#define_permissionsvoid

This method returns an undefined value.

Defines abilities for the given user.

This is the method to implement when defining permissions for a component. Always call +super+ when implementing this method.

Global administrators already have full access.


37
38
# File 'app/models/ability.rb', line 37

def define_permissions
end