Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CanCanCan ability to see redacted versions #4553

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AntonKhorev
Copy link
Collaborator

Thinking about https://github.com/openstreetmap/openstreetmap-website/pull/4324/files#r1501833550: deny_access is the ability exception handler, why not then throw the exception? Even better if cancancan throws it after making checks in ability.rb. The problem is, the ability to see redacted versions doesn't correspond to any controller method. But we can define this ability anyway and tell cancancan to check it with authorize! when required.

@AntonKhorev AntonKhorev force-pushed the show-unredacted-ability branch from bfaa37e to d66f064 Compare March 3, 2024 08:00
@AntonKhorev AntonKhorev force-pushed the show-unredacted-ability branch 3 times, most recently from 62b6445 to cafd4a0 Compare March 16, 2024 02:18
@AntonKhorev AntonKhorev changed the title Add an ability to see redacted versions Add a CanCanCan ability to see redacted versions Mar 25, 2024
@AntonKhorev AntonKhorev added the refactor Refactoring, or things that work but could be done better label Jul 3, 2024
@AntonKhorev AntonKhorev force-pushed the show-unredacted-ability branch from cafd4a0 to 012e752 Compare July 3, 2024 09:18
@@ -54,6 +54,7 @@ def initialize(user)
can [:index, :create, :destroy], UserMute

if user.moderator?
can :show_redactions, [Node, Way, Relation, OldNode, OldWay, OldRelation]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redactions are only applicable to Old{Node, Way, Relation}, i.e. we cannot redact the currently active version. I didn't quite get why we need to have "Node, Way, Relation" in the list here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've seen this commit. I found the old code a bit clearer, because to me the concept of redactions makes only sense when talking about Old* elements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking current_user&.moderator? could be clearer only if you know that moderators can view redacted information.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried replacing @feature with things like "Old#{@type.classify}".constantize, looks worse.

I don't see anything wrong with being able to "show_redactions" of "Node" (= "show_redactions" of some versions of "Node").

Copy link
Contributor

@mmd-osm mmd-osm Jul 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Node" (as in app/models/node.rb) does not have a redaction_id and does not belong to a redaction (unlike app/models/old_node.rb).

Also, "Node" has no concept of "some versions", it's always the latest version of an object only, which by definition cannot be redacted. Only the "Old*" objects have the full element history, including the latest version.

So maybe I'm a bit confused here, because my definition of Node and OldNode is based on the model definitions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Node" has no concept of "some versions", it's always the latest version ...

Yet we link to its history from its page. How can we do that if "Node" is only the latest version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, to link to the history, you would only need the element type, object id and the current version of the object (=latest version). Based on this info, you could generate a link to the latest version, and also to the first version, if the current version is not 1.

The actual history page data would then be provided by the old* objects:

<%= render :partial => "browse/#{@type}", :collection => @feature.send(:"old_#{@type}s").reverse %>

I found it helpful to check the local PostgreSQL db and compare current_nodes and nodes table contents (representing Node and OldNode models).

@AntonKhorev AntonKhorev force-pushed the show-unredacted-ability branch from 012e752 to 89201a3 Compare January 6, 2025 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactoring, or things that work but could be done better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants