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

Adds note tags support #5344

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

Conversation

nenad-vujicic
Copy link
Contributor

Description

PR adds support for note tags as described in #5294 Following changes are made:

  1. Created note_tags table, connected it with note table (using foreign key and associations), created NoteTag model file and NoteTagTest class with basic tests (PR Adding map note tags - part 1 - added migration script and model files #5323 does this)
  2. Added preparing and rendering of note tags in left sidebar using browse/tag_details partial, also, created test with multiple tags added rendering and checking if rendered HTML contains tags
  3. Updated (j)builder files to write note tags in XML, JSON, GPX, RSS and feed files and updated test to check existence of tags in each of above files (creation of tag is performed using ActiveLayer)
  4. Added support for creating tags at note creation time using POST HTTP request and improved tests to check existence of tags in each of generated files (creation of tag is performed using POST HTTP request). Also, added creating tag created_by, OpenStreetMaps-Website for notes created using OSM website.

Displayed resolved note:
image

Displayed opened note:
image

XML output for "opened note":
image

Displayed note without tags (all current):
image

Fixes #5294

How has this been tested?

Run tests from workflows, tested creating and displaying notes manually as administrator / moderator / regular user, tested displaying already existing notes (they will be displayed as earlier - without tags)

@nenad-vujicic
Copy link
Contributor Author

Here are a few more benefits of adding note tags to OSM, as implemented by this PR:

  1. Improves notes categorization (by e.g. adding descriptive tags for better organization like "Missing place" or similar):

image

  1. Improves collaboration & communication (by e.g. marking resolving some note requires outdoor survey):

image

  1. Now we are ready for advanced filtering by specific tags (needs development)

  2. Improves public outreach (by e.g. adding tags about mapathons)

image

  1. Improves multi-language support (by e.g. adding language in which note description is written)

image

@tyrasd @westnordost @Zverik @ToeBee @angoca @talllguy what do you think about this PR?

Thanks,
Nenad.

@westnordost
Copy link

westnordost commented Nov 21, 2024

Many of the use cases covered by this issue/PR are currently solved with hash tags (e.g. #surveyme) and tools are currently made to take these into account. Tools would need to be adapted to support tags as well. (Hashtags are not going away anytime soon)

The advantage of having tags implemented like this properly would be that there could be an efficient API with which to filter notes. (Right now, this is the only advantage I can think of over hash tags and stuff.) For example:

  • search for notes created by StreetComplete for certain quest types, to find common issues (misunderstandings, missing answer options) with quests
  • search for notes created by certain versions of StreetComplete, e.g. to find notes that where perhaps created in error due to the above
  • search specifically for notes that need e.g. survey. (However, this use case would not be useful for StreetComplete, because StreetComplete downloads all notes, anyway)

db/structure.sql Outdated

-- *not* creating schema, since initdb creates it


Copy link
Member

Choose a reason for hiding this comment

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

This block is noise created by the version of pg_dump you're using and has nothing to do with the actual changes in this PR so should be removed.

end

# Add foreign key without validation
add_foreign_key :note_tags, :notes, :column => :note_id, :name => "note_tags_id_fkey", :validate => false
Copy link
Member

Choose a reason for hiding this comment

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

Would moving this inside the create_table as t.foreign_key avoid the need to create it with validation disabled? Not sure if the strong migrations is clever enough to know that is safe?

If not then you can just add a second migration to enable validation as it's safe to do on an empty table.

@@ -50,7 +50,8 @@ OSM.NewNote = function (map) {
data: {
lat: location.lat,
lon: location.lng,
text: $(form.text).val()
text: $(form.text).val(),
tags: "created_by:OpenStreetMaps-Website"
Copy link
Member

Choose a reason for hiding this comment

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

There is no s on the end of OpenStreetMap ;-) I'm not sure what is the best value for the tag here but it definitely shouldn't have the trailing s.

key, value = pair.split(":", 2)
tags << { :k => sanitize(key), :v => sanitize(value) } if key && value
end
end
Copy link
Member

Choose a reason for hiding this comment

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

Encoding all the tags in a string like this is nasty and creates all sorts of problems if people use colons or commas in tag names or values - colons in particular are historically common in tag names for other object types.

I'm not sure what the solution is as this API is unusual in using form parameters rather than an XML or JSON body to create an object.

Copy link
Collaborator

Choose a reason for hiding this comment

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

JSON just for tags?

@nenad-vujicic nenad-vujicic marked this pull request as draft November 25, 2024 09:52
Added NoteTag model class, note_tags DB table, associations between Note
and NoteTag and private / foreign keys.
Added Note#tags routine for preparing note tags for rendering using
"browse/tag_details" partial. Also, added displaying of previously
prepared note tags between note's "Description" and comments in app/views/notes/show.html.erb.
Added writing note tags in (j)builder files for generating XML, JSON, GPX, RSS and feed files.
Improved API::NotesController#create to support tags (if passed). Also, added adding of "created_by:OpenStreetMap-Website" tag to note when created from OSM website.
Added registering new factory bot for note_tag and added new unit tests
to NoteTagTest for checking if key length is valid, value length is
valid, key length is invalid, value length is invalid, orphaned tag is
invalid and note_tags are unique.
Added NotesControllerTest#test_displaying_note_with_tags unit test for testing cases when note has tags and comment (description). Internally, new note is created with comment (description) and several tags and then rendered in sidebar. Existence of appropriate HTML tags for notes, comment (description) and tags is checked.
Added testing of note XML, JSON, GPX, RSS and feed outputs (with tags)
when note (and tags) are created on FactoryBot / ActiveRecord level.
Added testing of note XML, JSON, GPX, RSS and feed outputs (with tags)
when note (and tags) are created by sending POST/HTTP request.
@nenad-vujicic
Copy link
Contributor Author

OK, here is another attempt. I made the above corrections and updated it to pass tag definitions as a nested object serialized into JSON, supporting various characters in keys and values.

@nenad-vujicic nenad-vujicic marked this pull request as ready for review November 26, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal for adding support for map notes tags
4 participants