1 # frozen_string_literal: true
4 include CanCan::Ability
6 def initialize(user, token)
8 can [:permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id, :welcome], :site
10 can [:list, :rss, :view, :comments], DiaryEntry
15 can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry
17 if user.administrator?
18 can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
21 # Define abilities for the passed in user here. For example:
23 # user ||= User.new # guest user (not logged in)
30 # The first argument to `can` is the action you are giving the user
32 # If you pass :manage it will apply to every action. Other common actions
33 # here are :read, :create, :update and :destroy.
35 # The second argument is the resource the user can perform the action on.
36 # If you pass :all it will apply to every resource. Otherwise pass a Ruby
37 # class of the resource.
39 # The third argument is an optional hash of conditions to further filter the
41 # For example, here the user can only update published articles.
43 # can :update, Article, :published => true
45 # See the wiki for details:
46 # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
49 def has_capability?(token, cap)
50 token && token.read_attribute(cap)