2016-02-12 23:52:43 +08:00
|
|
|
class Activity < ActiveRecord::Base
|
2016-10-03 17:37:29 +08:00
|
|
|
after_create :generate_notification
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
enum type_of: [
|
|
|
|
:create_project,
|
|
|
|
:rename_project,
|
|
|
|
:change_project_visibility,
|
|
|
|
:archive_project,
|
|
|
|
:restore_project,
|
|
|
|
:assign_user_to_project,
|
|
|
|
:change_user_role_on_project,
|
|
|
|
:unassign_user_from_project,
|
|
|
|
:create_module,
|
|
|
|
:clone_module,
|
|
|
|
:archive_module,
|
|
|
|
:restore_module,
|
|
|
|
:change_module_description,
|
|
|
|
:assign_user_to_module,
|
|
|
|
:unassign_user_from_module,
|
|
|
|
:create_step,
|
|
|
|
:destroy_step,
|
|
|
|
:add_comment_to_step,
|
|
|
|
:complete_step,
|
|
|
|
:uncomplete_step,
|
|
|
|
:check_step_checklist_item,
|
|
|
|
:uncheck_step_checklist_item,
|
|
|
|
:edit_step,
|
|
|
|
:add_result,
|
|
|
|
:add_comment_to_result,
|
|
|
|
:archive_result,
|
2016-08-11 22:57:29 +08:00
|
|
|
:edit_result,
|
2016-08-16 14:49:24 +08:00
|
|
|
:clone_experiment,
|
2016-08-25 19:33:42 +08:00
|
|
|
:move_experiment,
|
|
|
|
:add_comment_to_project,
|
|
|
|
:edit_project_comment,
|
|
|
|
:delete_project_comment,
|
|
|
|
:add_comment_to_module,
|
|
|
|
:edit_module_comment,
|
|
|
|
:delete_module_comment,
|
|
|
|
:edit_step_comment,
|
|
|
|
:delete_step_comment,
|
|
|
|
:edit_result_comment,
|
2016-09-06 22:16:39 +08:00
|
|
|
:delete_result_comment,
|
|
|
|
:destroy_result
|
2016-02-12 23:52:43 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
validates :type_of, presence: true
|
|
|
|
validates :project, :user, presence: true
|
|
|
|
|
|
|
|
belongs_to :project, inverse_of: :activities
|
|
|
|
belongs_to :my_module, inverse_of: :activities
|
|
|
|
belongs_to :user, inverse_of: :activities
|
2016-10-03 17:37:29 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def generate_notification
|
|
|
|
if %w(assign_user_to_project assign_user_to_module).include? type_of
|
|
|
|
notification_type = :assignment
|
|
|
|
else
|
|
|
|
notification_type = :recent_changes
|
|
|
|
end
|
|
|
|
|
|
|
|
task_m = "| #{I18n.t('search.index.module')} #{my_module.name}" if my_module
|
|
|
|
notification = Notification.create(
|
|
|
|
type_of: notification_type,
|
|
|
|
title:
|
|
|
|
ActionController::Base.helpers.sanitize(message, tags: %w(strong a)),
|
|
|
|
message:
|
|
|
|
ActionController::Base
|
|
|
|
.helpers.sanitize(
|
|
|
|
"#{I18n.t('search.index.project')} #{project.name} #{task_m}"
|
|
|
|
),
|
|
|
|
generator_user_id: user.id
|
|
|
|
)
|
|
|
|
|
|
|
|
project.users.each do |project_user|
|
|
|
|
UserNotification.create(notification: notification, user: project_user)
|
|
|
|
end
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|