Merge remote-tracking branch 'upstream/pull/5535'

This commit is contained in:
Tom Hughes 2025-01-22 18:07:34 +00:00
commit b0cf1940e1
17 changed files with 232 additions and 210 deletions

View file

@ -32,7 +32,7 @@ class Ability
can :read, [:deletion, :account_terms]
if Settings.status != "database_offline"
can [:subscribe, :unsubscribe], Changeset
can [:read, :create, :destroy], :changeset_subscription
can [:read, :create, :update, :destroy], :oauth2_application
can [:read, :destroy], :oauth2_authorized_application
can [:read, :create, :destroy], :oauth2_authorization

View file

@ -0,0 +1,38 @@
class ChangesetSubscriptionsController < ApplicationController
layout "site"
before_action :authorize_web
before_action :set_locale
before_action :check_database_writable
authorize_resource :class => :changeset_subscription
around_action :web_timeout
def show
@changeset = Changeset.find(params[:changeset_id])
@subscribed = @changeset.subscribed?(current_user)
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
end
def create
@changeset = Changeset.find(params[:changeset_id])
@changeset.subscribe(current_user) unless @changeset.subscribed?(current_user)
redirect_to changeset_path(@changeset)
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
end
def destroy
@changeset = Changeset.find(params[:changeset_id])
@changeset.unsubscribe(current_user)
redirect_to changeset_path(@changeset)
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
end
end

View file

@ -7,9 +7,8 @@ class ChangesetsController < ApplicationController
before_action :authorize_web
before_action :set_locale
before_action -> { check_database_readable(:need_api => true) }, :only => [:index, :feed, :show]
before_action -> { check_database_readable(:need_api => true) }
before_action :require_oauth, :only => :show
before_action :check_database_writable, :only => [:subscribe, :unsubscribe]
authorize_resource
@ -107,34 +106,6 @@ class ChangesetsController < ApplicationController
render :template => "browse/not_found", :status => :not_found, :layout => map_layout
end
##
# subscribe to a changeset
def subscribe
@changeset = Changeset.find(params[:id])
if request.post?
@changeset.subscribe(current_user) unless @changeset.subscribed?(current_user)
redirect_to changeset_path(@changeset)
end
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
end
##
# unsubscribe from a changeset
def unsubscribe
@changeset = Changeset.find(params[:id])
if request.post?
@changeset.unsubscribe(current_user)
redirect_to changeset_path(@changeset)
end
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
end
private
#------------------------------------------------------------

View file

@ -177,7 +177,7 @@ class UserMailer < ApplicationMailer
@changeset_comment = comment.changeset.tags["comment"].presence
@time = comment.created_at
@changeset_author = comment.changeset.user.display_name
@unsubscribe_url = unsubscribe_changeset_url(comment.changeset)
@changeset_subscription_url = changeset_subscription_url(comment.changeset)
@author = @commenter
subject = if @owner
@ -193,8 +193,8 @@ class UserMailer < ApplicationMailer
set_list_headers(
"#{comment.changeset.id}.changeset.www.openstreetmap.org",
t(".description", :id => comment.changeset.id),
:subscribe => subscribe_changeset_url(comment.changeset),
:unsubscribe => @unsubscribe_url,
:subscribe => @changeset_subscription_url,
:unsubscribe => @changeset_subscription_url,
:archive => @changeset_url
)

View file

@ -0,0 +1,5 @@
<% content_for :heading do %>
<h1><%= t ".heading", :id => h(params[:changeset_id]) %></h1>
<% end %>
<p><%= t ".body", :id => h(params[:changeset_id]) %></p>

View file

@ -0,0 +1,12 @@
<% content_for :heading do %>
<h1><%= @subscribed ? t(".unsubscribe.heading") : t(".subscribe.heading") %></h1>
<% end %>
<%= render :partial => "heading", :object => @changeset, :as => "changeset" %>
<%= bootstrap_form_tag :method => (@subscribed ? :delete : :post) do |f| %>
<% if params[:referer] -%>
<%= f.hidden_field :referer, :value => params[:referer] %>
<% end -%>
<%= f.primary @subscribed ? t(".unsubscribe.button") : t(".subscribe.button") %>
<% end %>

View file

@ -1,5 +0,0 @@
<% content_for :heading do %>
<h1><%= t ".heading", :id => h(params[:id]) %></h1>
<% end %>
<p><%= t ".body", :id => h(params[:id]) %></p>

View file

@ -1,12 +0,0 @@
<% content_for :heading do %>
<h1><%= t ".heading" %></h1>
<% end %>
<%= render :partial => "heading", :object => @changeset, :as => "changeset" %>
<%= bootstrap_form_tag do |f| %>
<% if params[:referer] -%>
<%= f.hidden_field :referer, :value => params[:referer] %>
<% end -%>
<%= f.primary t(".button") %>
<% end %>

View file

@ -1,12 +0,0 @@
<% content_for :heading do %>
<h1><%= t ".heading" %></h1>
<% end %>
<%= render :partial => "heading", :object => @changeset, :as => "changeset" %>
<%= bootstrap_form_tag do |f| %>
<% if params[:referer] -%>
<%= f.hidden_field :referer, :value => params[:referer] %>
<% end -%>
<%= f.primary t(".button") %>
<% end %>

View file

@ -24,6 +24,6 @@
<% content_for :footer do %>
<p>
<%= t ".unsubscribe_html", :url => link_to(@unsubscribe_url, @unsubscribe_url) %>
<%= t ".unsubscribe_html", :url => link_to(@changeset_subscription_url, @changeset_subscription_url) %>
</p>
<% end %>

View file

@ -17,4 +17,4 @@
<%= t '.details', :url => @changeset_url %>
<%= t '.unsubscribe', :url => @unsubscribe_url %>
<%= t '.unsubscribe', :url => @changeset_subscription_url %>