Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/builds/tailwind.css

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions app/avo/actions/approve_moment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Avo::Actions::ApproveMoment < Avo::BaseAction
self.name = -> { I18n.t("admin.moments.approve") }
self.authorize = -> { MomentPolicy.new(current_user).moderate? }

def handle(query:, current_user:, **)
moments = query.select { |moment| MomentPolicy.new(current_user, moment).moderate? && !moment.approved? }
moments.each do |moment|
moment.update!(moderation_status: :approved)
CuratorActivity.record(user: current_user, action: :approve_moment, recordable: moment)
end
succeed I18n.t("admin.moments.approved", count: moments.size)
end
end
13 changes: 13 additions & 0 deletions app/avo/actions/reject_moment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Avo::Actions::RejectMoment < Avo::BaseAction
self.name = -> { I18n.t("admin.moments.reject") }
self.authorize = -> { MomentPolicy.new(current_user).moderate? }

def handle(query:, current_user:, **)
moments = query.select { |moment| MomentPolicy.new(current_user, moment).moderate? && !moment.rejected? }
moments.each do |moment|
moment.update!(moderation_status: :rejected)
CuratorActivity.record(user: current_user, action: :reject_moment, recordable: moment)
end
succeed I18n.t("admin.moments.rejected", count: moments.size)
end
end
16 changes: 16 additions & 0 deletions app/avo/filters/moment_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The queue opens on the moments waiting for a decision.
class Avo::Filters::MomentStatus < Avo::Filters::SelectFilter
self.name = -> { I18n.t("admin.moments.status") }

def apply(_request, query, value)
value == "all" ? query : query.where(moderation_status: value)
end

def default
"pending"
end

def options
%w[pending approved rejected all].index_with { |status| I18n.t("admin.moments.statuses.#{status}") }
end
end
38 changes: 38 additions & 0 deletions app/avo/resources/moment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Avo::Resources::Moment < Avo::BaseResource
self.icon = "tabler/outline/camera"
self.title = :note
self.includes = [ :user, :location ]
# Public moments only; a private one is not found even by its link.
self.index_query = -> { MomentPolicy.visible(query).order(created_at: :desc) }
self.find_record_method = -> {
scope = MomentPolicy.visible(query)
id.is_a?(Array) ? scope.where(uuid: id) : scope.find_by!(uuid: id)
}

def fields
field :photo_preview, as: :external_image, name: I18n.t("admin.moments.photo"), width: 96, height: 96, radius: 8,
link_to_record: true, only_on: :index do
main_app.admin_moment_photo_path(record, size: "thumb")
end
field :photo_full, as: :external_image, name: I18n.t("admin.moments.photo"), only_on: :show do
main_app.admin_moment_photo_path(record, size: "story")
end
field :moderation_status, as: :badge, name: I18n.t("admin.moments.status"),
options: { warning: "pending", success: "approved", danger: "rejected" }
field :note, as: :text, name: I18n.t("admin.moments.note")
field :author, as: :text, name: I18n.t("admin.moments.author") do
record.user&.username
end
field :location, as: :belongs_to, name: I18n.t("admin.moments.place")
field :created_at, as: :date_time, name: I18n.t("admin.moments.shared_at"), sortable: true
end

def filters
filter Avo::Filters::MomentStatus
end

def actions
action Avo::Actions::ApproveMoment
action Avo::Actions::RejectMoment
end
end
13 changes: 13 additions & 0 deletions app/controllers/admin/moment_photos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Serves a public moment's photo to the admin. Avo's own file field would hand
# out a signed blob url, which works for anyone holding it; this streams the
# bytes behind the same curator gate as the rest of the admin.
class Admin::MomentPhotosController < ApplicationController
include ServesMomentPhotos

before_action :require_login
before_action :require_curator

def show
stream_moment_photo(MomentPolicy.visible(Moment).find_by_public_id!(params[:id]), public: false)
end
end
3 changes: 3 additions & 0 deletions app/controllers/avo/moments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Avo::MomentsController < Avo::ResourcesController
include AdminResource
end
48 changes: 0 additions & 48 deletions app/controllers/curator/moments_controller.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/helpers/curator_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def activity_link_path(activity)
when Experience then avo.resources_experience_path(activity.recordable)
when Plan then avo.resources_plan_path(activity.recordable)
when AudioTour then avo.resources_audio_tour_path(activity.recordable)
when Moment then avo.resources_moment_path(activity.recordable) if activity.recordable.visibility_public_moment?
end
rescue ActionController::UrlGenerationError
nil
Expand Down
14 changes: 14 additions & 0 deletions app/policies/moment_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Travellers publish moments; curators decide whether the public sees them.
# Only moments a traveller chose to make public reach the admin, and nobody
# creates, edits or deletes one there: rejecting is how a moment comes down.
class MomentPolicy < AdminPolicy
def self.visible(query)
query.visibility_public_moment
end

def show? = curator? && (record.nil? || record.visibility_public_moment?)
def moderate? = show?
def create? = false
def update? = false
def destroy? = false
end
63 changes: 0 additions & 63 deletions app/views/curator/moments/index.html.erb

This file was deleted.

10 changes: 5 additions & 5 deletions app/views/layouts/curator.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class: "rounded-md px-3 py-2 text-sm font-medium text-emerald-100 dark:text-gray-300 hover:bg-emerald-600 dark:hover:bg-gray-700" %>

<%# Workflow dropdown: Reviews, Moments %>
<% workflow_active = [curator_reviews_path, curator_moments_path].any? { |p| request.path.start_with?(p) } %>
<% workflow_active = [curator_reviews_path].any? { |p| request.path.start_with?(p) } %>
<div data-controller="dropdown" class="relative">
<button data-action="click->dropdown#toggle" type="button"
class="inline-flex items-center gap-1 rounded-md px-3 py-2 text-sm font-medium <%= workflow_active ? 'bg-emerald-800 dark:bg-gray-900 text-white' : 'text-emerald-100 dark:text-gray-300 hover:bg-emerald-600 dark:hover:bg-gray-700' %>">
Expand All @@ -54,8 +54,8 @@
<div data-dropdown-target="menu" class="hidden absolute left-0 z-10 mt-1 w-48 origin-top-left rounded-md bg-white dark:bg-gray-800 py-1 shadow-lg ring-1 ring-black/5 dark:ring-gray-700">
<%= link_to t("curator.nav.reviews"), curator_reviews_path,
class: "block px-4 py-2 text-sm #{request.path.start_with?(curator_reviews_path) ? 'bg-emerald-50 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-400 font-medium' : 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700'}" %>
<%= link_to t("curator.nav.moments"), curator_moments_path,
class: "block px-4 py-2 text-sm #{request.path.start_with?(curator_moments_path) ? 'bg-emerald-50 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-400 font-medium' : 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700'}" %>
<%= link_to t("curator.nav.moments"), avo.resources_moments_path,
class: "block px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700" %>
</div>
</div>

Expand Down Expand Up @@ -135,8 +135,8 @@
<p class="px-3 text-xs font-semibold uppercase tracking-wider text-emerald-300 dark:text-gray-500"><%= t("curator.nav.workflow") %></p>
<%= link_to t("curator.nav.reviews"), curator_reviews_path,
class: "block rounded-md px-3 py-2 text-base font-medium #{request.path.start_with?(curator_reviews_path) ? 'bg-emerald-800 dark:bg-gray-900 text-white' : 'text-emerald-100 dark:text-gray-300 hover:bg-emerald-600 dark:hover:bg-gray-700'}" %>
<%= link_to t("curator.nav.moments"), curator_moments_path,
class: "block rounded-md px-3 py-2 text-base font-medium #{request.path.start_with?(curator_moments_path) ? 'bg-emerald-800 dark:bg-gray-900 text-white' : 'text-emerald-100 dark:text-gray-300 hover:bg-emerald-600 dark:hover:bg-gray-700'}" %>
<%= link_to t("curator.nav.moments"), avo.resources_moments_path,
class: "block rounded-md px-3 py-2 text-base font-medium text-emerald-100 dark:text-gray-300 hover:bg-emerald-600 dark:hover:bg-gray-700" %>
</div>

<%# Admin section - only for admin users %>
Expand Down
34 changes: 20 additions & 14 deletions config/locales/bs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,26 @@ bs:
ownerships:
curated: Usput
travellers: Putnici (javni)
moments:
photo: Fotografija
status: Status
note: Bilješka
author: Podijelio
place: Mjesto
shared_at: Podijeljeno
approve: Odobri
reject: Odbij
approved:
one: Jedna uspomena odobrena.
other: "Odobreno uspomena: %{count}."
rejected:
one: Jedna uspomena odbijena.
other: "Odbijeno uspomena: %{count}."
statuses:
pending: Čeka
approved: Odobreno
rejected: Odbijeno
all: Sve
audio_tours:
place: Mjesto
language: Jezik
Expand Down Expand Up @@ -1201,20 +1221,6 @@ bs:
dashboard: Pregled
reviews: Recenzije
moments: Uspomene
moments:
title: Podijeljene uspomene
subtitle: Fotografije putnika koje čekaju pregled prije nego postanu javne
empty: Nema uspomena za pregled.
by: objavio/la %{user}
approve: Odobri
reject: Odbij
status:
pending: Na čekanju
approved: Odobreno
rejected: Odbijeno
flash:
approved: Uspomena odobrena
rejected: Uspomena odbijena
dashboard:
welcome: Dobrodošao, %{username}!
total_locations: Ukupno lokacija
Expand Down
34 changes: 20 additions & 14 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,26 @@ en:
ownerships:
curated: Usput
travellers: Travellers (public)
moments:
photo: Photo
status: Status
note: Note
author: Shared by
place: Place
shared_at: Shared
approve: Approve
reject: Reject
approved:
one: One moment approved.
other: "%{count} moments approved."
rejected:
one: One moment rejected.
other: "%{count} moments rejected."
statuses:
pending: Waiting
approved: Approved
rejected: Rejected
all: All
audio_tours:
place: Place
language: Language
Expand Down Expand Up @@ -1262,20 +1282,6 @@ en:
workflow: Workflow
reviews: Reviews
moments: Moments
moments:
title: Shared moments
subtitle: Travellers' photos awaiting review before they appear publicly
empty: No moments to review.
by: by %{user}
approve: Approve
reject: Reject
status:
pending: Pending
approved: Approved
rejected: Rejected
flash:
approved: Moment approved
rejected: Moment rejected
dashboard:
welcome: Welcome, %{username}!
total_locations: Total Locations
Expand Down
8 changes: 1 addition & 7 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
# The admin (Avo) at /admin: a guest is sent to sign in, anyone who is not a
# curator or admin finds no such page. Avo checks the role again inside.
authenticate :user, ->(user) { user.can_curate? } do
get "admin/moment_photos/:id", to: "admin/moment_photos#show", as: :admin_moment_photo
mount_avo do
get "welcome", to: "tools#welcome", as: :welcome
end
Expand Down Expand Up @@ -143,13 +144,6 @@
# Curator dashboard - for curators and admins
namespace :curator do
resources :reviews, only: [ :index, :show, :destroy ]
resources :moments, only: [ :index ] do
member do
get :photo
post :approve
post :reject
end
end

# Admin features for admin users within curator dashboard
namespace :admin do
Expand Down
Loading