add user action and correct icon for small post
This commit is contained in:
parent
be759616b9
commit
0205a12956
|
@ -1,8 +1,12 @@
|
||||||
//function initializeWithApi() {
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||||
//};
|
|
||||||
//
|
function initialize(api) {
|
||||||
|
api.addPostSmallActionIcon('assigned','user-plus');
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'extend-for-assign',
|
name: 'extend-for-assign',
|
||||||
initialize() {
|
initialize() {
|
||||||
|
withPluginApi('0.8', initialize);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,7 @@ en:
|
||||||
action_codes:
|
action_codes:
|
||||||
assigned: "assigned"
|
assigned: "assigned"
|
||||||
discourse_assign:
|
discourse_assign:
|
||||||
|
assign_notification: "<i title='assigned' class='fa fa-user-plus'></i><p><span>{{username}}</span> {{description}}</p>"
|
||||||
assign:
|
assign:
|
||||||
title: "Assign"
|
title: "Assign"
|
||||||
help: "Assign Topic to User"
|
help: "Assign Topic to User"
|
||||||
|
|
67
plugin.rb
67
plugin.rb
|
@ -4,24 +4,6 @@
|
||||||
# authors: Sam Saffron
|
# authors: Sam Saffron
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
sql =<<SQL
|
|
||||||
CREATE TABLE IF NOT EXISTS assigned_users(
|
|
||||||
id SERIAL NOT NULL PRIMARY KEY,
|
|
||||||
topic_id integer NOT NULL,
|
|
||||||
assigned_to_id integer NOT NULL,
|
|
||||||
assigned_by_id integer,
|
|
||||||
created_at timestamp without time zone
|
|
||||||
)
|
|
||||||
SQL
|
|
||||||
|
|
||||||
User.exec_sql(sql)
|
|
||||||
|
|
||||||
|
|
||||||
class ::AssignedUser < ActiveRecord::Base
|
|
||||||
belongs_to :topic
|
|
||||||
belongs_to :assigned_to, class_name: 'User'
|
|
||||||
belongs_to :assigned_by, class_name: 'User'
|
|
||||||
end
|
|
||||||
|
|
||||||
module ::DiscourseAssign
|
module ::DiscourseAssign
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
|
@ -33,6 +15,10 @@ SQL
|
||||||
class ::DiscourseAssign::AssignController < Admin::AdminController
|
class ::DiscourseAssign::AssignController < Admin::AdminController
|
||||||
before_filter :ensure_logged_in
|
before_filter :ensure_logged_in
|
||||||
|
|
||||||
|
def unassign
|
||||||
|
_topic_id = params.require(:topic_id)
|
||||||
|
end
|
||||||
|
|
||||||
def assign
|
def assign
|
||||||
topic_id = params.require(:topic_id)
|
topic_id = params.require(:topic_id)
|
||||||
username = params.require(:username)
|
username = params.require(:username)
|
||||||
|
@ -42,19 +28,42 @@ SQL
|
||||||
|
|
||||||
raise Discourse::NotFound unless assign_to
|
raise Discourse::NotFound unless assign_to
|
||||||
|
|
||||||
assigned = AssignedUser.where(topic_id: topic.id).first_or_initialize
|
topic.custom_fields["assigned_to_id"] = assign_to.id
|
||||||
assigned.assigned_to_id = assign_to.id
|
topic.custom_fields["assigned_by_id"] = current_user.id
|
||||||
assigned.assigned_by_id = current_user.id
|
topic.save!
|
||||||
assigned.save!
|
|
||||||
|
|
||||||
topic.add_moderator_post(current_user,
|
#Scheduler::Defer.later "add moderator post" do
|
||||||
I18n.t('discourse_assign.assigned_to',
|
|
||||||
username: assign_to.username),
|
|
||||||
{ bump: false,
|
|
||||||
post_type: Post.types[:small_action],
|
|
||||||
action_code: "assigned"})
|
|
||||||
|
|
||||||
render json: {status: "ok"}
|
UserAction.log_action!(action_type: UserAction::ASSIGNED,
|
||||||
|
user_id: assign_to.id,
|
||||||
|
acting_user_id: current_user.id,
|
||||||
|
target_post_id: topic.posts.find_by(post_number: 1).id,
|
||||||
|
target_topic_id: topic.id)
|
||||||
|
|
||||||
|
topic.add_moderator_post(current_user,
|
||||||
|
I18n.t('discourse_assign.assigned_to',
|
||||||
|
username: assign_to.username),
|
||||||
|
{ bump: false,
|
||||||
|
post_type: Post.types[:small_action],
|
||||||
|
action_code: "assigned"})
|
||||||
|
|
||||||
|
unless false && current_user.id == assign_to.id
|
||||||
|
|
||||||
|
Notification.create!(notification_type: Notification.types[:custom],
|
||||||
|
user_id: assign_to.id,
|
||||||
|
topic_id: topic.id,
|
||||||
|
post_number: 1,
|
||||||
|
data: {
|
||||||
|
message: 'discourse_assign.assign_notification',
|
||||||
|
display_username: current_user.username,
|
||||||
|
topic_title: topic.title
|
||||||
|
}.to_json
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
#end
|
||||||
|
|
||||||
|
render json: success_json
|
||||||
end
|
end
|
||||||
|
|
||||||
DiscourseAssign::Engine.routes.draw do
|
DiscourseAssign::Engine.routes.draw do
|
||||||
|
|
Loading…
Reference in New Issue