diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/boards/components/board_sidebar.js | 2 | ||||
-rw-r--r-- | app/channels/application_cable/channel.rb | 11 | ||||
-rw-r--r-- | app/channels/application_cable/connection.rb | 8 | ||||
-rw-r--r-- | app/channels/application_cable/logging.rb | 17 | ||||
-rw-r--r-- | app/controllers/concerns/known_sign_in.rb | 2 | ||||
-rw-r--r-- | app/mailers/emails/profile.rb | 11 | ||||
-rw-r--r-- | app/mailers/previews/notify_preview.rb | 2 | ||||
-rw-r--r-- | app/models/active_session.rb | 2 | ||||
-rw-r--r-- | app/services/issuable/bulk_update_service.rb | 8 | ||||
-rw-r--r-- | app/services/notification_service.rb | 4 | ||||
-rw-r--r-- | app/views/notify/unknown_sign_in_email.html.haml | 66 |
11 files changed, 110 insertions, 23 deletions
diff --git a/app/assets/javascripts/boards/components/board_sidebar.js b/app/assets/javascripts/boards/components/board_sidebar.js index c8953158811..056a7b48212 100644 --- a/app/assets/javascripts/boards/components/board_sidebar.js +++ b/app/assets/javascripts/boards/components/board_sidebar.js @@ -54,7 +54,7 @@ export default Vue.extend({ return this.issue.milestone ? this.issue.milestone.title : __('No milestone'); }, canRemove() { - return !this.list.preset; + return !this.list?.preset; }, hasLabels() { return this.issue.labels && this.issue.labels.length; diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index 9aec2305390..0de2b0185b5 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -2,5 +2,16 @@ module ApplicationCable class Channel < ActionCable::Channel::Base + include Logging + + private + + def notification_payload(_) + super.merge!(params: params.except(:channel)) + end + + def request + connection.request + end end end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 87c833f3593..1361269f2a2 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -2,8 +2,12 @@ module ApplicationCable class Connection < ActionCable::Connection::Base + include Logging + identified_by :current_user + public :request + def connect self.current_user = find_user_from_session_store end @@ -18,5 +22,9 @@ module ApplicationCable def session_id Rack::Session::SessionId.new(cookies[Gitlab::Application.config.session_options[:key]]) end + + def notification_payload(_) + super.merge!(params: request.params) + end end end diff --git a/app/channels/application_cable/logging.rb b/app/channels/application_cable/logging.rb new file mode 100644 index 00000000000..4152f8c779f --- /dev/null +++ b/app/channels/application_cable/logging.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module ApplicationCable + module Logging + private + + def notification_payload(_) + super.merge!( + Labkit::Correlation::CorrelationId::LOG_KEY => request.request_id, + user_id: current_user&.id, + username: current_user&.username, + remote_ip: request.remote_ip, + ua: request.env['HTTP_USER_AGENT'] + ) + end + end +end diff --git a/app/controllers/concerns/known_sign_in.rb b/app/controllers/concerns/known_sign_in.rb index 97883d8d08c..c0b9605de58 100644 --- a/app/controllers/concerns/known_sign_in.rb +++ b/app/controllers/concerns/known_sign_in.rb @@ -26,6 +26,6 @@ module KnownSignIn end def notify_user - current_user.notification_service.unknown_sign_in(current_user, request.remote_ip) + current_user.notification_service.unknown_sign_in(current_user, request.remote_ip, current_user.current_sign_in_at) end end diff --git a/app/mailers/emails/profile.rb b/app/mailers/emails/profile.rb index 4b19149a833..c327a0bab43 100644 --- a/app/mailers/emails/profile.rb +++ b/app/mailers/emails/profile.rb @@ -45,13 +45,20 @@ module Emails end end - def unknown_sign_in_email(user, ip) + def unknown_sign_in_email(user, ip, time) @user = user @ip = ip + @time = time @target_url = edit_profile_password_url Gitlab::I18n.with_locale(@user.preferred_language) do - mail(to: @user.notification_email, subject: subject(_("Unknown sign-in from new location"))) + mail( + to: @user.notification_email, + subject: subject(_("%{host} sign-in from new location") % { host: Gitlab.config.gitlab.host }) + ) do |format| + format.html { render layout: 'mailer' } + format.text { render layout: 'mailer' } + end end end end diff --git a/app/mailers/previews/notify_preview.rb b/app/mailers/previews/notify_preview.rb index c931b5a848f..cb7c6a36c27 100644 --- a/app/mailers/previews/notify_preview.rb +++ b/app/mailers/previews/notify_preview.rb @@ -162,7 +162,7 @@ class NotifyPreview < ActionMailer::Preview end def unknown_sign_in_email - Notify.unknown_sign_in_email(user, '127.0.0.1').message + Notify.unknown_sign_in_email(user, '127.0.0.1', Time.current).message end private diff --git a/app/models/active_session.rb b/app/models/active_session.rb index 065bd5507be..a23190cc8b3 100644 --- a/app/models/active_session.rb +++ b/app/models/active_session.rb @@ -36,7 +36,7 @@ class ActiveSession timestamp = Time.current active_user_session = new( - ip_address: request.ip, + ip_address: request.remote_ip, browser: client.name, os: client.os_name, device_name: client.device_name, diff --git a/app/services/issuable/bulk_update_service.rb b/app/services/issuable/bulk_update_service.rb index 2cd0e1e992d..1518b697f86 100644 --- a/app/services/issuable/bulk_update_service.rb +++ b/app/services/issuable/bulk_update_service.rb @@ -40,9 +40,13 @@ module Issuable private def permitted_attrs(type) - attrs = %i(state_event milestone_id assignee_id assignee_ids add_label_ids remove_label_ids subscription_event) + attrs = %i(state_event milestone_id add_label_ids remove_label_ids subscription_event) - if type == 'issue' + issuable_specific_attrs(type, attrs) + end + + def issuable_specific_attrs(type, attrs) + if type == 'issue' || type == 'merge_request' attrs.push(:assignee_ids) else attrs.push(:assignee_id) diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index ae512563585..66f83d5c127 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -68,10 +68,10 @@ class NotificationService # Notify a user when a previously unknown IP or device is used to # sign in to their account - def unknown_sign_in(user, ip) + def unknown_sign_in(user, ip, time) return unless user.can?(:receive_notifications) - mailer.unknown_sign_in_email(user, ip).deliver_later + mailer.unknown_sign_in_email(user, ip, time).deliver_later end # When create an issue we should send an email to: diff --git a/app/views/notify/unknown_sign_in_email.html.haml b/app/views/notify/unknown_sign_in_email.html.haml index a4123fada1b..914242da5c6 100644 --- a/app/views/notify/unknown_sign_in_email.html.haml +++ b/app/views/notify/unknown_sign_in_email.html.haml @@ -1,14 +1,54 @@ -%p - = _('Hi %{username}!') % { username: sanitize_name(@user.name) } -%p - = _('A sign-in to your account has been made from the following IP address: %{ip}.') % { ip: @ip } -%p - - password_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: 'https://docs.gitlab.com/ee/user/profile/#changing-your-password' } - = _('If you recently signed in and recognize the IP address, you may disregard this email.') - = _('If you did not recently sign in, you should immediately %{password_link_start}change your password%{password_link_end}.').html_safe % { password_link_start: password_link_start, password_link_end: '</a>'.html_safe } - = _('Passwords should be unique and not used for any other sites or services.') +- default_font = "font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;" +- default_style = "#{default_font}font-size:15px;line-height:1.4;color:#8c8c8c;font-weight:300;padding:14px 0;margin:0;" +- spacer_style = "#{default_font};height:18px;font-size:18px;line-height:18px;" -- unless @user.two_factor_enabled? - %p - - mfa_link_start = '<a href="https://docs.gitlab.com/ee/user/profile/account/two_factor_authentication.html" target="_blank">'.html_safe - = _('To further protect your account, consider configuring a %{mfa_link_start}two-factor authentication%{mfa_link_end} method.').html_safe % { mfa_link_start: mfa_link_start, mfa_link_end: '</a>'.html_safe } +%tr.alert + %td{ style: "#{default_font}padding:10px;border-radius:3px;font-size:14px;line-height:1.3;text-align:center;overflow:hidden;color:#ffffff;background-color:#FC6D26;" } + %table.img{ border: "0", cellpadding: "0", cellspacing: "0", style: "border-collapse:collapse;margin:0 auto;" } + %tbody + %tr + %td{ style: "#{default_font}vertical-align:middle;color:#ffffff;text-align:center;" } + %span + = _("Your %{host} account was signed in to from a new location") % { host: Gitlab.config.gitlab.host } +%tr.spacer + %td{ style: spacer_style } + +%tr.section + %td{ style: "#{default_font};padding:0 15px;border:1px solid #ededed;border-radius:3px;overflow:hidden;" } + %table.info{ border: "0", cellpadding: "0", cellspacing: "0", style: "width:100%;" } + %tbody + %tr + %td{ style: default_style } + = _('Hostname') + %td{ style: "#{default_style}color:#333333;font-weight:400;width:75%;padding-left:5px;" } + = Gitlab.config.gitlab.host + %tr + %td{ style: "#{default_style}border-top:1px solid #ededed;" } + = _('IP Address') + %td{ style: "#{default_style}color:#333333;font-weight:400;width:75%;padding-left:5px;border-top:1px solid #ededed;" } + %span.muted{ style: "color:#333333;text-decoration:none;" } + = @ip + %tr + %td{ style: "#{default_style}border-top:1px solid #ededed;" } + = _('Time') + %td{ style: "#{default_style}color:#333333;font-weight:400;width:75%;padding-left:5px;border-top:1px solid #ededed;" } + = @time.strftime('%Y-%m-%d %l:%M:%S %p %Z') +%tr.spacer + %td{ style: spacer_style } + +%tr.section + %td{ style: "#{default_font};line-height:1.4;text-align:center;padding:0 15px;overflow:hidden;" } + %table.img{ border: "0", cellpadding: "0", cellspacing: "0", style: "border-collapse:collapse;width:100%;" } + %tbody + %tr{ style: 'width:100%;' } + %td{ style: "#{default_style}text-align:center;" } + - password_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: 'https://docs.gitlab.com/ee/user/profile/#changing-your-password' } + = _('If you recently signed in and recognize the IP address, you may disregard this email.') + %p + = _('If you did not recently sign in, you should immediately %{password_link_start}change your password%{password_link_end}.').html_safe % { password_link_start: password_link_start, password_link_end: '</a>'.html_safe } + = _('Passwords should be unique and not used for any other sites or services.') + + - unless @user.two_factor_enabled? + %p + - mfa_link_start = '<a href="https://docs.gitlab.com/ee/user/profile/account/two_factor_authentication.html" target="_blank">'.html_safe + = _('To further protect your account, consider configuring a %{mfa_link_start}two-factor authentication%{mfa_link_end} method.').html_safe % { mfa_link_start: mfa_link_start, mfa_link_end: '</a>'.html_safe } |