mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-02 21:51:51 +08:00
Merge pull request #187 from ZmagoD/zd_SCI_440
add notifications generators
This commit is contained in:
commit
1aa09a2ce2
5 changed files with 62 additions and 3 deletions
|
@ -102,7 +102,10 @@ table {
|
|||
}
|
||||
|
||||
.dropdown-notifications {
|
||||
max-height: 500px;
|
||||
min-width: 450px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
padding-bottom: 0;
|
||||
padding-top: 0;
|
||||
|
||||
|
|
|
@ -211,15 +211,23 @@ class Users::SettingsController < ApplicationController
|
|||
user: @new_user_org.user,
|
||||
organization: @new_user_org.organization
|
||||
).exists? && @new_user_org.save
|
||||
AppMailer.delay.invitation_to_organization(@new_user_org.user, @user_organization.user, @new_user_org.organization)
|
||||
AppMailer.delay.invitation_to_organization(@new_user_org.user,
|
||||
@user_organization.user,
|
||||
@new_user_org.organization)
|
||||
|
||||
generate_notification(@user_organization.user,
|
||||
@new_user_org.user,
|
||||
@new_user_org.role_str,
|
||||
@new_user_org.organization)
|
||||
|
||||
flash[:notice] = I18n.t(
|
||||
"users.settings.organizations.edit.modal_add_user.existing_flash_success",
|
||||
'users.settings.organizations.edit.modal_add_user.existing_flash_success',
|
||||
user: @new_user_org.user.full_name,
|
||||
role: @new_user_org.role_str
|
||||
)
|
||||
else
|
||||
flash[:alert] =
|
||||
I18n.t("users.settings.organizations.edit.modal_add_user.existing_flash_error")
|
||||
I18n.t('users.settings.organizations.edit.modal_add_user.existing_flash_error')
|
||||
end
|
||||
|
||||
# Either way, redirect back to organization page
|
||||
|
@ -520,4 +528,21 @@ class Users::SettingsController < ApplicationController
|
|||
)
|
||||
end
|
||||
|
||||
def generate_notification(user, target_user, role, org)
|
||||
title = I18n.t('activities.assign_user_to_organization',
|
||||
assigned_user: target_user.name,
|
||||
role: role,
|
||||
organization: org.name,
|
||||
assigned_by_user: user.name)
|
||||
|
||||
message = "#{I18n.t('search.index.organization')} #{org.name}"
|
||||
notification = Notification.create(
|
||||
type_of: :assignment,
|
||||
title:
|
||||
ActionController::Base.helpers.sanitize(title),
|
||||
message:
|
||||
ActionController::Base.helpers.sanitize(message),
|
||||
)
|
||||
UserNotification.create(notification: notification, user: target_user)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Activity < ActiveRecord::Base
|
||||
after_create :generate_notification
|
||||
|
||||
enum type_of: [
|
||||
:create_project,
|
||||
:rename_project,
|
||||
|
@ -48,4 +50,31 @@ class Activity < ActiveRecord::Base
|
|||
belongs_to :project, inverse_of: :activities
|
||||
belongs_to :my_module, inverse_of: :activities
|
||||
belongs_to :user, inverse_of: :activities
|
||||
|
||||
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
|
||||
end
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-10">
|
||||
<strong><%= notification.title %></strong> <br>
|
||||
<%= l(notification.created_at, format: :full) %> | <%= notification.message %>
|
||||
|
|
|
@ -1052,6 +1052,7 @@ en:
|
|||
delete_step_comment: "<i>%{user}</i> deleted comment on Step %{step} <strong>%{step_name}</strong>."
|
||||
edit_result_comment: "<i>%{user}</i> edited comment on result <strong>%{result}</strong>."
|
||||
delete_result_comment: "<i>%{user}</i> deleted comment on result <strong>%{result}</strong>."
|
||||
assign_user_to_organization: "<i>%{assigned_user}</i> was added as %{role} to organization <strong>%{organization}</strong> by <i>%{assigned_by_user}</i>."
|
||||
|
||||
user_my_modules:
|
||||
new:
|
||||
|
|
Loading…
Reference in a new issue