diff --git a/app/models/moment.rb b/app/models/moment.rb index 4ccafecf..0b8ddfac 100644 --- a/app/models/moment.rb +++ b/app/models/moment.rb @@ -24,6 +24,7 @@ class Moment < ApplicationRecord validates :note, length: { maximum: 1000 } validate :photo_present validate :acceptable_photo + validate :captured_at_a_visited_place, on: :create # A moment is never visible on publish alone — going public re-enters # moderation, so a curator must approve it before anyone else can see it. @@ -85,6 +86,15 @@ def require_moderation_when_published self.moderation_status = :pending if visibility_public_moment? && visibility_changed? end + # Capture is earned by being there: a check-in at this place on any of the + # traveller's plans. Asked on create only, so a moment outlives its check-in. + def captured_at_a_visited_place + return if user.nil? || location.nil? + return if user.plan_visits.exists?(location_id: location_id) + + errors.add(:base, I18n.t("plans.moments.not_visited")) + end + def photo_present errors.add(:photo, :blank) unless photo.attached? end diff --git a/app/views/plans/_moment_gallery.html.erb b/app/views/plans/_moment_gallery.html.erb index 95d38514..2ec6bf12 100644 --- a/app/views/plans/_moment_gallery.html.erb +++ b/app/views/plans/_moment_gallery.html.erb @@ -46,10 +46,14 @@
-
- <%= render "plans/moment_instant_form", plan: plan, location: location, - context: context, compact: true, tile: tile %> -
+ <%# Capture is earned by being there. A guest's check-ins live on the + device until sign-in, so the guest keeps the sign-in tile. %> + <% if !logged_in? || visited_location?(location) %> +
+ <%= render "plans/moment_instant_form", plan: plan, location: location, + context: context, compact: true, tile: tile %> +
+ <% end %>
<%= render "plans/moment_gallery_items", moments: moments, diff --git a/config/locales/bs.yml b/config/locales/bs.yml index b8b54459..b1000706 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -451,6 +451,7 @@ bs: note_save: Sačuvaj bilješku note_saved: Bilješka sačuvana note_failed: Bilješka nije sačuvana + not_visited: Prvo ovdje označi posjetu. Uspomena se bilježi na mjestu do kojeg si stigao/la. public: Javno pending: Čeka pregled add_for_plan: Dodaj uspomene diff --git a/config/locales/en.yml b/config/locales/en.yml index 7892dfc0..8987511b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -454,6 +454,7 @@ en: note_save: Save note note_saved: Note saved note_failed: That note could not be saved + not_visited: Mark your visit here first. A moment is captured at a place you have reached. public: Public pending: Awaiting review add_for_plan: Add moments diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index d9fc1587..80c9d835 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -54,6 +54,13 @@ def load_profile_moments assert_selector "#my-moments-frame [data-photo-gallery-target='thumbnail']", minimum: 1, wait: 10 end + # A traveller with check-ins is congratulated on the badges the profile's + # server sync awards, and the celebration covers the page until dismissed. + def dismiss_badge_celebration + find("div.fixed.inset-0.bg-black\\/50 > div > button", wait: 10).click + assert_no_selector "div.fixed.inset-0.bg-black\\/50" + end + # Submitting before the field values have landed posts a blank form, which # re-renders the login page — no error raised, the test simply never left it. # Assert the value is in before pressing, and press again if the page did not diff --git a/test/controllers/curator/moments_controller_test.rb b/test/controllers/curator/moments_controller_test.rb index 4e113868..49149484 100644 --- a/test/controllers/curator/moments_controller_test.rb +++ b/test/controllers/curator/moments_controller_test.rb @@ -104,6 +104,7 @@ def login_as(user) end def build_public_pending_moment + @user.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @user.moments.build(plan: @plan, location: @location) moment.photo.attach( io: File.open("test/fixtures/files/test_image.jpg"), diff --git a/test/controllers/moments/likes_controller_test.rb b/test/controllers/moments/likes_controller_test.rb index 5d17ec21..1d97408a 100644 --- a/test/controllers/moments/likes_controller_test.rb +++ b/test/controllers/moments/likes_controller_test.rb @@ -89,6 +89,7 @@ def login_as(user) end def moment_for(visibility:, moderation:) + @owner.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @owner.moments.build(plan: @plan, location: @location) moment.photo.attach(io: StringIO.new("fake image data"), filename: "heart.jpg", content_type: "image/jpeg") moment.save! diff --git a/test/controllers/moments_controller_test.rb b/test/controllers/moments_controller_test.rb index dd571a52..01f8fb0a 100644 --- a/test/controllers/moments_controller_test.rb +++ b/test/controllers/moments_controller_test.rb @@ -11,6 +11,7 @@ class MomentsControllerTest < ActionDispatch::IntegrationTest @experience.locations << @location @plan = Plan.create!(title: "Moment Trip", city_name: "Sarajevo", visibility: :public_plan, user: @owner) @plan.plan_experiences.create!(experience: @experience, day_number: 1) + @owner.plan_visits.create!(plan: @plan, location: @location) end teardown do @@ -44,6 +45,17 @@ class MomentsControllerTest < ActionDispatch::IntegrationTest assert moment.photo.attached? end + test "create is refused before a check-in at the place" do + @owner.plan_visits.destroy_all + login_as(@owner) + + assert_no_difference "Moment.count" do + post plan_moments_path(@plan), params: moment_params + end + + assert_equal I18n.t("plans.moments.not_visited"), flash[:alert] + end + test "create rejects a non-image upload" do login_as(@owner) @@ -125,6 +137,7 @@ class MomentsControllerTest < ActionDispatch::IntegrationTest end test "create allows a public plan the user does not own" do + @stranger.plan_visits.create!(plan: @plan, location: @location) login_as(@stranger) assert_difference "Moment.count", 1 do diff --git a/test/controllers/new_design_controller_test.rb b/test/controllers/new_design_controller_test.rb index 3c23d8f1..c4a07701 100644 --- a/test/controllers/new_design_controller_test.rb +++ b/test/controllers/new_design_controller_test.rb @@ -194,6 +194,7 @@ class NewDesignControllerTest < ActionDispatch::IntegrationTest test "explore returns approved public moments under the moment type" do user = User.create!(username: "explorer_sharer", email: "explorer_sharer@example.com", password: "password123") + user.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = user.moments.build(plan: @plan, location: @location) moment.photo.attach(io: File.open(file_fixture("real_image.jpg")), filename: "m.jpg", content_type: "image/jpeg") moment.save! @@ -241,6 +242,7 @@ class NewDesignControllerTest < ActionDispatch::IntegrationTest test "explore does not surface a pending or private moment" do user = User.create!(username: "private_sharer", email: "private_sharer@example.com", password: "password123") + user.plan_visits.find_or_create_by!(plan: @plan, location: @mostar_location) moment = user.moments.build(plan: @plan, location: @mostar_location) moment.photo.attach(io: File.open(file_fixture("real_image.jpg")), filename: "m.jpg", content_type: "image/jpeg") moment.save! @@ -800,6 +802,7 @@ class NewDesignControllerTest < ActionDispatch::IntegrationTest private def own_moment_for(user, location) + user.plan_visits.find_or_create_by!(plan: @plan, location: location) moment = user.moments.build(plan: @plan, location: location) moment.photo.attach(io: File.open(file_fixture("real_image.jpg")), filename: "m.jpg", content_type: "image/jpeg") moment.save! @@ -830,6 +833,7 @@ def sync_browse_records end def publish_moment(user, location) + user.plan_visits.find_or_create_by!(plan: @plan, location: location) moment = user.moments.build(plan: @plan, location: location) moment.photo.attach(io: File.open(file_fixture("real_image.jpg")), filename: "m.jpg", content_type: "image/jpeg") moment.save! diff --git a/test/controllers/travel_profiles_controller_test.rb b/test/controllers/travel_profiles_controller_test.rb index f8332dce..ec3e5527 100644 --- a/test/controllers/travel_profiles_controller_test.rb +++ b/test/controllers/travel_profiles_controller_test.rb @@ -426,6 +426,7 @@ class TravelProfilesControllerTest < ActionDispatch::IntegrationTest private def own_moment + @user.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @user.moments.build(plan: @plan, location: @location) moment.photo.attach(io: File.open(file_fixture("test_image.jpg")), filename: "m.jpg", content_type: "image/jpeg") moment.save! diff --git a/test/integration/explore_bosnia_test.rb b/test/integration/explore_bosnia_test.rb index 8eebfc28..023a6a07 100644 --- a/test/integration/explore_bosnia_test.rb +++ b/test/integration/explore_bosnia_test.rb @@ -527,10 +527,15 @@ class ExploreBosniaTest < ActionDispatch::IntegrationTest Location.where("name LIKE 'Spot %'").destroy_all end + # A place with a moment of your own is a place you have visited, so it is no + # longer dealt; the moment that can still ride along is another traveller's. test "the deck ships no moments until a panel is opened" do - moment = @user.moments.new(plan: Plan.explore_bosnia_for(@user), location: @near, visibility: :private_moment) + other = User.create!(username: "deck_wanderer", email: "deck_wanderer@example.com", password: "password123") + other.plan_visits.create!(plan: Plan.explore_bosnia_for(other), location: @near) + moment = other.moments.new(plan: Plan.explore_bosnia_for(other), location: @near, visibility: :public_moment) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "real_image.jpg", content_type: "image/jpeg") moment.save! + moment.update!(moderation_status: :approved) login_as(@user) get explore_bosnia_experience_path("history", **SARAJEVO) @@ -538,10 +543,13 @@ class ExploreBosniaTest < ActionDispatch::IntegrationTest assert_response :success assert_select "turbo-frame[id=?][loading='lazy']", ActionView::RecordIdentifier.dom_id(@near, :moments_frame), count: 1 - refute_includes response.body, photo_plan_moment_path(moment.plan, moment, size: "thumb") + refute_includes response.body, moment.photo.blob.signed_id + ensure + other&.destroy end test "the moments frame renders the gallery for its location" do + @user.plan_visits.find_or_create_by!(plan: Plan.explore_bosnia_for(@user), location: @near) moment = @user.moments.new(plan: Plan.explore_bosnia_for(@user), location: @near, visibility: :private_moment) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "real_image.jpg", content_type: "image/jpeg") moment.save! @@ -560,6 +568,7 @@ class ExploreBosniaTest < ActionDispatch::IntegrationTest test "the gallery shows every moment in rows of three, not a sideways strip" do plan = Plan.explore_bosnia_for(@user) moments = 5.times.map do + @user.plan_visits.find_or_create_by!(plan: plan, location: @near) moment = @user.moments.new(plan: plan, location: @near, visibility: :private_moment) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "real_image.jpg", content_type: "image/jpeg") @@ -630,7 +639,19 @@ class ExploreBosniaTest < ActionDispatch::IntegrationTest assert_select "form[action=?]", publish_plan_moment_path(moment.plan, moment), count: 1 end - test "the moments panel offers the upload tile without a visit" do + test "the moments panel offers no upload tile before a visit" do + login_as(@user) + + get plan_moments_path(Plan.explore_bosnia_for(@user), location_id: @near.uuid, context: "explore"), + headers: { "Turbo-Frame" => ActionView::RecordIdentifier.dom_id(@near, :moments_frame) } + + assert_response :success + assert_select "label[aria-label=?]", I18n.t("plans.moments.add"), count: 0 + end + + test "the moments panel offers the upload tile once the place is visited on any plan" do + other_plan = Plan.create!(title: "Trip", visibility: :private_plan, user: @user) + @user.plan_visits.create!(plan: other_plan, location: @near) login_as(@user) get plan_moments_path(Plan.explore_bosnia_for(@user), location_id: @near.uuid, context: "explore"), @@ -642,6 +663,7 @@ class ExploreBosniaTest < ActionDispatch::IntegrationTest test "the moments panel shows another traveller's approved public moment" do other = User.create!(username: "other_wanderer", email: "other_wanderer@example.com", password: "password123") + other.plan_visits.find_or_create_by!(plan: Plan.explore_bosnia_for(other), location: @near) moment = other.moments.new(plan: Plan.explore_bosnia_for(other), location: @near, visibility: :public_moment) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "real_image.jpg", content_type: "image/jpeg") moment.save! @@ -658,6 +680,7 @@ class ExploreBosniaTest < ActionDispatch::IntegrationTest end test "an own approved public moment removes the be-first invitation" do + @user.plan_visits.find_or_create_by!(plan: Plan.explore_bosnia_for(@user), location: @near) moment = @user.moments.new(plan: Plan.explore_bosnia_for(@user), location: @near, visibility: :public_moment) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "real_image.jpg", content_type: "image/jpeg") @@ -677,6 +700,7 @@ class ExploreBosniaTest < ActionDispatch::IntegrationTest end test "publishing from the story actually publishes and streams the carousel back" do + @user.plan_visits.find_or_create_by!(plan: Plan.explore_bosnia_for(@user), location: @near) moment = @user.moments.new(plan: Plan.explore_bosnia_for(@user), location: @near, visibility: :private_moment) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "real_image.jpg", content_type: "image/jpeg") moment.save! @@ -694,6 +718,7 @@ class ExploreBosniaTest < ActionDispatch::IntegrationTest end test "deleting a moment from the story destroys it and its photo everywhere" do + @user.plan_visits.find_or_create_by!(plan: Plan.explore_bosnia_for(@user), location: @near) moment = @user.moments.new(plan: Plan.explore_bosnia_for(@user), location: @near, visibility: :private_moment) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "real_image.jpg", content_type: "image/jpeg") moment.save! diff --git a/test/integration/guest_walk_test.rb b/test/integration/guest_walk_test.rb index d380d148..8dbce126 100644 --- a/test/integration/guest_walk_test.rb +++ b/test/integration/guest_walk_test.rb @@ -183,6 +183,7 @@ class GuestWalkTest < ActionDispatch::IntegrationTest test "a signed-in traveller reading a place outside a plan can still upload" do user = User.create!(username: "browsing", email: "browsing@example.com", password: "password123") + user.plan_visits.create!(plan: Plan.explore_bosnia_for(user), location: @location) post user_session_path, params: { user: { email: user.email, password: "password123" } } get location_moments_path(@location.uuid) diff --git a/test/integration/moment_like_lifecycle_test.rb b/test/integration/moment_like_lifecycle_test.rb index f5a3f8e9..2c833562 100644 --- a/test/integration/moment_like_lifecycle_test.rb +++ b/test/integration/moment_like_lifecycle_test.rb @@ -114,6 +114,7 @@ class MomentLikeLifecycleTest < ActionDispatch::IntegrationTest end test "nobody can like a private moment, its author least of all" do + @author.plan_visits.find_or_create_by!(plan: @plan, location: @location) private_one = @author.moments.build(plan: @plan, location: @location, note: "mine alone") private_one.photo.attach(io: File.open(file_fixture("real_image.jpg")), filename: "mine.jpg", content_type: "image/jpeg") @@ -127,6 +128,7 @@ class MomentLikeLifecycleTest < ActionDispatch::IntegrationTest private def public_moment + @author.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @author.moments.build(plan: @plan, location: @location, note: "lifecycle") moment.photo.attach(io: File.open(file_fixture("real_image.jpg")), filename: "life.jpg", content_type: "image/jpeg") diff --git a/test/integration/moment_photo_access_test.rb b/test/integration/moment_photo_access_test.rb index 6f71ab91..c33f8f75 100644 --- a/test/integration/moment_photo_access_test.rb +++ b/test/integration/moment_photo_access_test.rb @@ -92,6 +92,7 @@ class MomentPhotoAccessTest < ActionDispatch::IntegrationTest end test "a blob whose bytes are not an image is refused rather than 500ing" do + @owner.plan_visits.find_or_create_by!(plan: @plan, location: @location) junk = @owner.moments.build(plan: @plan, location: @location) junk.photo.attach(io: StringIO.new("not an image"), filename: "junk.jpg", content_type: "image/jpeg") junk.save! @@ -109,6 +110,7 @@ def login_as(user) end def build_moment + @owner.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @owner.moments.build(plan: @plan, location: @location, note: "private moment") moment.photo.attach( io: File.open("test/fixtures/files/real_image.jpg"), diff --git a/test/integration/moments_walk_test.rb b/test/integration/moments_walk_test.rb index f22b37d9..10b27113 100644 --- a/test/integration/moments_walk_test.rb +++ b/test/integration/moments_walk_test.rb @@ -130,6 +130,7 @@ def login_as(user) end def add_moment(note: nil) + @user.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @user.moments.build(plan: @plan, location: @location, note: note) moment.photo.attach( io: File.open("test/fixtures/files/test_image.jpg"), diff --git a/test/integration/plan_start_test.rb b/test/integration/plan_start_test.rb index 68d942dd..472a293f 100644 --- a/test/integration/plan_start_test.rb +++ b/test/integration/plan_start_test.rb @@ -79,6 +79,7 @@ class PlanStartTest < ActionDispatch::IntegrationTest end test "capturing a photo on the walk adds it and shows it on the step" do + @user.plan_visits.create!(plan: @plan, location: @location) login_as(@user) post plan_moments_path(@plan), params: { @@ -165,6 +166,7 @@ class PlanStartTest < ActionDispatch::IntegrationTest test "another traveller's private moment never surfaces as a shared moment on the walk" do stranger = User.create!(username: "stranger", email: "stranger@example.com", password: "password123") + stranger.plan_visits.create!(plan: @plan, location: @location) hidden = Moment.create!(user: stranger, plan: @plan, location: @location, photo: fixture_file_upload("test/fixtures/files/real_image.jpg", "image/jpeg")) login_as(@user) diff --git a/test/models/like_test.rb b/test/models/like_test.rb index 1c8ff9ee..c47b38ec 100644 --- a/test/models/like_test.rb +++ b/test/models/like_test.rb @@ -91,6 +91,7 @@ class LikeTest < ActiveSupport::TestCase private def public_moment + @owner.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @owner.moments.build(plan: @plan, location: @location) moment.photo.attach(io: StringIO.new("fake image data"), filename: "like.jpg", content_type: "image/jpeg") moment.save! diff --git a/test/models/moment_test.rb b/test/models/moment_test.rb index 6a9227c6..d50aeb56 100644 --- a/test/models/moment_test.rb +++ b/test/models/moment_test.rb @@ -10,6 +10,7 @@ class MomentTest < ActiveSupport::TestCase @other_user = User.create!(username: "moment_stranger", email: "moment_stranger@example.com", password: "password123") @location = Location.create!(name: "Moment Location", city: "Mostar", lat: 43.34, lng: 17.81) @plan = Plan.create!(title: "Moment Plan", city_name: "Mostar", visibility: :private_plan, user: @user) + @user.plan_visits.create!(plan: @plan, location: @location) end teardown do @@ -40,6 +41,36 @@ class MomentTest < ActiveSupport::TestCase assert_includes moment.errors[:photo], "must be JPEG, PNG, GIF, or WebP" end + test "is refused at a place the traveller has not checked in at" do + @user.plan_visits.destroy_all + moment = build_moment + + assert_not moment.valid? + assert_includes moment.errors[:base], I18n.t("plans.moments.not_visited") + end + + test "a moment with no place is refused for the place, not for the check-in" do + moment = build_moment + moment.location = nil + + assert_not moment.valid? + assert_not_includes moment.errors[:base], I18n.t("plans.moments.not_visited") + end + + test "a check-in on any plan earns the capture" do + explore = Plan.explore_bosnia_for(@user) + + assert build_moment(plan: explore).valid? + end + + test "an existing moment still saves after its check-in is gone" do + moment = build_moment + moment.save! + @user.plan_visits.destroy_all + + assert moment.update(note: "Still mine") + end + test "rejects a note longer than 1000 characters" do moment = build_moment moment.note = "a" * 1001 diff --git a/test/models/plan_test.rb b/test/models/plan_test.rb index 83cd6e8f..874f20cd 100644 --- a/test/models/plan_test.rb +++ b/test/models/plan_test.rb @@ -723,6 +723,7 @@ def count_location_selects end def build_moment(traveller, plan) + traveller.plan_visits.find_or_create_by!(plan: plan, location: @location) moment = traveller.moments.build(plan: plan, location: @location) moment.photo.attach( io: File.open("test/fixtures/files/test_image.jpg"), diff --git a/test/system/explore_bosnia_test.rb b/test/system/explore_bosnia_test.rb index 4577ce4e..a22abb6a 100644 --- a/test/system/explore_bosnia_test.rb +++ b/test/system/explore_bosnia_test.rb @@ -1,7 +1,8 @@ require "application_system_test_case" # The explore browse deck in a real browser: the card's button checks in, tapping -# the card opens the menu, and the moments panel opens for anyone. +# the card opens the menu, and the moments panel opens for anyone. Capturing a +# moment there is earned by checking in. class ExploreBosniaSystemTest < ApplicationSystemTestCase setup do @user = User.create!(username: "sys_explorer", email: "sys_explorer@example.com", password: "password123") @@ -65,7 +66,7 @@ def stand_at(location) assert @user.plan_visits.joins(:plan).exists?(location: @location) end - test "moments open from the menu without having visited the place" do + test "moments open from the menu before a visit, and capture opens with the check-in" do login visit_deck @@ -74,16 +75,30 @@ def stand_at(location) find("button", text: I18n.t("plans.start.shared_moments"), match: :first).click assert_selector "[data-card-menu-target='panel'][data-panel='moments']", visible: true + assert_selector "[data-card-menu-target='panel'][data-panel='moments'] turbo-frame[complete]" + assert_no_selector "label[aria-label='#{I18n.t('plans.moments.add')}']" + + page.refresh + settle_deck + check_in + assert_text "Visited" + + open_moments_panel assert_selector "label[aria-label='#{I18n.t('plans.moments.add')}']" end + # Another traveller's moments: a place with moments of your own is a place you + # have checked in at, and the deck no longer deals it. test "a card's moments wrap into rows and the panel scrolls through them" do - plan = Plan.explore_bosnia_for(@user) + other = User.create!(username: "sys_other", email: "sys_other@example.com", password: "password123") + plan = Plan.explore_bosnia_for(other) + other.plan_visits.create!(plan: plan, location: @location) 7.times do - moment = @user.moments.new(plan: plan, location: @location, visibility: :private_moment) + moment = other.moments.new(plan: plan, location: @location, visibility: :public_moment) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "real_image.jpg", content_type: "image/jpeg") moment.save! + moment.update!(moderation_status: :approved) end login visit_deck @@ -107,6 +122,8 @@ def stand_at(location) })() JS assert_equal "auto", overflow, "the panel has to scroll once the rows outgrow the card" + ensure + other&.destroy end test "on a phone two filters can be pressed in a row without a page load" do diff --git a/test/system/moment_caption_test.rb b/test/system/moment_caption_test.rb index d761a522..d3075927 100644 --- a/test/system/moment_caption_test.rb +++ b/test/system/moment_caption_test.rb @@ -9,6 +9,7 @@ class MomentCaptionTest < ApplicationSystemTestCase @reader = User.create!(username: "cap_reader", email: "cap_reader@example.com", password: "password123") @location = Location.create!(name: "Caption Falls", city: "Jajce", lat: 44.34, lng: 17.27) @plan = Plan.create!(title: "Caption Plan", city_name: "Jajce", visibility: :private_plan, user: @author) + @author.plan_visits.create!(plan: @plan, location: @location) @moments = 2.times.map { |i| public_moment("worth the walk #{i}") } @moments.each { |m| Browse.sync_record(m) } end @@ -455,6 +456,7 @@ class MomentCaptionTest < ApplicationSystemTestCase test "the profile opens its moments in the same viewer, with the owner's controls" do login_as("cap_author") visit profile_page_path + dismiss_badge_celebration load_profile_moments find("#my-moments-frame [data-photo-gallery-target='thumbnail']", match: :first).click diff --git a/test/system/plan_walk_test.rb b/test/system/plan_walk_test.rb index 24d0c9b1..bef8589f 100644 --- a/test/system/plan_walk_test.rb +++ b/test/system/plan_walk_test.rb @@ -85,11 +85,13 @@ def stand_at(location) end test "publishing a moment from the profile updates in place (no full reload)" do + @user.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @user.moments.build(plan: @plan, location: @location) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "m.jpg", content_type: "image/jpeg") moment.save! login visit profile_page_path + dismiss_badge_celebration load_profile_moments frame = "##{ActionView::RecordIdentifier.dom_id(moment)}" @@ -103,11 +105,13 @@ def stand_at(location) end test "deleting a moment from the profile removes its card in place" do + @user.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @user.moments.build(plan: @plan, location: @location) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "m.jpg", content_type: "image/jpeg") moment.save! login visit profile_page_path + dismiss_badge_celebration load_profile_moments frame = "##{ActionView::RecordIdentifier.dom_id(moment)}" @@ -154,10 +158,10 @@ def stand_at(location) end test "the fullscreen moment closes on the X, even sitting over a swipeable card" do + @user.plan_visits.find_or_create_by!(plan: @plan, location: @location) moment = @user.moments.build(plan: @plan, location: @location) moment.photo.attach(io: File.open(Rails.root.join("test/fixtures/files/real_image.jpg")), filename: "m.jpg", content_type: "image/jpeg") moment.save! - @user.plan_visits.create!(plan: @plan, location: @location) login visit start_plan_path(@plan) diff --git a/wiki/_views/by-kind.md b/wiki/_views/by-kind.md index c1a366cd..ef618c88 100644 --- a/wiki/_views/by-kind.md +++ b/wiki/_views/by-kind.md @@ -2,7 +2,7 @@ title: Index — by kind kind: meta status: living -updated: 2026-09-30 +updated: 2026-10-08 confidence: high sources: - tools/brain.py @@ -21,6 +21,7 @@ Auto-generated by `python tools/brain.py views`. Do not edit by hand. - [Archive a place instead of deleting it](../decisions/archive-places-not-delete.md) — *accepted* - [Audio tours are paid by subscription; everything else stays free](../decisions/audio-tours-by-subscription.md) — *accepted* - [Avo now; compiling with Roundhouse and Spinel later](../decisions/avo-now-compile-later.md) — *accepted* +- [Capturing a moment needs a check-in at the place](../decisions/capture-needs-a-check-in.md) — *accepted* - [Curator dashboard v2 (RFC-0001)](../decisions/curator-dashboard-v2.md) — *superseded* - [DSL-first architecture for the Platform](../decisions/dsl-first-platform-architecture.md) — *accepted* - [Introspection and self-improvement in P0](../decisions/introspection-in-p0.md) — *accepted* diff --git a/wiki/_views/by-repo.md b/wiki/_views/by-repo.md index 82c3bb69..3485b4ce 100644 --- a/wiki/_views/by-repo.md +++ b/wiki/_views/by-repo.md @@ -2,7 +2,7 @@ title: Index — by repo kind: meta status: living -updated: 2026-09-30 +updated: 2026-10-08 confidence: high sources: - tools/brain.py @@ -25,6 +25,7 @@ Auto-generated by `python tools/brain.py views`. Do not edit by hand. - [Audio tours are paid by subscription; everything else stays free](../decisions/audio-tours-by-subscription.md) — *accepted* - [Avo admin and roles](../initiatives/avo-admin-and-roles.md) — *proposed* - [Avo now; compiling with Roundhouse and Spinel later](../decisions/avo-now-compile-later.md) — *accepted* +- [Capturing a moment needs a check-in at the place](../decisions/capture-needs-a-check-in.md) — *accepted* - [Conventions](../architecture/conventions.md) — *living* - [Curator dashboard v2 (RFC-0001)](../decisions/curator-dashboard-v2.md) — *superseded* - [Curator dashboard v2 salvage](../initiatives/curator-dashboard-v2-salvage.md) — *superseded* diff --git a/wiki/_views/by-team.md b/wiki/_views/by-team.md index 8fa4c90c..d5a82c12 100644 --- a/wiki/_views/by-team.md +++ b/wiki/_views/by-team.md @@ -2,7 +2,7 @@ title: Index — by team kind: meta status: living -updated: 2026-09-30 +updated: 2026-10-08 confidence: high sources: - tools/brain.py diff --git a/wiki/decisions/capture-needs-a-check-in.md b/wiki/decisions/capture-needs-a-check-in.md new file mode 100644 index 00000000..67fb91df --- /dev/null +++ b/wiki/decisions/capture-needs-a-check-in.md @@ -0,0 +1,54 @@ +--- +title: Capturing a moment needs a check-in at the place +kind: decision +status: accepted +updated: 2026-10-08 +repos: +- usput.ba +confidence: medium +sources: +- https://github.com/misabegovic/usput.ba/pull/164 +- https://github.com/misabegovic/usput.ba/pull/165 +- https://github.com/misabegovic/usput.ba/pull/166 +- app/models/moment.rb +- app/views/plans/_moment_gallery.html.erb +- app/views/moments/update.turbo_stream.erb +- app/controllers/plans/visits_controller.rb +- config/locales/en.yml +- test/integration/explore_bosnia_test.rb +- test/system/explore_bosnia_test.rb +enola_intent: + page: + type: decision + status: accepted + scope: + - usput.ba + origin: + - repo + - web +--- +# Capturing a moment needs a check-in at the place + +## Context + +The product said one thing and the code did another. PR #164 introduced moments with the words "At a place you have reached you can capture a moment", and the [feature inventory](../product/features.md) repeats it. The explore copy reads "Visit it, capture a moment, come back for more" (`explore_bosnia.subtitle` in `config/locales/en.yml`). A check-in already redraws the place's moments gallery (`Plans::VisitsController#create` renders `moments/update`), and a test from #165 carries the comment "capture is earned by being there". + +Nothing enforced it. Neither `MomentsController#create` nor `Moment` asked for a check-in, and the upload tile rendered for every signed-in traveller. Three tests asserted the tile without a visit: two from #165 (the explore deck's moments panel) and one from #166 (a place read outside a plan). None of the pull request bodies, issues, commits, wiki pages or planning sources says that capture without a visit was wanted; the tests were the only place it was stated. The question was raised on 2026-10-08 by a concept map of the product, and the operator delegated the call. + +## Decision + +A moment is captured only at a place the traveller has checked in at, on any of their plans. `Moment` refuses to be created otherwise, with a message telling the traveller to mark the visit first, and the controller's existing failure path returns that message. The upload tile appears only once the place is visited; before that the moments panel still opens and shows other travellers' approved moments. A guest keeps the sign-in tile, because a guest's check-ins live on the device until sign-in replays them. The rule is asked on create only, so a moment outlives its check-in. + +## Alternatives + +- Amend the inventory to say capture needs no visit. Rejected: every written statement of intent says reached, and the check-in already redraws the gallery as though capture follows it. +- Ask for a check-in on the same plan as the moment. Rejected: a place reached on one trip is reached; the deck already treats a visit on any plan as visited, and the location page uploads to the plan its visit was on or to the explore plan. +- Hide the tile but let the server accept any capture. Rejected: the rule would then hold only for travellers who use the screen. + +## Consequences + +A moment now means the traveller was there, which is what a public moment shown to others implies. In the explore deck a card's moments panel offers capture after the check-in, not before. Tests that build a moment record a check-in first, and the three tests that asserted the tile without a visit now assert the opposite. + +## Status notes + +In force from the pull request that adds `Moment#captured_at_a_visited_place` (`app/models/moment.rb`) and the `visited_location?` guard on the upload tile (`app/views/plans/_moment_gallery.html.erb`). The message is `plans.moments.not_visited` in `config/locales/en.yml` and `config/locales/bs.yml`. diff --git a/wiki/decisions/index.md b/wiki/decisions/index.md index 77477f12..505427dc 100644 --- a/wiki/decisions/index.md +++ b/wiki/decisions/index.md @@ -2,7 +2,7 @@ title: Decisions kind: reference status: living -updated: 2026-09-30 +updated: 2026-10-08 repos: - usput.ba sources: @@ -22,6 +22,7 @@ Architecture decision records, one choice per page. Accepted pages describe the ## Accepted +- [Capturing a moment needs a check-in at the place](capture-needs-a-check-in.md) - [Accounts through Devise, signed in by email](accounts-through-devise.md) - [Audio tours are paid by subscription; everything else stays free](audio-tours-by-subscription.md) - [Jev flags reviews; flagged reviews wait for an admin](jev-flags-reviews.md) diff --git a/wiki/decisions/log.md b/wiki/decisions/log.md index b374fe88..0c321837 100644 --- a/wiki/decisions/log.md +++ b/wiki/decisions/log.md @@ -2,7 +2,7 @@ title: Decision log kind: reference status: living -updated: 2026-09-30 +updated: 2026-10-08 repos: - usput.ba confidence: medium @@ -59,3 +59,4 @@ Every recorded decision for Usput.ba in date order, oldest first. Dates are thos | 2026-09-30 | [Avo now; compiling with Roundhouse and Spinel later](avo-now-compile-later.md) | accepted | Avo is adopted; Roundhouse is used for `check` only until compiling fits what usput uses. | | 2026-09-30 | [Audio tours are paid by subscription; everything else stays free](audio-tours-by-subscription.md) | accepted | EUR 3 a week, 6 a month, 39 a year, all renewing, first stop free, through Stripe from a company abroad. | | 2026-09-30 | [Accounts through Devise, signed in by email](accounts-through-devise.md) | accepted | Devise with confirmation (three-day grace), reset through Postmark, a rotating session token to sign out everywhere; replaces #171's session rows. | +| 2026-10-08 | [Capturing a moment needs a check-in at the place](capture-needs-a-check-in.md) | accepted | A moment is created only where the traveller checked in, on any plan; the upload tile waits for the visit. | diff --git a/wiki/product/domain.md b/wiki/product/domain.md index 35593e1b..4a15a1c4 100644 --- a/wiki/product/domain.md +++ b/wiki/product/domain.md @@ -2,7 +2,7 @@ title: Domain vocabulary kind: reference status: living -updated: 2026-09-30 +updated: 2026-10-08 repos: - usput.ba confidence: medium @@ -87,7 +87,7 @@ The product word is check-in; the table is `plan_visits`. A row records that a u ### Moment -A photo and an optional note (up to 1000 characters) that a user takes at a location on a plan (`app/models/moment.rb`). The photo is required: JPEG, PNG, GIF or WebP, at most 10 MB. +A photo and an optional note (up to 1000 characters) that a user takes at a location on a plan (`app/models/moment.rb`). The photo is required: JPEG, PNG, GIF or WebP, at most 10 MB. A moment is created only where its user has a check-in at the location, on any plan; the check is made on create, so a moment outlives its check-in ([decision](../decisions/capture-needs-a-check-in.md)). - **Visibility.** `private_moment` (default) or `public_moment`. - **Moderation.** `pending`, `approved`, `rejected`. Making a moment public resets it to `pending`, so a curator must approve it before others see it. Only public and approved moments are `publicly_visible`, likeable, shareable and indexed in Browse. diff --git a/wiki/product/features.md b/wiki/product/features.md index ee45e960..8bd1d58d 100644 --- a/wiki/product/features.md +++ b/wiki/product/features.md @@ -114,7 +114,7 @@ This is what Usput.ba ships as of 2026-09-29, grouped by what a person does with - **Walk.** `/plans/:id/start` walks a plan as a stack of cards, nearest first. Each card carries a map, the audio tour and the check-in ([#164](https://github.com/misabegovic/usput.ba/pull/164)). - **Check-in.** Browser and server ask the same question: is the traveller within 100 m? The distance is one constant, `MAX_VISIT_DISTANCE_KM`, used by every surface (`app/controllers/concerns/records_visits.rb`). A warm and cold hint under the button tracks the distance. Admins check in from anywhere. The PR notes that 100 m is a testing value meant to drop to about 10 m ([#164](https://github.com/misabegovic/usput.ba/pull/164)). - **Guest walk.** A visitor explores, walks and checks in without an account. The walk stays on the device and is replayed into ordinary rows once, at sign-in or sign-up. The replay cannot be re-verified on the server: the 100 m gate ran in the browser ([#166](https://github.com/misabegovic/usput.ba/pull/166); `app/services/guest_visits_importer.rb`, `MAX_VISITS = 500`). -- **Moments.** At a place already reached, a traveller captures a photo and a note. A moment is private; publishing sends it to a curator, and only an approved public moment is visible to others or searchable. Photos are served by the app's own action after a session check, never by a signed storage URL ([#164](https://github.com/misabegovic/usput.ba/pull/164)). Photos can be taken in the app, and iPhone photos are converted before upload ([#167](https://github.com/misabegovic/usput.ba/pull/167)). +- **Moments.** At a place already reached, a traveller captures a photo and a note. Reached means checked in, on any plan: the server refuses a moment anywhere else, and the upload tile appears only after the check-in ([decision](../decisions/capture-needs-a-check-in.md); `app/models/moment.rb`). A moment is private; publishing sends it to a curator, and only an approved public moment is visible to others or searchable. Photos are served by the app's own action after a session check, never by a signed storage URL ([#164](https://github.com/misabegovic/usput.ba/pull/164)). Photos can be taken in the app, and iPhone photos are converted before upload ([#167](https://github.com/misabegovic/usput.ba/pull/167)). - **Moments view and likes.** A moment opens in a full view with who took it, where, the note, a download and a like. A like is its own record and needs a login. Each moment has its own URL (`/moments/:id`) with a link preview. A place's page has a shelf of its moments, loaded as the traveller scrolls ([#167](https://github.com/misabegovic/usput.ba/pull/167); `config/routes.rb`). - **Travel profile.** `/profile` shows plans, moments and visited places. Visited places and counts come from check-in rows, not from the device copy (`app/controllers/travel_profiles_controller.rb`). diff --git a/wiki/state.md b/wiki/state.md index 3da0fbae..9811e94c 100644 --- a/wiki/state.md +++ b/wiki/state.md @@ -66,6 +66,7 @@ Where Usput.ba has been, what is true in the code today, what the older planning - **Accounts.** Devise with sign-in by email, confirmation within three days, reset by email through Postmark, an account page, and one token that ends every session on a password change, a block or a button; #171's session rows are gone ([decision](decisions/accounts-through-devise.md)). A database holding accounts without an email cannot migrate, by design: the rebuild starts empty. - **Admin.** Avo 4 Community at `/admin`, open only to curators and admins, checked in the route and again inside Avo; users page for admins, with role changes and blocks, places, experiences and plans with all 16 languages editable, plans limited to curated ones and travellers' public ones, and audio tours ([Avo admin and roles](initiatives/avo-admin-and-roles.md)). Curators create and edit there directly; there are no proposals. What is left of the old curator dashboard runs beside it until each Avo slice replaces a part. - **Curator dashboard.** What remains at `/curator` is the start page with counts and recent activity, whose links now open the admin, the moments queue (`Moment` enum `moderation_status`), the reviews list, where only an admin removes a review, and the old users pages. Proposals (`ContentChange`, its contributions and curator reviews) and the curator pages for places, experiences, plans and audio tours were removed on 2026-09-30 ([removal plan](initiatives/remove-curator-dashboard.md)). +- **Moments need a check-in.** Since 2026-10-08 a moment is saved only at a place the traveller checked in at, on any of their plans, and the upload tile appears only after that check-in; guests keep the sign-in tile ([decision](decisions/capture-needs-a-check-in.md); `app/models/moment.rb`). - **Reviews are unmoderated.** `Review` has no status column; any visitor can post (the controller has no login requirement and still permits `author_name`), and every review counts toward `average_rating` (`app/models/review.rb`, `app/controllers/reviews_controller.rb`). - **Platform CLI.** `bin/platform` offers `status`, `version`, `query` and `exec` for DSL queries; there is no `chat` command (`lib/platform/cli.rb`). Executors cover schema, table queries, content, curators, external data, infrastructure and quality. The MCP server exists (`lib/platform/mcp_server.rb`) and refuses to run in production. - **AI content.** `Ai::LocationEnricher`, `Ai::ExperienceTypeClassifier`, `Ai::AudioTourGenerator` and `Ai::ExperienceLocationSyncer` call the LLM directly with prompts under `app/prompts/`. Audio tours are generated from rake tasks and DSL, not from the dashboard.