From ea17182372526bab9dc1d30af854ecc7cb7cc10b Mon Sep 17 00:00:00 2001 From: zmagod Date: Mon, 3 Oct 2016 11:37:29 +0200 Subject: [PATCH 1/2] generate notifications [fixes SCI-440] --- app/assets/stylesheets/themes/scinote.scss | 5 ++- app/controllers/users/settings_controller.rb | 31 +++++++++++++++++-- app/models/activity.rb | 29 +++++++++++++++++ .../_recent_notifications.html.erb | 2 +- config/locales/en.yml | 1 + 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 7bb363f70..34e7e92fe 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -101,7 +101,10 @@ table { } .dropdown-notifications { + max-height: 500px; min-width: 450px; + overflow-x: hidden; + overflow-y: scroll; padding-bottom: 0; padding-top: 0; @@ -116,7 +119,7 @@ table { } .assignment { - + } .notifications-dropdown-header { diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 95c3a1fb5..39655fbb6 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -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 diff --git a/app/models/activity.rb b/app/models/activity.rb index bc2c91212..6cd65c165 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -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 diff --git a/app/views/user_notifications/_recent_notifications.html.erb b/app/views/user_notifications/_recent_notifications.html.erb index ed57ce053..5cbef6c7c 100644 --- a/app/views/user_notifications/_recent_notifications.html.erb +++ b/app/views/user_notifications/_recent_notifications.html.erb @@ -14,7 +14,7 @@ <% end %>
- <%= notification.title %>
+ <%= notification.title.html_safe %>
<%= l(notification.created_at, format: :full) %> | <%= notification.message %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 07108175b..cb091ba2d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1052,6 +1052,7 @@ en: delete_step_comment: "%{user} deleted comment on Step %{step} %{step_name}." edit_result_comment: "%{user} edited comment on result %{result}." delete_result_comment: "%{user} deleted comment on result %{result}." + assign_user_to_organization: "%{assigned_user} was added as %{role} to organization %{organization} by %{assigned_by_user}." user_my_modules: new: From 947096862d18ddecdde09936521b059fd0949a68 Mon Sep 17 00:00:00 2001 From: zmagod Date: Mon, 3 Oct 2016 11:40:59 +0200 Subject: [PATCH 2/2] fixed hound --- app/controllers/users/settings_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 39655fbb6..a432a5341 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -530,10 +530,10 @@ class Users::SettingsController < ApplicationController 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) + 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(