From b95a8d03e32a86838d99ded814a08cb7aac44772 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Fri, 20 Dec 2024 05:21:06 +0300 Subject: [PATCH] Replace show and index abilities with read ability --- app/abilities/ability.rb | 41 ++++++++++++++++----------------- app/abilities/api_ability.rb | 27 ++++++++++------------ app/abilities/api_capability.rb | 6 ++--- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 2214ba621..e4b9dcf6b 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -5,8 +5,7 @@ class Ability def initialize(user) can :query, :browse - can :show, [Node, Way, Relation] - can [:index, :show], [OldNode, OldWay, OldRelation] + can :read, [Node, Way, Relation, OldNode, OldWay, OldRelation] can [:show, :create], Note can :search, :direction can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site @@ -14,47 +13,47 @@ class Ability can [:search, :search_latlon, :search_osm_nominatim, :search_osm_nominatim_reverse], :geocoder if Settings.status != "database_offline" - can [:index, :feed, :show], Changeset - can :show, ChangesetComment + can [:read, :feed], Changeset + can :read, ChangesetComment can [:confirm, :confirm_resend, :confirm_email], :confirmation - can [:index, :rss, :show], DiaryEntry - can :index, DiaryComment + can [:read, :rss], DiaryEntry + can :read, DiaryComment can [:index], Note can [:create, :update], :password - can [:index, :show], Redaction + can :read, Redaction can [:create, :destroy], :session - can [:index, :show, :data, :georss], Trace - can [:terms, :create, :save, :suspended, :show, :auth_success, :auth_failure], User - can [:index, :show, :blocks_on, :blocks_by], UserBlock + can [:read, :data, :georss], Trace + can [:read, :terms, :create, :save, :suspended, :auth_success, :auth_failure], User + can [:read, :blocks_on, :blocks_by], UserBlock end if user&.active? can :welcome, :site - can [:show], :deletion + can :read, :deletion if Settings.status != "database_offline" can [:subscribe, :unsubscribe], Changeset - can [:index, :create, :show, :update, :destroy], :oauth2_application - can [:index, :destroy], :oauth2_authorized_application - can [:show, :create, :destroy], :oauth2_authorization + can [:read, :create, :update, :destroy], :oauth2_application + can [:read, :destroy], :oauth2_authorized_application + can [:read, :create, :destroy], :oauth2_authorization can [:update, :destroy], :account - can [:show], :dashboard + can :read, :dashboard can [:create, :subscribe, :unsubscribe], DiaryEntry can :update, DiaryEntry, :user => user can [:create], DiaryComment can [:make_friend, :remove_friend], Friendship - can [:create, :reply, :show, :inbox, :outbox, :muted, :mark, :unmute, :destroy], Message + can [:read, :create, :reply, :inbox, :outbox, :muted, :mark, :unmute, :destroy], Message can [:close, :reopen], Note - can [:show, :update], :preference + can [:read, :update], :preference can :update, :profile can :create, Report can [:mine, :create, :update, :destroy], Trace can [:account, :go_public], User - can [:index, :create, :destroy], UserMute + can [:read, :create, :destroy], UserMute if user.moderator? can [:hide, :unhide], [DiaryEntry, DiaryComment] - can [:index, :show, :resolve, :ignore, :reopen], Issue + can [:read, :resolve, :ignore, :reopen], Issue can :create, IssueComment can [:create, :update, :destroy], Redaction can [:create, :revoke_all], UserBlock @@ -65,10 +64,10 @@ class Ability if user.administrator? can [:hide, :unhide], [DiaryEntry, DiaryComment] - can [:index, :show, :resolve, :ignore, :reopen], Issue + can [:read, :resolve, :ignore, :reopen], Issue can :create, IssueComment can [:set_status, :destroy], User - can [:show, :update], :users_list + can [:read, :update], :users_list can [:create, :destroy], UserRole end end diff --git a/app/abilities/api_ability.rb b/app/abilities/api_ability.rb index c790da66a..36cfee0bb 100644 --- a/app/abilities/api_ability.rb +++ b/app/abilities/api_ability.rb @@ -4,27 +4,24 @@ class ApiAbility include CanCan::Ability def initialize(user) - can :show, :capability - can :index, :map - can :show, :permission - can :show, :version + can :read, [:version, :capability, :permission, :map] if Settings.status != "database_offline" - can [:index, :show, :download], Changeset - can [:index, :create, :feed, :show, :search], Note - can :index, Tracepoint - can [:index, :show], User - can [:index, :show], Node - can [:index, :show, :full, :ways_for_node], Way - can [:index, :show, :full, :relations_for_node, :relations_for_way, :relations_for_relation], Relation - can [:history, :show], [OldNode, OldWay, OldRelation] - can [:show], UserBlock + can [:read, :download], Changeset + can [:read, :create, :feed, :search], Note + can :read, Tracepoint + can :read, User + can :read, Node + can [:read, :full, :ways_for_node], Way + can [:read, :full, :relations_for_node, :relations_for_way, :relations_for_relation], Relation + can [:history, :read], [OldNode, OldWay, OldRelation] + can :read, UserBlock if user&.active? can [:comment, :close, :reopen], Note - can [:create, :show, :update, :destroy], Trace + can [:read, :create, :update, :destroy], Trace can [:details, :gpx_files], User - can [:index, :show, :update, :update_all, :destroy], UserPreference + can [:read, :update, :update_all, :destroy], UserPreference if user.terms_agreed? can [:create, :update, :upload, :close, :subscribe, :unsubscribe], Changeset diff --git a/app/abilities/api_capability.rb b/app/abilities/api_capability.rb index 0e953d50b..1c2eab41f 100644 --- a/app/abilities/api_capability.rb +++ b/app/abilities/api_capability.rb @@ -10,13 +10,13 @@ class ApiCapability if user&.active? can [:create, :comment, :close, :reopen], Note if scope?(token, :write_notes) can [:create, :destroy], NoteSubscription if scope?(token, :write_notes) - can [:show, :data], Trace if scope?(token, :read_gpx) + can [:read, :data], Trace if scope?(token, :read_gpx) can [:create, :update, :destroy], Trace if scope?(token, :write_gpx) can [:details], User if scope?(token, :read_prefs) can [:gpx_files], User if scope?(token, :read_gpx) - can [:index, :show], UserPreference if scope?(token, :read_prefs) + can :read, UserPreference if scope?(token, :read_prefs) can [:update, :update_all, :destroy], UserPreference if scope?(token, :write_prefs) - can [:inbox, :outbox, :show, :update, :destroy], Message if scope?(token, :consume_messages) + can [:inbox, :outbox, :read, :update, :destroy], Message if scope?(token, :consume_messages) can [:create], Message if scope?(token, :send_messages) if user.terms_agreed? -- 2.39.5