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