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 can [:read, :read_one], UserPreference if has_capability?(token, :allow_read_prefs)
18 can [:update, :update_one, :delete_one], UserPreference if has_capability?(token, :allow_write_prefs)
20 if user.administrator?
21 can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
24 # Define abilities for the passed in user here. For example:
26 # user ||= User.new # guest user (not logged in)
33 # The first argument to `can` is the action you are giving the user
35 # If you pass :manage it will apply to every action. Other common actions
36 # here are :read, :create, :update and :destroy.
38 # The second argument is the resource the user can perform the action on.
39 # If you pass :all it will apply to every resource. Otherwise pass a Ruby
40 # class of the resource.
42 # The third argument is an optional hash of conditions to further filter the
44 # For example, here the user can only update published articles.
46 # can :update, Article, :published => true
48 # See the wiki for details:
49 # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
52 def has_capability?(token, cap)
53 token && token.read_attribute(cap)