]> git.openstreetmap.org Git - rails.git/blob - app/abilities/ability.rb
Use full list of osm xml root attributes in builder templates
[rails.git] / app / abilities / ability.rb
1 # frozen_string_literal: true
2
3 class Ability
4   include CanCan::Ability
5
6   def initialize(user)
7     can :index, ChangesetComment
8     can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id], :site
9     can [:index, :rss, :show, :comments], DiaryEntry
10     can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim,
11          :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder
12     can [:index, :create, :comment, :feed, :show, :search, :mine], Note
13     can [:index, :show], Redaction
14     can [:terms, :api_users, :login, :logout, :new, :create, :save, :confirm, :confirm_resend, :confirm_email, :lost_password, :reset_password, :show, :api_read, :auth_success, :auth_failure], User
15     can [:index, :show, :blocks_on, :blocks_by], UserBlock
16
17     if user
18       can :welcome, :site
19       can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry
20       can [:close, :reopen], Note
21       can [:new, :create], Report
22       can [:account, :go_public, :make_friend, :remove_friend, :api_details, :api_gpx_files], User
23       can [:read, :read_one, :update, :update_one, :delete_one], UserPreference
24
25       if user.terms_agreed? || !REQUIRE_TERMS_AGREED # rubocop:disable Style/IfUnlessModifier
26         can :create, ChangesetComment
27       end
28
29       if user.moderator?
30         can [:destroy, :restore], ChangesetComment
31         can [:index, :show, :resolve, :ignore, :reopen], Issue
32         can :create, IssueComment
33         can :destroy, Note
34         can [:new, :create, :edit, :update, :destroy], Redaction
35         can [:new, :edit, :create, :update, :revoke], UserBlock
36       end
37
38       if user.administrator?
39         can [:hide, :hidecomment], [DiaryEntry, DiaryComment]
40         can [:index, :show, :resolve, :ignore, :reopen], Issue
41         can :create, IssueComment
42         can [:set_status, :delete, :index], User
43         can [:grant, :revoke], UserRole
44       end
45     end
46
47     # Define abilities for the passed in user here. For example:
48     #
49     #   user ||= User.new # guest user (not logged in)
50     #   if user.admin?
51     #     can :manage, :all
52     #   else
53     #     can :read, :all
54     #   end
55     #
56     # The first argument to `can` is the action you are giving the user
57     # permission to do.
58     # If you pass :manage it will apply to every action. Other common actions
59     # here are :read, :create, :update and :destroy.
60     #
61     # The second argument is the resource the user can perform the action on.
62     # If you pass :all it will apply to every resource. Otherwise pass a Ruby
63     # class of the resource.
64     #
65     # The third argument is an optional hash of conditions to further filter the
66     # objects.
67     # For example, here the user can only update published articles.
68     #
69     #   can :update, Article, :published => true
70     #
71     # See the wiki for details:
72     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
73   end
74 end