mirror of
				https://github.com/discourse/discourse-solved.git
				synced 2025-11-04 08:28:55 +00:00 
			
		
		
		
	This commit autoloads plugin files, and also extracts features into their own modules. - `plugin.rb` is smaller - external plugins like discourse-automation and discourse-assign have their own entrypoints - solved filters as well
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
# frozen_string_literal: true
 | 
						|
 | 
						|
class DiscourseSolved::AnswerController < ::ApplicationController
 | 
						|
  requires_plugin DiscourseSolved::PLUGIN_NAME
 | 
						|
 | 
						|
  def accept
 | 
						|
    limit_accepts
 | 
						|
 | 
						|
    post = Post.find(params[:id].to_i)
 | 
						|
 | 
						|
    topic = post.topic
 | 
						|
    topic ||= Topic.with_deleted.find(post.topic_id) if guardian.is_staff?
 | 
						|
 | 
						|
    guardian.ensure_can_accept_answer!(topic, post)
 | 
						|
 | 
						|
    DiscourseSolved.accept_answer!(post, current_user, topic: topic)
 | 
						|
 | 
						|
    render json: success_json
 | 
						|
  end
 | 
						|
 | 
						|
  def unaccept
 | 
						|
    limit_accepts
 | 
						|
 | 
						|
    post = Post.find(params[:id].to_i)
 | 
						|
 | 
						|
    topic = post.topic
 | 
						|
    topic ||= Topic.with_deleted.find(post.topic_id) if guardian.is_staff?
 | 
						|
 | 
						|
    guardian.ensure_can_accept_answer!(topic, post)
 | 
						|
 | 
						|
    DiscourseSolved.unaccept_answer!(post, topic: topic)
 | 
						|
 | 
						|
    render json: success_json
 | 
						|
  end
 | 
						|
 | 
						|
  def limit_accepts
 | 
						|
    return if current_user.staff?
 | 
						|
    RateLimiter.new(nil, "accept-hr-#{current_user.id}", 20, 1.hour).performed!
 | 
						|
    RateLimiter.new(nil, "accept-min-#{current_user.id}", 4, 30.seconds).performed!
 | 
						|
  end
 | 
						|
end
 |