You’re still describing your solution and not the problem you’re solving. What do you want to do in that file? There may be a better way to trigger it. Knowing that will also make it easier to suggest something similar.
The subscription plugin adds an endpoint, so you might look at that. You’ll need to add a route in rails and then in ember add an action to your button that will call it.
I have a user with huge number of posts. I want to delete all posts of for that user the default delete all posts button giving 503 error. So I written a code schedule a cron job to run every 2 minutes and delete 100 posts at a time
Yes, you are but there are many such users on the site. And my client is non-technical person how will he that.I need to write a plugin as the client institng me
And also the issue can arises in other forums website. We really need to have a look at the issue I am facing. we can make improvements in default delete post feature in future update
I am still stucked at this, What can be main cause of the issue below is my implementaion of code
===> plugin.rb
Discourse::Application.routes.append do
get '/admin/plugins/delete-topic-ui' => 'admin/plugins#index'
get '/admin/plugins/delete_all_posts' => 'delete_user_posts#delete_all_posts'
end
class DeleteUserPostsController < ApplicationController
# before_action :ensure_admin, only: [:delete_all_posts]
def delete_all_posts
# username = params[:username]
username = SiteSetting.delete_posts_for_username
user = User.find_by_username_or_email(username)
if user
PostDestroyer.new(current_user).destroy_all_posts(user)
redirect_to admin_index_path, notice: "All posts by #{username} have been deleted."
else
redirect_to admin_index_path, alert: "User not found."
end
end
def ensure_admin
unless current_user&.admin?
render json: { error: 'Unauthorized' }, status: :unauthorized
end
end
end
import { ajax } from 'discourse/lib/ajax';
export default Ember.Controller.extend({
actions: {
deletePosts() {
ajax('/admin/plugins/delete_all_posts', {
type: 'GET',
data: {
// Include any data you want to send to the server in the request body
// Example: param1: 'value1', param2: 'value2'
}
})
.then(response => {
// Handle the success response
console.log(response);
})
.catch(error => {
// Handle the error
console.error(error);
});
},
test() {
ajax('/test', {
type: 'GET',
data: {
// Include any data you want to send to the server in the request body
// Example: param1: 'value1', param2: 'value2'
},
dataType: 'text'
})
.then(response => {
// Handle the success response
console.log(response);
})
.catch(error => {
// Handle the error
console.error(error);
});
},
testjob() {
ajax('/testjob', {
type: 'GET',
data: {
// Include any data you want to send to the server in the request body
// Example: param1: 'value1', param2: 'value2'
}
})
.then(response => {
// Handle the success response
console.log(response);
})
.catch(error => {
// Handle the error
console.error(error);
});
}
}
});