From 31b0e53015e38e51d9c02cca85c9279600b1bf85 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 28 Mar 2016 13:41:00 +0200 Subject: Introduce NotificationSetting model It will hold notification setting per group or per project. It will allow get rid of notification level stored in Member model Signed-off-by: Dmitriy Zaporozhets --- app/models/notification_setting.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app/models/notification_setting.rb (limited to 'app') diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb new file mode 100644 index 00000000000..0dce146b7a9 --- /dev/null +++ b/app/models/notification_setting.rb @@ -0,0 +1,14 @@ +class NotificationSetting < ActiveRecord::Base + belongs_to :user + belongs_to :source, polymorphic: true + + validates :user, presence: true + validates :source, presence: true + validates :level, presence: true + validates :user_id, uniqueness: { scope: [:source_type, :source_id], + message: "already exists in source", + allow_nil: true } + # Notification level + # Note: When adding an option, it MUST go on the end of the array. + enum level: [:disabled, :participating, :watch, :global, :mention] +end -- cgit v1.2.1 From 359157c097993a9b917ca590e128e85cf358d95d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 28 Mar 2016 18:17:42 +0200 Subject: Introduce NotificationSetting to user interface * visiting project will create notification setting if missing * change notification setting per project even without membership * use notification settings instead of membership on profile page Signed-off-by: Dmitriy Zaporozhets --- app/assets/javascripts/project.js.coffee | 8 +-- .../profiles/notifications_controller.rb | 14 ++-- app/controllers/projects_controller.rb | 17 +++-- app/helpers/notifications_helper.rb | 74 +++++++++++++--------- app/models/notification.rb | 4 +- app/models/notification_setting.rb | 7 ++ app/models/user.rb | 7 +- .../profiles/notifications/_settings.html.haml | 18 +++--- app/views/profiles/notifications/show.html.haml | 30 ++++----- .../projects/buttons/_notifications.html.haml | 20 ++---- 10 files changed, 106 insertions(+), 93 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/project.js.coffee b/app/assets/javascripts/project.js.coffee index 87d313ed67c..f171442d05a 100644 --- a/app/assets/javascripts/project.js.coffee +++ b/app/assets/javascripts/project.js.coffee @@ -37,15 +37,9 @@ class @Project $('.update-notification').on 'click', (e) -> e.preventDefault() notification_level = $(@).data 'notification-level' + label = $(@).data 'notification-title' $('#notification_level').val(notification_level) $('#notification-form').submit() - label = null - switch notification_level - when 0 then label = ' Disabled ' - when 1 then label = ' Participating ' - when 2 then label = ' Watching ' - when 3 then label = ' Global ' - when 4 then label = ' On Mention ' $('#notifications-button').empty().append("" + label + "") $(@).parents('ul').find('li.active').removeClass 'active' $(@).parent().addClass 'active' diff --git a/app/controllers/profiles/notifications_controller.rb b/app/controllers/profiles/notifications_controller.rb index 1fd1d6882df..6ca7537300f 100644 --- a/app/controllers/profiles/notifications_controller.rb +++ b/app/controllers/profiles/notifications_controller.rb @@ -2,8 +2,8 @@ class Profiles::NotificationsController < Profiles::ApplicationController def show @user = current_user @notification = current_user.notification - @project_members = current_user.project_members - @group_members = current_user.group_members + @group_notifications = current_user.notification_settings.for_groups + @project_notifications = current_user.notification_settings.for_projects end def update @@ -11,14 +11,10 @@ class Profiles::NotificationsController < Profiles::ApplicationController @saved = if type == 'global' current_user.update_attributes(user_params) - elsif type == 'group' - group_member = current_user.group_members.find(params[:notification_id]) - group_member.notification_level = params[:notification_level] - group_member.save else - project_member = current_user.project_members.find(params[:notification_id]) - project_member.notification_level = params[:notification_level] - project_member.save + notification_setting = current_user.notification_settings.find(params[:notification_id]) + notification_setting.level = params[:notification_level] + notification_setting.save end respond_to do |format| diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 928817ba811..77122f59128 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -98,14 +98,23 @@ class ProjectsController < Projects::ApplicationController respond_to do |format| format.html do + if current_user + @membership = @project.team.find_member(current_user.id) + + if @membership + @notification_setting = current_user.notification_settings.find_or_initialize_by(source: @project) + + unless @notification_setting.persisted? + @notification_setting.set_defaults + @notification_setting.save + end + end + end + if @project.repository_exists? if @project.empty_repo? render 'projects/empty' else - if current_user - @membership = @project.team.find_member(current_user.id) - end - render :show end else diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 499c655d2bf..a0e91a63d2d 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -1,48 +1,60 @@ module NotificationsHelper include IconsHelper - def notification_icon(notification) - if notification.disabled? - icon('volume-off', class: 'ns-mute') - elsif notification.participating? - icon('volume-down', class: 'ns-part') - elsif notification.watch? - icon('volume-up', class: 'ns-watch') - else - icon('circle-o', class: 'ns-default') + def notification_icon_class(level) + case level.to_sym + when :disabled + 'microphone-slash' + when :participating + 'volume-up' + when :watch + 'eye' + when :mention + 'at' + when :global + 'globe' end end - def notification_list_item(notification_level, user_membership) - case notification_level - when Notification::N_DISABLED - update_notification_link(Notification::N_DISABLED, user_membership, 'Disabled', 'microphone-slash') - when Notification::N_PARTICIPATING - update_notification_link(Notification::N_PARTICIPATING, user_membership, 'Participate', 'volume-up') - when Notification::N_WATCH - update_notification_link(Notification::N_WATCH, user_membership, 'Watch', 'eye') - when Notification::N_MENTION - update_notification_link(Notification::N_MENTION, user_membership, 'On mention', 'at') - when Notification::N_GLOBAL - update_notification_link(Notification::N_GLOBAL, user_membership, 'Global', 'globe') - else - # do nothing + def notification_icon(level) + icon("#{notification_icon_class(level)} fw") + end + + def notification_title(level) + case level.to_sym + when :disabled + 'Disabled' + when :participating + 'Participate' + when :watch + 'Watch' + when :mention + 'On mention' + when :global + 'Global' end end - def update_notification_link(notification_level, user_membership, title, icon) - content_tag(:li, class: active_level_for(user_membership, notification_level)) do - link_to '#', class: 'update-notification', data: { notification_level: notification_level } do - icon("#{icon} fw", text: title) + def notification_list_item(level, setting) + title = notification_title(level) + + data = { + notification_level: level, + notification_title: title + } + + content_tag(:li, class: active_level_for(setting, level)) do + link_to '#', class: 'update-notification', data: data do + icon("#{notification_icon_class(level)} fw", text: title) end end end - def notification_label(user_membership) - Notification.new(user_membership).to_s + def notification_label(setting) + notification_title(setting.level) end - def active_level_for(user_membership, level) - 'active' if user_membership.notification_level == level + def active_level_for(setting, level) + 'active' if setting.level == level end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 171b8df45c2..379f041969b 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -57,7 +57,7 @@ class Notification def level target.notification_level end - + def to_s case level when N_DISABLED @@ -71,7 +71,7 @@ class Notification when N_GLOBAL 'Global' else - # do nothing + # do nothing end end end diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb index 0dce146b7a9..287862a01bc 100644 --- a/app/models/notification_setting.rb +++ b/app/models/notification_setting.rb @@ -11,4 +11,11 @@ class NotificationSetting < ActiveRecord::Base # Notification level # Note: When adding an option, it MUST go on the end of the array. enum level: [:disabled, :participating, :watch, :global, :mention] + + scope :for_groups, -> { where(source_type: 'Namespace') } + scope :for_projects, -> { where(source_type: 'Project') } + + def set_defaults + self.level = :global + end end diff --git a/app/models/user.rb b/app/models/user.rb index 128ddc2a694..59493e6f90c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -143,6 +143,7 @@ class User < ActiveRecord::Base has_many :spam_logs, dependent: :destroy has_many :builds, dependent: :nullify, class_name: 'Ci::Build' has_many :todos, dependent: :destroy + has_many :notification_settings, dependent: :destroy # # Validations @@ -157,7 +158,7 @@ class User < ActiveRecord::Base presence: true, uniqueness: { case_sensitive: false } - validates :notification_level, inclusion: { in: Notification.notification_levels }, presence: true + validates :notification_level, presence: true validate :namespace_uniq, if: ->(user) { user.username_changed? } validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? } validate :unique_email, if: ->(user) { user.email_changed? } @@ -190,6 +191,10 @@ class User < ActiveRecord::Base # Note: When adding an option, it MUST go on the end of the array. enum project_view: [:readme, :activity, :files] + # Notification level + # Note: When adding an option, it MUST go on the end of the array. + enum notification_level: [:disabled, :participating, :watch, :global, :mention] + alias_attribute :private_token, :authentication_token delegate :path, to: :namespace, allow_nil: true, prefix: true diff --git a/app/views/profiles/notifications/_settings.html.haml b/app/views/profiles/notifications/_settings.html.haml index d0d044136f6..c32de0b9925 100644 --- a/app/views/profiles/notifications/_settings.html.haml +++ b/app/views/profiles/notifications/_settings.html.haml @@ -1,17 +1,17 @@ %li.notification-list-item %span.notification.fa.fa-holder.append-right-5 - - if notification.global? - = notification_icon(@notification) + - if setting.global? + = notification_icon(current_user.notification_level) - else - = notification_icon(notification) + = notification_icon(setting.level) %span.str-truncated - - if membership.kind_of? GroupMember - = link_to membership.group.name, membership.group + - if setting.source.kind_of? Project + = link_to_project(setting.source) - else - = link_to_project(membership.project) + = link_to setting.source.name, group_path(setting.source) .pull-right = form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do - = hidden_field_tag :notification_type, type, id: dom_id(membership, 'notification_type') - = hidden_field_tag :notification_id, membership.id, id: dom_id(membership, 'notification_id') - = select_tag :notification_level, options_for_select(Notification.options_with_labels, notification.level), class: 'form-control trigger-submit' + = hidden_field_tag :notification_id, setting.id + = hidden_field_tag :notification_level, setting.level + = select_tag :notification_level, options_for_select(User.notification_levels.keys, setting.level), class: 'form-control trigger-submit' diff --git a/app/views/profiles/notifications/show.html.haml b/app/views/profiles/notifications/show.html.haml index de80abd7f4d..f6900f61b2d 100644 --- a/app/views/profiles/notifications/show.html.haml +++ b/app/views/profiles/notifications/show.html.haml @@ -26,29 +26,29 @@ .form-group = f.label :notification_level, class: 'label-light' .radio - = f.label :notification_level, value: Notification::N_DISABLED do - = f.radio_button :notification_level, Notification::N_DISABLED + = f.label :notification_level, value: :disabled do + = f.radio_button :notification_level, :disabled .level-title Disabled %p You will not get any notifications via email .radio - = f.label :notification_level, value: Notification::N_MENTION do - = f.radio_button :notification_level, Notification::N_MENTION + = f.label :notification_level, value: :mention do + = f.radio_button :notification_level, :mention .level-title On Mention %p You will receive notifications only for comments in which you were @mentioned .radio - = f.label :notification_level, value: Notification::N_PARTICIPATING do - = f.radio_button :notification_level, Notification::N_PARTICIPATING + = f.label :notification_level, value: :participating do + = f.radio_button :notification_level, :participating .level-title Participating %p You will only receive notifications from related resources (e.g. from your commits or assigned issues) .radio - = f.label :notification_level, value: Notification::N_WATCH do - = f.radio_button :notification_level, Notification::N_WATCH + = f.label :notification_level, value: :watch do + = f.radio_button :notification_level, :watch .level-title Watch %p You will receive notifications for any activity @@ -57,18 +57,16 @@ = f.submit 'Update settings', class: "btn btn-create" %hr %h5 - Groups (#{@group_members.count}) + Groups (#{@group_notifications.count}) %div %ul.bordered-list - - @group_members.each do |group_member| - - notification = Notification.new(group_member) - = render 'settings', type: 'group', membership: group_member, notification: notification + - @group_notifications.each do |setting| + = render 'settings', setting: setting %h5 - Projects (#{@project_members.count}) + Projects (#{@project_notifications.count}) %p.account-well To specify the notification level per project of a group you belong to, you need to be a member of the project itself, not only its group. .append-bottom-default %ul.bordered-list - - @project_members.each do |project_member| - - notification = Notification.new(project_member) - = render 'settings', type: 'project', membership: project_member, notification: notification + - @project_notifications.each do |setting| + = render 'settings', setting: setting diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index a3786c35a1f..4b8a10f0819 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -1,20 +1,12 @@ -- case @membership -- when ProjectMember +- if @notification_setting = form_tag profile_notifications_path, method: :put, remote: true, class: 'inline', id: 'notification-form' do - = hidden_field_tag :notification_type, 'project' - = hidden_field_tag :notification_id, @membership.id - = hidden_field_tag :notification_level + = hidden_field_tag :notification_id, @notification_setting.id + = hidden_field_tag :notification_level, @notification_setting.level %span.dropdown %a.dropdown-new.btn.notifications-btn#notifications-button{href: '#', "data-toggle" => "dropdown"} = icon('bell') - = notification_label(@membership) + = notification_title(@notification_setting.level) = icon('angle-down') %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown - - Notification.project_notification_levels.each do |level| - = notification_list_item(level, @membership) - -- when GroupMember - .btn.disabled.notifications-btn.has-tooltip{title: "To change the notification level, you need to be a member of the project itself, not only its group."} - = icon('bell') - = notification_label(@membership) - = icon('angle-down') + - NotificationSetting.levels.each do |level| + = notification_list_item(level.first, @notification_setting) -- cgit v1.2.1 From 7ea1bcab45697556d4ffd79ab680872ed823d4a3 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 28 Mar 2016 18:25:57 +0200 Subject: Create notification setting when membership created Signed-off-by: Dmitriy Zaporozhets --- app/models/member.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app') diff --git a/app/models/member.rb b/app/models/member.rb index ca08007b7eb..177f37c3bbd 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -56,6 +56,7 @@ class Member < ActiveRecord::Base before_validation :generate_invite_token, on: :create, if: -> (member) { member.invite_email.present? } after_create :send_invite, if: :invite? + after_create :create_notification_setting, unless: :invite? after_create :post_create_hook, unless: :invite? after_update :post_update_hook, unless: :invite? after_destroy :post_destroy_hook, unless: :invite? @@ -160,6 +161,15 @@ class Member < ActiveRecord::Base send_invite end + def create_notification_setting + notification_setting = user.notification_settings.find_or_initialize_by(source: source) + + unless notification_setting.persisted? + notification_setting.set_defaults + notification_setting.save + end + end + private def send_invite -- cgit v1.2.1 From b8f38437900cdddac9d19d5c48a2a8e5bb037f41 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 28 Mar 2016 20:31:36 +0200 Subject: Update NotificationService to use NotificationSettings instead of membership Signed-off-by: Dmitriy Zaporozhets --- app/models/concerns/notifiable.rb | 15 --------------- app/models/group.rb | 1 + app/models/member.rb | 5 ++++- app/models/notification.rb | 22 ++-------------------- app/models/project.rb | 1 + app/models/user.rb | 3 +++ app/services/notification_service.rb | 34 ++++++++++++++++------------------ 7 files changed, 27 insertions(+), 54 deletions(-) delete mode 100644 app/models/concerns/notifiable.rb (limited to 'app') diff --git a/app/models/concerns/notifiable.rb b/app/models/concerns/notifiable.rb deleted file mode 100644 index d7dcd97911d..00000000000 --- a/app/models/concerns/notifiable.rb +++ /dev/null @@ -1,15 +0,0 @@ -# == Notifiable concern -# -# Contains notification functionality -# -module Notifiable - extend ActiveSupport::Concern - - included do - validates :notification_level, inclusion: { in: Notification.project_notification_levels }, presence: true - end - - def notification - @notification ||= Notification.new(self) - end -end diff --git a/app/models/group.rb b/app/models/group.rb index b332601c59b..9a04ac70d35 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -27,6 +27,7 @@ class Group < Namespace has_many :users, through: :group_members has_many :project_group_links, dependent: :destroy has_many :shared_projects, through: :project_group_links, source: :project + has_many :notification_settings, dependent: :destroy, as: :source validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? } validate :visibility_level_allowed_by_projects diff --git a/app/models/member.rb b/app/models/member.rb index 177f37c3bbd..e665ba6fb75 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -19,7 +19,6 @@ class Member < ActiveRecord::Base include Sortable - include Notifiable include Gitlab::Access attr_accessor :raw_invite_token @@ -170,6 +169,10 @@ class Member < ActiveRecord::Base end end + def notification + @notification ||= user.notification_settings.find_by(source: source) + end + private def send_invite diff --git a/app/models/notification.rb b/app/models/notification.rb index 379f041969b..8a90b456cc2 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -30,30 +30,12 @@ class Notification end end + delegate :disabled?, :participating?, :watch?, :global?, :mention?, to: :target + def initialize(target) @target = target end - def disabled? - target.notification_level == N_DISABLED - end - - def participating? - target.notification_level == N_PARTICIPATING - end - - def watch? - target.notification_level == N_WATCH - end - - def global? - target.notification_level == N_GLOBAL - end - - def mention? - target.notification_level == N_MENTION - end - def level target.notification_level end diff --git a/app/models/project.rb b/app/models/project.rb index 2285063ab50..2f9621809b6 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -154,6 +154,7 @@ class Project < ActiveRecord::Base has_many :project_group_links, dependent: :destroy has_many :invited_groups, through: :project_group_links, source: :group has_many :todos, dependent: :destroy + has_many :notification_settings, dependent: :destroy, as: :source has_one :import_data, dependent: :destroy, class_name: "ProjectImportData" diff --git a/app/models/user.rb b/app/models/user.rb index 59493e6f90c..f556dc5903d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -193,6 +193,9 @@ class User < ActiveRecord::Base # Notification level # Note: When adding an option, it MUST go on the end of the array. + # + # TODO: Add '_prefix: :notification' to enum when update to Rails 5. https://github.com/rails/rails/pull/19813 + # Because user.notification_disabled? is much better than user.disabled? enum notification_level: [:disabled, :participating, :watch, :global, :mention] alias_attribute :private_token, :authentication_token diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index eff0d96f93d..9628843c230 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -253,8 +253,8 @@ class NotificationService def project_watchers(project) project_members = project_member_notification(project) - users_with_project_level_global = project_member_notification(project, Notification::N_GLOBAL) - users_with_group_level_global = group_member_notification(project, Notification::N_GLOBAL) + users_with_project_level_global = project_member_notification(project, :global) + users_with_group_level_global = group_member_notification(project, :global) users = users_with_global_level_watch([users_with_project_level_global, users_with_group_level_global].flatten.uniq) users_with_project_setting = select_project_member_setting(project, users_with_project_level_global, users) @@ -264,18 +264,16 @@ class NotificationService end def project_member_notification(project, notification_level=nil) - project_members = project.project_members - if notification_level - project_members.where(notification_level: notification_level).pluck(:user_id) + project.notification_settings.where(level: NotificationSetting.levels[notification_level]).pluck(:user_id) else - project_members.pluck(:user_id) + project.notification_settings.pluck(:user_id) end end def group_member_notification(project, notification_level) if project.group - project.group.group_members.where(notification_level: notification_level).pluck(:user_id) + project.group.notification_settings.where(level: NotificationSetting.levels[notification_level]).pluck(:user_id) else [] end @@ -284,13 +282,13 @@ class NotificationService def users_with_global_level_watch(ids) User.where( id: ids, - notification_level: Notification::N_WATCH + notification_level: NotificationSetting.levels[:watch] ).pluck(:id) end # Build a list of users based on project notifcation settings def select_project_member_setting(project, global_setting, users_global_level_watch) - users = project_member_notification(project, Notification::N_WATCH) + users = project_member_notification(project, :watch) # If project setting is global, add to watch list if global setting is watch global_setting.each do |user_id| @@ -304,7 +302,7 @@ class NotificationService # Build a list of users based on group notification settings def select_group_member_setting(project, project_members, global_setting, users_global_level_watch) - uids = group_member_notification(project, Notification::N_WATCH) + uids = group_member_notification(project, :watch) # Group setting is watch, add to users list if user is not project member users = [] @@ -351,20 +349,20 @@ class NotificationService users.reject do |user| next user.notification.send(method_name) unless project - member = project.project_members.find_by(user_id: user.id) + setting = user.notification_settings.find_by(source: project) - if !member && project.group - member = project.group.group_members.find_by(user_id: user.id) + if !setting && project.group + setting = user.notification_settings.find_by(source: group) end - # reject users who globally set mention notification and has no membership - next user.notification.send(method_name) unless member + # reject users who globally set mention notification and has no setting per project/group + next user.notification.send(method_name) unless setting # reject users who set mention notification in project - next true if member.notification.send(method_name) + next true if setting.send(method_name) - # reject users who have N_MENTION in project and disabled in global settings - member.notification.global? && user.notification.send(method_name) + # reject users who have mention level in project and disabled in global settings + setting.global? && user.notification.send(method_name) end end -- cgit v1.2.1 From 4ca73f56cb59b86f25b55ff02800571fb82c742f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 28 Mar 2016 23:22:28 +0200 Subject: Small refactoring and cleanup of notification logic Signed-off-by: Dmitriy Zaporozhets --- app/helpers/notifications_helper.rb | 12 ++-------- app/models/member.rb | 2 ++ app/models/members/group_member.rb | 1 - app/models/members/project_member.rb | 1 - app/models/notification.rb | 46 ------------------------------------ 5 files changed, 4 insertions(+), 58 deletions(-) (limited to 'app') diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index a0e91a63d2d..8816cc5d164 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -22,16 +22,12 @@ module NotificationsHelper def notification_title(level) case level.to_sym - when :disabled - 'Disabled' when :participating 'Participate' - when :watch - 'Watch' when :mention 'On mention' - when :global - 'Global' + else + level.to_s.titlecase end end @@ -50,10 +46,6 @@ module NotificationsHelper end end - def notification_label(setting) - notification_title(setting.level) - end - def active_level_for(setting, level) 'active' if setting.level == level end diff --git a/app/models/member.rb b/app/models/member.rb index e665ba6fb75..799f28c3fdf 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -62,6 +62,8 @@ class Member < ActiveRecord::Base delegate :name, :username, :email, to: :user, prefix: true + default_value_for :notification_level, NotificationSetting.levels[:global] + class << self def find_by_invite_token(invite_token) invite_token = Devise.token_generator.digest(self, :invite_token, invite_token) diff --git a/app/models/members/group_member.rb b/app/models/members/group_member.rb index 65d2ea00570..9fb474a1a93 100644 --- a/app/models/members/group_member.rb +++ b/app/models/members/group_member.rb @@ -24,7 +24,6 @@ class GroupMember < Member # Make sure group member points only to group as it source default_value_for :source_type, SOURCE_TYPE - default_value_for :notification_level, Notification::N_GLOBAL validates_format_of :source_type, with: /\ANamespace\z/ default_scope { where(source_type: SOURCE_TYPE) } diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 560d1690e14..07ddb02ae9d 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -27,7 +27,6 @@ class ProjectMember < Member # Make sure project member points only to project as it source default_value_for :source_type, SOURCE_TYPE - default_value_for :notification_level, Notification::N_GLOBAL validates_format_of :source_type, with: /\AProject\z/ default_scope { where(source_type: SOURCE_TYPE) } diff --git a/app/models/notification.rb b/app/models/notification.rb index 8a90b456cc2..3805bde88b0 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,35 +1,6 @@ class Notification - # - # Notification levels - # - N_DISABLED = 0 - N_PARTICIPATING = 1 - N_WATCH = 2 - N_GLOBAL = 3 - N_MENTION = 4 - attr_accessor :target - class << self - def notification_levels - [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH] - end - - def options_with_labels - { - disabled: N_DISABLED, - participating: N_PARTICIPATING, - watch: N_WATCH, - mention: N_MENTION, - global: N_GLOBAL - } - end - - def project_notification_levels - [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH, N_GLOBAL] - end - end - delegate :disabled?, :participating?, :watch?, :global?, :mention?, to: :target def initialize(target) @@ -39,21 +10,4 @@ class Notification def level target.notification_level end - - def to_s - case level - when N_DISABLED - 'Disabled' - when N_PARTICIPATING - 'Participating' - when N_WATCH - 'Watching' - when N_MENTION - 'On mention' - when N_GLOBAL - 'Global' - else - # do nothing - end - end end -- cgit v1.2.1 From 08b3d7f6ef23b7a8a83c7e71e2d04f6416e73406 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 29 Mar 2016 13:08:30 +0200 Subject: Refactor notification helper and fix notification service Signed-off-by: Dmitriy Zaporozhets --- app/helpers/notifications_helper.rb | 12 ++++-------- app/services/notification_service.rb | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 8816cc5d164..54ab9179efc 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -16,8 +16,8 @@ module NotificationsHelper end end - def notification_icon(level) - icon("#{notification_icon_class(level)} fw") + def notification_icon(level, text = nil) + icon("#{notification_icon_class(level)} fw", text: text) end def notification_title(level) @@ -39,14 +39,10 @@ module NotificationsHelper notification_title: title } - content_tag(:li, class: active_level_for(setting, level)) do + content_tag(:li, class: ('active' if setting.level == level)) do link_to '#', class: 'update-notification', data: data do - icon("#{notification_icon_class(level)} fw", text: title) + notification_icon(level, title) end end end - - def active_level_for(setting, level) - 'active' if setting.level == level - end end diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 9628843c230..23f211dfcd2 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -352,7 +352,7 @@ class NotificationService setting = user.notification_settings.find_by(source: project) if !setting && project.group - setting = user.notification_settings.find_by(source: group) + setting = user.notification_settings.find_by(source: project.group) end # reject users who globally set mention notification and has no setting per project/group -- cgit v1.2.1 From 86418c475be1b2a37e89682bc87055b7372bbcfb Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 29 Mar 2016 13:37:43 +0200 Subject: Remove useless Notification model Signed-off-by: Dmitriy Zaporozhets --- app/models/member.rb | 4 ++-- app/models/notification.rb | 13 ------------- app/models/user.rb | 4 ---- app/services/notification_service.rb | 24 +++++++++++++++--------- 4 files changed, 17 insertions(+), 28 deletions(-) delete mode 100644 app/models/notification.rb (limited to 'app') diff --git a/app/models/member.rb b/app/models/member.rb index 799f28c3fdf..cbcc54c0250 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -171,8 +171,8 @@ class Member < ActiveRecord::Base end end - def notification - @notification ||= user.notification_settings.find_by(source: source) + def notification_setting + @notification_setting ||= user.notification_settings.find_by(source: source) end private diff --git a/app/models/notification.rb b/app/models/notification.rb deleted file mode 100644 index 3805bde88b0..00000000000 --- a/app/models/notification.rb +++ /dev/null @@ -1,13 +0,0 @@ -class Notification - attr_accessor :target - - delegate :disabled?, :participating?, :watch?, :global?, :mention?, to: :target - - def initialize(target) - @target = target - end - - def level - target.notification_level - end -end diff --git a/app/models/user.rb b/app/models/user.rb index f556dc5903d..af6b86bfa70 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -357,10 +357,6 @@ class User < ActiveRecord::Base "#{self.class.reference_prefix}#{username}" end - def notification - @notification ||= Notification.new(self) - end - def generate_password if self.force_random_password self.password = self.password_confirmation = Devise.friendly_token.first(8) diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 23f211dfcd2..0928dda349e 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -329,25 +329,31 @@ class NotificationService # Remove users with disabled notifications from array # Also remove duplications and nil recipients def reject_muted_users(users, project = nil) - reject_users(users, :disabled?, project) + reject_users(users, :disabled, project) end # Remove users with notification level 'Mentioned' def reject_mention_users(users, project = nil) - reject_users(users, :mention?, project) + reject_users(users, :mention, project) end - # Reject users which method_name from notification object returns true. + # Reject users which has certain notification level # # Example: - # reject_users(users, :watch?, project) + # reject_users(users, :watch, project) # - def reject_users(users, method_name, project = nil) + def reject_users(users, level, project = nil) + level = level.to_s + + unless NotificationSetting.levels.keys.include?(level) + raise 'Invalid notification level' + end + users = users.to_a.compact.uniq users = users.reject(&:blocked?) users.reject do |user| - next user.notification.send(method_name) unless project + next user.notification_level == level unless project setting = user.notification_settings.find_by(source: project) @@ -356,13 +362,13 @@ class NotificationService end # reject users who globally set mention notification and has no setting per project/group - next user.notification.send(method_name) unless setting + next user.notification_level == level unless setting # reject users who set mention notification in project - next true if setting.send(method_name) + next true if setting.level == level # reject users who have mention level in project and disabled in global settings - setting.global? && user.notification.send(method_name) + setting.global? && user.notification_level == level end end -- cgit v1.2.1 From 71e7b398431506c8bac2e8e6014b0f3891a41f95 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 29 Mar 2016 13:52:42 +0200 Subject: Refactor creating notification setting with defaults Signed-off-by: Dmitriy Zaporozhets --- app/controllers/projects_controller.rb | 7 +------ app/models/member.rb | 7 +------ app/models/notification_setting.rb | 11 +++++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 77122f59128..e2dc6309d26 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -102,12 +102,7 @@ class ProjectsController < Projects::ApplicationController @membership = @project.team.find_member(current_user.id) if @membership - @notification_setting = current_user.notification_settings.find_or_initialize_by(source: @project) - - unless @notification_setting.persisted? - @notification_setting.set_defaults - @notification_setting.save - end + @notification_setting = current_user.notification_settings.find_or_create_for(@project) end end diff --git a/app/models/member.rb b/app/models/member.rb index cbcc54c0250..747d0f16d8d 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -163,12 +163,7 @@ class Member < ActiveRecord::Base end def create_notification_setting - notification_setting = user.notification_settings.find_or_initialize_by(source: source) - - unless notification_setting.persisted? - notification_setting.set_defaults - notification_setting.save - end + user.notification_setting.find_or_create_for(source) end def notification_setting diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb index 287862a01bc..13a8995b036 100644 --- a/app/models/notification_setting.rb +++ b/app/models/notification_setting.rb @@ -15,6 +15,17 @@ class NotificationSetting < ActiveRecord::Base scope :for_groups, -> { where(source_type: 'Namespace') } scope :for_projects, -> { where(source_type: 'Project') } + def self.find_or_create_for(source) + setting = find_or_initialize_by(source: source) + + unless setting.persisted? + setting.set_defaults + setting.save + end + + setting + end + def set_defaults self.level = :global end -- cgit v1.2.1 From f8f68d6b8c5b5d85b4798257ae3ae4bf4ec8fadc Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 29 Mar 2016 14:03:23 +0200 Subject: Fix few bugs related to recent notifications refactoring Signed-off-by: Dmitriy Zaporozhets --- app/controllers/profiles/notifications_controller.rb | 1 - app/models/member.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'app') diff --git a/app/controllers/profiles/notifications_controller.rb b/app/controllers/profiles/notifications_controller.rb index 6ca7537300f..0cca5d1e330 100644 --- a/app/controllers/profiles/notifications_controller.rb +++ b/app/controllers/profiles/notifications_controller.rb @@ -1,7 +1,6 @@ class Profiles::NotificationsController < Profiles::ApplicationController def show @user = current_user - @notification = current_user.notification @group_notifications = current_user.notification_settings.for_groups @project_notifications = current_user.notification_settings.for_projects end diff --git a/app/models/member.rb b/app/models/member.rb index 747d0f16d8d..7d5af1d5c8a 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -163,7 +163,7 @@ class Member < ActiveRecord::Base end def create_notification_setting - user.notification_setting.find_or_create_for(source) + user.notification_settings.find_or_create_for(source) end def notification_setting -- cgit v1.2.1 From 5583197e091e8f75ad9c99a1bbc46e6a0b7279d4 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 29 Mar 2016 17:42:38 +0200 Subject: Create NotificationSettings object only when user change value in dropdown Signed-off-by: Dmitriy Zaporozhets --- app/assets/javascripts/project.js.coffee | 9 ++++++++- .../projects/notification_settings_controller.rb | 22 ++++++++++++++++++++++ app/controllers/projects_controller.rb | 3 ++- .../projects/buttons/_notifications.html.haml | 5 ++--- 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 app/controllers/projects/notification_settings_controller.rb (limited to 'app') diff --git a/app/assets/javascripts/project.js.coffee b/app/assets/javascripts/project.js.coffee index f171442d05a..07be85a32a5 100644 --- a/app/assets/javascripts/project.js.coffee +++ b/app/assets/javascripts/project.js.coffee @@ -38,12 +38,19 @@ class @Project e.preventDefault() notification_level = $(@).data 'notification-level' label = $(@).data 'notification-title' - $('#notification_level').val(notification_level) + $('#notification_setting_level').val(notification_level) $('#notification-form').submit() $('#notifications-button').empty().append("" + label + "") $(@).parents('ul').find('li.active').removeClass 'active' $(@).parent().addClass 'active' + $('#notification-form').on 'ajax:success', (e, data) -> + if data.saved + new Flash("Notification settings saved", "notice") + else + new Flash("Failed to save new settings", "alert") + + @projectSelectDropdown() projectSelectDropdown: -> diff --git a/app/controllers/projects/notification_settings_controller.rb b/app/controllers/projects/notification_settings_controller.rb new file mode 100644 index 00000000000..3ecf63d107f --- /dev/null +++ b/app/controllers/projects/notification_settings_controller.rb @@ -0,0 +1,22 @@ +class Projects::NotificationSettingsController < Projects::ApplicationController + def create + notification_setting = project.notification_settings.new(notification_setting_params) + notification_setting.user = current_user + saved = notification_setting.save + + render json: { saved: saved } + end + + def update + notification_setting = project.notification_settings.where(user_id: current_user).find(params[:id]) + saved = notification_setting.update_attributes(notification_setting_params) + + render json: { saved: saved } + end + + private + + def notification_setting_params + params.require(:notification_setting).permit(:level) + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e2dc6309d26..ec5318f2d2c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -102,7 +102,8 @@ class ProjectsController < Projects::ApplicationController @membership = @project.team.find_member(current_user.id) if @membership - @notification_setting = current_user.notification_settings.find_or_create_for(@project) + @notification_setting = current_user.notification_settings.find_or_initialize_by(source: @project) + @notification_setting.set_defaults unless @notification_setting.persisted? end end diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index 4b8a10f0819..2b9d8f2ac81 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -1,7 +1,6 @@ - if @notification_setting - = form_tag profile_notifications_path, method: :put, remote: true, class: 'inline', id: 'notification-form' do - = hidden_field_tag :notification_id, @notification_setting.id - = hidden_field_tag :notification_level, @notification_setting.level + = form_for [@project.namespace.becomes(Namespace), @project, @notification_setting], remote: true, html: { class: 'inline', id: 'notification-form' } do |f| + = f.hidden_field :level %span.dropdown %a.dropdown-new.btn.notifications-btn#notifications-button{href: '#', "data-toggle" => "dropdown"} = icon('bell') -- cgit v1.2.1 From 729fe42bff474535c9eebb0b73974a79756372b8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 29 Mar 2016 17:56:12 +0200 Subject: Improve project notification settings explanation Signed-off-by: Dmitriy Zaporozhets --- app/views/profiles/notifications/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/profiles/notifications/show.html.haml b/app/views/profiles/notifications/show.html.haml index f6900f61b2d..e9c8ae28544 100644 --- a/app/views/profiles/notifications/show.html.haml +++ b/app/views/profiles/notifications/show.html.haml @@ -65,7 +65,7 @@ %h5 Projects (#{@project_notifications.count}) %p.account-well - To specify the notification level per project of a group you belong to, you need to be a member of the project itself, not only its group. + To specify the notification level per project of a group you belong to, you need to visit project page and change notification level there. .append-bottom-default %ul.bordered-list - @project_notifications.each do |setting| -- cgit v1.2.1 From 26631f9981a826ebe4aeba726e9be2b813d2c5c5 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 29 Mar 2016 18:59:03 +0200 Subject: Change how notification settings in profile are rendered and updated Signed-off-by: Dmitriy Zaporozhets --- app/assets/javascripts/profile.js.coffee | 7 ++- .../groups/notification_settings_controller.rb | 14 +++++ .../profiles/notifications_controller.rb | 28 ++------- .../notifications/_group_settings.html.haml | 13 ++++ .../notifications/_project_settings.html.haml | 13 ++++ .../profiles/notifications/_settings.html.haml | 17 ----- app/views/profiles/notifications/show.html.haml | 72 +++++++++++----------- app/views/profiles/notifications/update.js.haml | 6 -- 8 files changed, 88 insertions(+), 82 deletions(-) create mode 100644 app/controllers/groups/notification_settings_controller.rb create mode 100644 app/views/profiles/notifications/_group_settings.html.haml create mode 100644 app/views/profiles/notifications/_project_settings.html.haml delete mode 100644 app/views/profiles/notifications/_settings.html.haml delete mode 100644 app/views/profiles/notifications/update.js.haml (limited to 'app') diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile.js.coffee index ae87c6c4e40..f4a2562885d 100644 --- a/app/assets/javascripts/profile.js.coffee +++ b/app/assets/javascripts/profile.js.coffee @@ -18,8 +18,11 @@ class @Profile $(this).find('.btn-save').enable() $(this).find('.loading-gif').hide() - $('.update-notifications').on 'ajax:complete', -> - $(this).find('.btn-save').enable() + $('.update-notifications').on 'ajax:success', (e, data) -> + if data.saved + new Flash("Notification settings saved", "notice") + else + new Flash("Failed to save new settings", "alert") @bindEvents() diff --git a/app/controllers/groups/notification_settings_controller.rb b/app/controllers/groups/notification_settings_controller.rb new file mode 100644 index 00000000000..78e43c83aba --- /dev/null +++ b/app/controllers/groups/notification_settings_controller.rb @@ -0,0 +1,14 @@ +class Groups::NotificationSettingsController < Groups::ApplicationController + def update + notification_setting = group.notification_settings.where(user_id: current_user).find(params[:id]) + saved = notification_setting.update_attributes(notification_setting_params) + + render json: { saved: saved } + end + + private + + def notification_setting_params + params.require(:notification_setting).permit(:level) + end +end diff --git a/app/controllers/profiles/notifications_controller.rb b/app/controllers/profiles/notifications_controller.rb index 0cca5d1e330..18ee55c839a 100644 --- a/app/controllers/profiles/notifications_controller.rb +++ b/app/controllers/profiles/notifications_controller.rb @@ -6,29 +6,13 @@ class Profiles::NotificationsController < Profiles::ApplicationController end def update - type = params[:notification_type] - - @saved = if type == 'global' - current_user.update_attributes(user_params) - else - notification_setting = current_user.notification_settings.find(params[:notification_id]) - notification_setting.level = params[:notification_level] - notification_setting.save - end - - respond_to do |format| - format.html do - if @saved - flash[:notice] = "Notification settings saved" - else - flash[:alert] = "Failed to save new settings" - end - - redirect_back_or_default(default: profile_notifications_path) - end - - format.js + if current_user.update_attributes(user_params) + flash[:notice] = "Notification settings saved" + else + flash[:alert] = "Failed to save new settings" end + + redirect_back_or_default(default: profile_notifications_path) end def user_params diff --git a/app/views/profiles/notifications/_group_settings.html.haml b/app/views/profiles/notifications/_group_settings.html.haml new file mode 100644 index 00000000000..89ae7ffda2b --- /dev/null +++ b/app/views/profiles/notifications/_group_settings.html.haml @@ -0,0 +1,13 @@ +%li.notification-list-item + %span.notification.fa.fa-holder.append-right-5 + - if setting.global? + = notification_icon(current_user.notification_level) + - else + = notification_icon(setting.level) + + %span.str-truncated + = link_to group.name, group_path(group) + + .pull-right + = form_for [group, setting], remote: true, html: { class: 'update-notifications' } do |f| + = f.select :level, NotificationSetting.levels.keys, {}, class: 'form-control trigger-submit' diff --git a/app/views/profiles/notifications/_project_settings.html.haml b/app/views/profiles/notifications/_project_settings.html.haml new file mode 100644 index 00000000000..17c097154da --- /dev/null +++ b/app/views/profiles/notifications/_project_settings.html.haml @@ -0,0 +1,13 @@ +%li.notification-list-item + %span.notification.fa.fa-holder.append-right-5 + - if setting.global? + = notification_icon(current_user.notification_level) + - else + = notification_icon(setting.level) + + %span.str-truncated + = link_to_project(project) + + .pull-right + = form_for [project.namespace.becomes(Namespace), project, setting], remote: true, html: { class: 'update-notifications' } do |f| + = f.select :level, NotificationSetting.levels.keys, {}, class: 'form-control trigger-submit' diff --git a/app/views/profiles/notifications/_settings.html.haml b/app/views/profiles/notifications/_settings.html.haml deleted file mode 100644 index c32de0b9925..00000000000 --- a/app/views/profiles/notifications/_settings.html.haml +++ /dev/null @@ -1,17 +0,0 @@ -%li.notification-list-item - %span.notification.fa.fa-holder.append-right-5 - - if setting.global? - = notification_icon(current_user.notification_level) - - else - = notification_icon(setting.level) - - %span.str-truncated - - if setting.source.kind_of? Project - = link_to_project(setting.source) - - else - = link_to setting.source.name, group_path(setting.source) - .pull-right - = form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do - = hidden_field_tag :notification_id, setting.id - = hidden_field_tag :notification_level, setting.level - = select_tag :notification_level, options_for_select(User.notification_levels.keys, setting.level), class: 'form-control trigger-submit' diff --git a/app/views/profiles/notifications/show.html.haml b/app/views/profiles/notifications/show.html.haml index e9c8ae28544..a2a505c082b 100644 --- a/app/views/profiles/notifications/show.html.haml +++ b/app/views/profiles/notifications/show.html.haml @@ -1,8 +1,8 @@ - page_title "Notifications" - header_title page_title, profile_notifications_path -= form_for @user, url: profile_notifications_path, method: :put, html: { class: 'update-notifications prepend-top-default' } do |f| - -if @user.errors.any? +%div + - if @user.errors.any? %div.alert.alert-danger %ul - @user.errors.full_messages.each do |msg| @@ -20,48 +20,50 @@ .col-lg-9 %h5 Global notification settings - .form-group - = f.label :notification_email, class: "label-light" - = f.select :notification_email, @user.all_emails, { include_blank: false }, class: "select2" - .form-group - = f.label :notification_level, class: 'label-light' - .radio - = f.label :notification_level, value: :disabled do - = f.radio_button :notification_level, :disabled - .level-title - Disabled - %p You will not get any notifications via email - .radio - = f.label :notification_level, value: :mention do - = f.radio_button :notification_level, :mention - .level-title - On Mention - %p You will receive notifications only for comments in which you were @mentioned + = form_for @user, url: profile_notifications_path, method: :put, html: { class: 'update-notifications prepend-top-default' } do |f| + .form-group + = f.label :notification_email, class: "label-light" + = f.select :notification_email, @user.all_emails, { include_blank: false }, class: "select2" + .form-group + = f.label :notification_level, class: 'label-light' + .radio + = f.label :notification_level, value: :disabled do + = f.radio_button :notification_level, :disabled + .level-title + Disabled + %p You will not get any notifications via email - .radio - = f.label :notification_level, value: :participating do - = f.radio_button :notification_level, :participating - .level-title - Participating - %p You will only receive notifications from related resources (e.g. from your commits or assigned issues) + .radio + = f.label :notification_level, value: :mention do + = f.radio_button :notification_level, :mention + .level-title + On Mention + %p You will receive notifications only for comments in which you were @mentioned - .radio - = f.label :notification_level, value: :watch do - = f.radio_button :notification_level, :watch - .level-title - Watch - %p You will receive notifications for any activity + .radio + = f.label :notification_level, value: :participating do + = f.radio_button :notification_level, :participating + .level-title + Participating + %p You will only receive notifications from related resources (e.g. from your commits or assigned issues) - .prepend-top-default - = f.submit 'Update settings', class: "btn btn-create" + .radio + = f.label :notification_level, value: :watch do + = f.radio_button :notification_level, :watch + .level-title + Watch + %p You will receive notifications for any activity + + .prepend-top-default + = f.submit 'Update settings', class: "btn btn-create" %hr %h5 Groups (#{@group_notifications.count}) %div %ul.bordered-list - @group_notifications.each do |setting| - = render 'settings', setting: setting + = render 'group_settings', setting: setting, group: setting.source %h5 Projects (#{@project_notifications.count}) %p.account-well @@ -69,4 +71,4 @@ .append-bottom-default %ul.bordered-list - @project_notifications.each do |setting| - = render 'settings', setting: setting + = render 'project_settings', setting: setting, project: setting.source diff --git a/app/views/profiles/notifications/update.js.haml b/app/views/profiles/notifications/update.js.haml deleted file mode 100644 index 84c6ab25599..00000000000 --- a/app/views/profiles/notifications/update.js.haml +++ /dev/null @@ -1,6 +0,0 @@ -- if @saved - :plain - new Flash("Notification settings saved", "notice") -- else - :plain - new Flash("Failed to save new settings", "alert") -- cgit v1.2.1 From 3d145ce8d513207988d523288334a61a575d4c01 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Thu, 24 Mar 2016 12:28:06 +0100 Subject: fix labels not showing on todos page --- app/assets/stylesheets/framework/variables.scss | 1 + app/assets/stylesheets/pages/events.scss | 11 ++++++++++- app/assets/stylesheets/pages/todos.scss | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index 463ce4ecdd7..6d188659524 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -28,6 +28,7 @@ $gl-link-color: #3084bb; $gl-dark-link-color: #333; $gl-placeholder-color: #8f8f8f; $gl-icon-color: $gl-placeholder-color; +$gl-grayish-blue: #7f8fa4; $gl-gray: $gl-text-color; $gl-header-color: $gl-title-color; diff --git a/app/assets/stylesheets/pages/events.scss b/app/assets/stylesheets/pages/events.scss index c66efe978cd..6fe57c737b3 100644 --- a/app/assets/stylesheets/pages/events.scss +++ b/app/assets/stylesheets/pages/events.scss @@ -41,8 +41,17 @@ word-wrap: break-word; .md { - color: #7f8fa4; + color: $gl-grayish-blue; font-size: $gl-font-size; + + .label { + color: $gl-text-color; + font-size: inherit; + } + + iframe.twitter-share-button { + vertical-align: bottom; + } } pre { diff --git a/app/assets/stylesheets/pages/todos.scss b/app/assets/stylesheets/pages/todos.scss index e83fa9e3d52..75f78569e3c 100644 --- a/app/assets/stylesheets/pages/todos.scss +++ b/app/assets/stylesheets/pages/todos.scss @@ -34,6 +34,11 @@ color: #7f8fa4; font-size: $gl-font-size; + .label { + color: $gl-text-color; + font-size: inherit; + } + p { color: #5c5d5e; } -- cgit v1.2.1 From c11c574d3ef4384b38f310c8d8568a116e0d0dfd Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 7 Apr 2016 00:00:58 -0500 Subject: Convert time param to Time --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e6ceb213532..16e5b8ac223 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -184,7 +184,7 @@ module ApplicationHelper element = content_tag :time, time.to_s, class: "#{html_class} js-timeago #{"js-timeago-pending" unless skip_js}", datetime: time.to_time.getutc.iso8601, - title: time.in_time_zone.to_s(:medium), + title: time.to_time.in_time_zone.to_s(:medium), data: { toggle: 'tooltip', placement: placement, container: 'body' } unless skip_js -- cgit v1.2.1 From af3d7d3134033a50dbe41d88654bfea9847524a7 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 7 Apr 2016 11:00:36 +0100 Subject: Fixed issue with any label & no label filters missing Closes #15008 --- app/views/shared/issuable/_label_dropdown.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/shared/issuable/_label_dropdown.html.haml b/app/views/shared/issuable/_label_dropdown.html.haml index fd5e58c1f1f..f722e61eeac 100644 --- a/app/views/shared/issuable/_label_dropdown.html.haml +++ b/app/views/shared/issuable/_label_dropdown.html.haml @@ -1,7 +1,7 @@ - if params[:label_name].present? = hidden_field_tag(:label_name, params[:label_name]) .dropdown - %button.dropdown-menu-toggle.js-label-select.js-filter-submit{type: "button", data: {toggle: "dropdown", field_name: "label_name", show_no: "true", show_any: "true", selected: params[:label_name], project_id: @project.try(:id), labels: labels_filter_path, default_label: "Label"}} + %button.dropdown-menu-toggle.js-label-select.js-filter-submit.js-extra-options{type: "button", data: {toggle: "dropdown", field_name: "label_name", show_no: "true", show_any: "true", selected: params[:label_name], project_id: @project.try(:id), labels: labels_filter_path, default_label: "Label"}} %span.dropdown-toggle-text = h(params[:label_name].presence || "Label") = icon('chevron-down') -- cgit v1.2.1 From 656d8d8865a817e9c01e11f875d6ce1a3d8adebf Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 7 Apr 2016 15:56:59 +0100 Subject: Fixed colour of dropdown link hover --- app/assets/stylesheets/pages/issuable.scss | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app') diff --git a/app/assets/stylesheets/pages/issuable.scss b/app/assets/stylesheets/pages/issuable.scss index 88c1b614c74..8b6f37f21b5 100644 --- a/app/assets/stylesheets/pages/issuable.scss +++ b/app/assets/stylesheets/pages/issuable.scss @@ -263,6 +263,12 @@ } } + .dropdown-content { + a:hover { + color: inherit; + } + } + .dropdown-menu-toggle { width: 100%; padding-top: 6px; -- cgit v1.2.1 From 24f18c8e52b55c96f20dbe0b3b9a9c74baff7813 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 7 Apr 2016 16:19:26 +0100 Subject: Updated meqia query for admin/groups search box --- app/assets/stylesheets/framework/nav.scss | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/assets/stylesheets/framework/nav.scss b/app/assets/stylesheets/framework/nav.scss index 94f5a12ff6a..192d53b048a 100644 --- a/app/assets/stylesheets/framework/nav.scss +++ b/app/assets/stylesheets/framework/nav.scss @@ -58,12 +58,12 @@ .nav-search { display: inline-block; - width: 50%; + width: 100%; padding: 11px 0; /* Small devices (phones, tablets, 768px and lower) */ - @media (max-width: $screen-sm-min) { - width: 100%; + @media (min-width: $screen-sm-min) { + width: 50%; } } -- cgit v1.2.1 From 0dbf2df341f6d71218c927e2d5f4ac5cf67794be Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Thu, 7 Apr 2016 16:42:01 +0100 Subject: fix quick submit missing in edit merge request page --- app/views/projects/merge_requests/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/projects/merge_requests/_form.html.haml b/app/views/projects/merge_requests/_form.html.haml index 3e4ab09c6d4..1e6724fc92b 100644 --- a/app/views/projects/merge_requests/_form.html.haml +++ b/app/views/projects/merge_requests/_form.html.haml @@ -1,4 +1,4 @@ -= form_for [@project.namespace.becomes(Namespace), @project, @merge_request], html: { class: 'merge-request-form form-horizontal gfm-form js-requires-input' } do |f| += form_for [@project.namespace.becomes(Namespace), @project, @merge_request], html: { class: 'merge-request-form form-horizontal gfm-form js-requires-input js-quick-submit' } do |f| = render 'shared/issuable/form', f: f, issuable: @merge_request :javascript -- cgit v1.2.1 From b19ccdeed45605a7bb79509092b297087d6c6e8c Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 7 Apr 2016 12:00:19 -0500 Subject: Add datetime_utility.js.coffee --- app/assets/javascripts/lib/datetime_utility.js.coffee | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/assets/javascripts/lib/datetime_utility.js.coffee (limited to 'app') diff --git a/app/assets/javascripts/lib/datetime_utility.js.coffee b/app/assets/javascripts/lib/datetime_utility.js.coffee new file mode 100644 index 00000000000..ef9406fc331 --- /dev/null +++ b/app/assets/javascripts/lib/datetime_utility.js.coffee @@ -0,0 +1,15 @@ +((w) -> + + w.gl ?= {} + w.gl.utils ?= {} + + w.gl.utils.formatDate = (datetime) -> + dateFormat(datetime, 'mmm d, yyyy h:MMtt Z') + + w.gl.utils.updateFormatDate = ($timeagoEls) -> + $timeagoEls.each( -> + $el = $(@) + $el.attr('title', gl.utils.formatDate($el.attr('datetime'))) + ) + +) window -- cgit v1.2.1 From 3440c0e61f570e9f42a81fb125a021b138b5bebc Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 7 Apr 2016 12:02:43 -0500 Subject: Update datetime in .timeago elements This should be done before .timeago() is called on the element --- app/assets/javascripts/application.js.coffee | 5 ++++- app/assets/javascripts/merge_request_tabs.js.coffee | 12 +++++++++--- app/assets/javascripts/notes.js.coffee | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index f01c67e9474..922a28b4ef5 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -41,6 +41,7 @@ #= require shortcuts_issuable #= require shortcuts_network #= require jquery.nicescroll +#= require date.format #= require_tree . #= require fuzzaldrin-plus #= require cropper @@ -163,7 +164,9 @@ $ -> $('.trigger-submit').on 'change', -> $(@).parents('form').submit() - $('abbr.timeago, .js-timeago').timeago() + $timeago = $('abbr.timeago, .js-timeago') + gl.utils.updateFormatDate($timeago) + $timeago.timeago() # Flash if (flash = $(".flash-container")).length > 0 diff --git a/app/assets/javascripts/merge_request_tabs.js.coffee b/app/assets/javascripts/merge_request_tabs.js.coffee index 839e6ec2c08..fdf084a8a82 100644 --- a/app/assets/javascripts/merge_request_tabs.js.coffee +++ b/app/assets/javascripts/merge_request_tabs.js.coffee @@ -141,7 +141,9 @@ class @MergeRequestTabs url: "#{source}.json" success: (data) => document.querySelector("div#commits").innerHTML = data.html - $('.js-timeago').timeago() + $timeago = $('.js-timeago', 'div#commits') + gl.utils.updateFormatDate($timeago) + $timeago.timeago() @commitsLoaded = true @scrollToElement("#commits") @@ -152,7 +154,9 @@ class @MergeRequestTabs url: "#{source}.json" + @_location.search success: (data) => document.querySelector("div#diffs").innerHTML = data.html - $('.js-timeago').timeago() + $timeago = $('.js-timeago', 'div#diffs') + gl.utils.updateFormatDate($timeago) + $timeago.timeago() $('div#diffs .js-syntax-highlight').syntaxHighlight() @expandViewContainer() if @diffViewType() is 'parallel' @diffsLoaded = true @@ -165,7 +169,9 @@ class @MergeRequestTabs url: "#{source}.json" success: (data) => document.querySelector("div#builds").innerHTML = data.html - $('.js-timeago').timeago() + $timeago = $('.js-timeago', 'div#builds') + gl.utils.updateFormatDate($timeago) + $timeago.timeago() @buildsLoaded = true @scrollToElement("#builds") diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee index 86e3b860fcb..02e52040e3c 100644 --- a/app/assets/javascripts/notes.js.coffee +++ b/app/assets/javascripts/notes.js.coffee @@ -163,9 +163,16 @@ class @Notes else if @isNewNote(note) @note_ids.push(note.id) - $('ul.main-notes-list') + $notesList = $('ul.main-notes-list') + + $notesList .append(note.html) .syntaxHighlight() + + # Update datetime format on the recent note + $timeago = $notesList.find("#note_#{note.id} .js-timeago") + gl.utils.updateFormatDate($timeago) + @initTaskList() @updateNotesCount(1) @@ -217,6 +224,8 @@ class @Notes # append new note to all matching discussions discussionContainer.append note_html + gl.utils.updateFormatDate($('.js-timeago', note_html)) + @updateNotesCount(1) ### @@ -345,7 +354,11 @@ class @Notes updateNote: (_xhr, note, _status) => # Convert returned HTML to a jQuery object so we can modify it further $html = $(note.html) - $('.js-timeago', $html).timeago() + + $timeago = $('.js-timeago', $html) + gl.utils.updateFormatDate($timeago) + $timeago.timeago() + $html.syntaxHighlight() $html.find('.js-task-list-container').taskList('enable') -- cgit v1.2.1 From 1d2429af9b0fd4ef1427c7676a50dae4e2cf0ff9 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Thu, 7 Apr 2016 16:45:33 -0500 Subject: Add missing proper nil and error handling to SAML login process. --- app/controllers/omniauth_callbacks_controller.rb | 26 +++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index d28e96c3f18..df98f56a1cd 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -60,6 +60,8 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController continue_login_process end + rescue Gitlab::OAuth::SignupDisabledError + handle_signup_error end def omniauth_error @@ -92,16 +94,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController continue_login_process end rescue Gitlab::OAuth::SignupDisabledError - label = Gitlab::OAuth::Provider.label_for(oauth['provider']) - message = "Signing in using your #{label} account without a pre-existing GitLab account is not allowed." - - if current_application_settings.signup_enabled? - message << " Create a GitLab account first, and then connect it to your #{label} account." - end - - flash[:notice] = message - - redirect_to new_user_session_path + handle_signup_error end def handle_service_ticket provider, ticket @@ -122,6 +115,19 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController end end + def handle_signup_error + label = Gitlab::OAuth::Provider.label_for(oauth['provider']) + message = "Signing in using your #{label} account without a pre-existing GitLab account is not allowed." + + if current_application_settings.signup_enabled? + message << " Create a GitLab account first, and then connect it to your #{label} account." + end + + flash[:notice] = message + + redirect_to new_user_session_path + end + def oauth @oauth ||= request.env['omniauth.auth'] end -- cgit v1.2.1 From 6dacf0fd6d2627e05e50e0116566946e3b81bc5f Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 8 Apr 2016 16:02:13 +0100 Subject: Fixed issue with member access not being visible on notes Fixes #15049 --- app/views/projects/notes/_note.html.haml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/views/projects/notes/_note.html.haml b/app/views/projects/notes/_note.html.haml index a681d6dece4..b4fa917718b 100644 --- a/app/views/projects/notes/_note.html.haml +++ b/app/views/projects/notes/_note.html.haml @@ -10,12 +10,12 @@ = "#{note.author.to_reference} commented" %a{ href: "##{dom_id(note)}" } = time_ago_with_tooltip(note.created_at, placement: 'bottom', html_class: 'note-created-ago') - - if note_editable?(note) - .note-actions - - access = note.project.team.human_max_access(note.author.id) - - if access - %span.note-role - = access + .note-actions + - access = note.project.team.human_max_access(note.author.id) + - if access + %span.note-role + = access + - if note_editable?(note) = link_to '#', title: 'Edit comment', class: 'note-action-button js-note-edit' do = icon('pencil-square-o') = link_to namespace_project_note_path(note.project.namespace, note.project, note), title: 'Remove comment', method: :delete, data: { confirm: 'Are you sure you want to remove this comment?' }, remote: true, class: 'note-action-button js-note-delete' do -- cgit v1.2.1 From 127119f2c4db9038a7f34d1cc73ae1ed19cf0b8d Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Fri, 8 Apr 2016 16:59:06 -0300 Subject: Simplify query to retrieve NotificationSetting on controllers --- app/controllers/groups/notification_settings_controller.rb | 2 +- app/controllers/projects/notification_settings_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/controllers/groups/notification_settings_controller.rb b/app/controllers/groups/notification_settings_controller.rb index 78e43c83aba..20405a05190 100644 --- a/app/controllers/groups/notification_settings_controller.rb +++ b/app/controllers/groups/notification_settings_controller.rb @@ -1,6 +1,6 @@ class Groups::NotificationSettingsController < Groups::ApplicationController def update - notification_setting = group.notification_settings.where(user_id: current_user).find(params[:id]) + notification_setting = group.notification_settings.find_by(user_id: current_user) saved = notification_setting.update_attributes(notification_setting_params) render json: { saved: saved } diff --git a/app/controllers/projects/notification_settings_controller.rb b/app/controllers/projects/notification_settings_controller.rb index 3ecf63d107f..da9034380af 100644 --- a/app/controllers/projects/notification_settings_controller.rb +++ b/app/controllers/projects/notification_settings_controller.rb @@ -8,7 +8,7 @@ class Projects::NotificationSettingsController < Projects::ApplicationController end def update - notification_setting = project.notification_settings.where(user_id: current_user).find(params[:id]) + notification_setting = project.notification_settings.find_by(user_id: current_user) saved = notification_setting.update_attributes(notification_setting_params) render json: { saved: saved } -- cgit v1.2.1 From ee497599cc69b126cc2e4a929f1799d3d3eb989d Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Fri, 8 Apr 2016 17:24:27 -0300 Subject: Use default_value_for to set default NotificationSetting#level --- app/controllers/projects_controller.rb | 1 - app/models/notification_setting.rb | 14 ++++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 41a4c41cf80..39f436f6f4e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -106,7 +106,6 @@ class ProjectsController < Projects::ApplicationController if @membership @notification_setting = current_user.notification_settings.find_or_initialize_by(source: @project) - @notification_setting.set_defaults unless @notification_setting.persisted? end end diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb index 13a8995b036..d89194b5a12 100644 --- a/app/models/notification_setting.rb +++ b/app/models/notification_setting.rb @@ -1,4 +1,10 @@ class NotificationSetting < ActiveRecord::Base + # Notification level + # Note: When adding an option, it MUST go on the end of the array. + enum level: [:disabled, :participating, :watch, :global, :mention] + + default_value_for :level, NotificationSetting.levels[:global] + belongs_to :user belongs_to :source, polymorphic: true @@ -8,9 +14,6 @@ class NotificationSetting < ActiveRecord::Base validates :user_id, uniqueness: { scope: [:source_type, :source_id], message: "already exists in source", allow_nil: true } - # Notification level - # Note: When adding an option, it MUST go on the end of the array. - enum level: [:disabled, :participating, :watch, :global, :mention] scope :for_groups, -> { where(source_type: 'Namespace') } scope :for_projects, -> { where(source_type: 'Project') } @@ -19,14 +22,9 @@ class NotificationSetting < ActiveRecord::Base setting = find_or_initialize_by(source: source) unless setting.persisted? - setting.set_defaults setting.save end setting end - - def set_defaults - self.level = :global - end end -- cgit v1.2.1 From 635b65d1206293d0b92322df18d458447ee73d5a Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Fri, 8 Apr 2016 17:35:21 -0300 Subject: Add method to return the user notification setting for a group, or a project --- app/controllers/projects_controller.rb | 2 +- app/models/user.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 39f436f6f4e..3768efe142a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -105,7 +105,7 @@ class ProjectsController < Projects::ApplicationController @membership = @project.team.find_member(current_user.id) if @membership - @notification_setting = current_user.notification_settings.find_or_initialize_by(source: @project) + @notification_setting = current_user.notification_settings_for(@project) end end diff --git a/app/models/user.rb b/app/models/user.rb index f68379fd050..031315debd7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -831,6 +831,10 @@ class User < ActiveRecord::Base end end + def notification_settings_for(source) + notification_settings.find_or_initialize_by(source: source) + end + private def projects_union -- cgit v1.2.1 From 667d44c25ccefb511fc0d206eaa5990117032236 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 11 Apr 2016 12:46:19 +0200 Subject: Fix high CPU usage when PostReceive receives refs/merge-requests/ --- app/workers/post_receive.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb index 3cc232ef1ae..9e1215b21a6 100644 --- a/app/workers/post_receive.rb +++ b/app/workers/post_receive.rb @@ -40,7 +40,7 @@ class PostReceive if Gitlab::Git.tag_ref?(ref) GitTagPushService.new.execute(post_received.project, @user, oldrev, newrev, ref) - else + elsif Gitlab::Git.branch_ref?(ref) GitPushService.new(post_received.project, @user, oldrev: oldrev, newrev: newrev, ref: ref).execute end end -- cgit v1.2.1 From 73fdd4b83d76998fef9770dbeaf05981d4500b8c Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 11 Apr 2016 10:23:40 -0300 Subject: Use Hash instead of Array on NotificationSetting#level enum --- app/models/notification_setting.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'app') diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb index d89194b5a12..5001738f411 100644 --- a/app/models/notification_setting.rb +++ b/app/models/notification_setting.rb @@ -1,7 +1,5 @@ class NotificationSetting < ActiveRecord::Base - # Notification level - # Note: When adding an option, it MUST go on the end of the array. - enum level: [:disabled, :participating, :watch, :global, :mention] + enum level: { disabled: 0, participating: 1, watch: 2, global: 3, mention: 4 } default_value_for :level, NotificationSetting.levels[:global] -- cgit v1.2.1 From de4d98fd120fd43bd744abc116c62708577b5673 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Mon, 11 Apr 2016 15:19:11 +0100 Subject: fix bug causing comment form in issue to submit twice when CTRL+Enter is pressed twice --- app/assets/javascripts/behaviors/quick_submit.js.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/assets/javascripts/behaviors/quick_submit.js.coffee b/app/assets/javascripts/behaviors/quick_submit.js.coffee index 6e29d374267..3cb96bacaa7 100644 --- a/app/assets/javascripts/behaviors/quick_submit.js.coffee +++ b/app/assets/javascripts/behaviors/quick_submit.js.coffee @@ -29,7 +29,11 @@ $(document).on 'keydown.quick_submit', '.js-quick-submit', (e) -> e.preventDefault() $form = $(e.target).closest('form') - $form.find('input[type=submit], button[type=submit]').disable() + $submit_button = $form.find('input[type=submit], button[type=submit]') + + return if $submit_button.attr('disabled') + + $submit_button.disable() $form.submit() # If the user tabs to a submit button on a `js-quick-submit` form, display a -- cgit v1.2.1 From 60fd4188a540368776738896b1e10683b7fa9e65 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 5 Apr 2016 16:18:25 +0100 Subject: Build notification null check Cancels build notification interval on page change --- app/assets/javascripts/merge_request_widget.js.coffee | 15 ++++++++++++++- app/views/projects/merge_requests/widget/_show.html.haml | 7 +------ 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index 84a8887fbce..1e3a5847521 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -12,10 +12,19 @@ class @MergeRequestWidget @readyForCICheck = true clearInterval @fetchBuildStatusInterval + @clearEventListeners() + @addEventListeners() @pollCIStatus() notifyPermissions() - setOpts: (@opts) -> + clearEventListeners: -> + $(document).off 'page:change.merge_request' + + addEventListeners: -> + $(document).on 'page:change.merge_request', => + if $('body').data('page') isnt 'projects:merge_requests:show' + clearInterval @fetchBuildStatusInterval + @clearEventListeners() mergeInProgress: (deleteSourceBranch = false)-> $.ajax @@ -63,11 +72,15 @@ class @MergeRequestWidget @firstCICheck = false @opts.ci_status = data.status +<<<<<<< a918e8bf277418048776a5d9c34a64b39f4e56f3 if @opts.ci_status is '' @opts.ci_status = data.status return if data.status isnt @opts.ci_status +======= + if data.status isnt @opts.ci_status and data.status? +>>>>>>> Build notification null check @showCIStatus data.status if data.coverage @showCICoverage data.coverage diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml index 92d95358937..003477dda1a 100644 --- a/app/views/projects/merge_requests/widget/_show.html.haml +++ b/app/views/projects/merge_requests/widget/_show.html.haml @@ -8,7 +8,6 @@ = render 'projects/merge_requests/widget/locked' :javascript - var merge_request_widget; var opts = { merge_check_url: "#{merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", check_enable: #{@merge_request.unchecked? ? "true" : "false"}, @@ -20,8 +19,4 @@ builds_path: "#{builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}" }; - if(typeof merge_request_widget === 'undefined') { - merge_request_widget = new MergeRequestWidget(opts); - } else { - merge_request_widget.setOpts(opts); - } + new MergeRequestWidget(opts); -- cgit v1.2.1 From b87cc5f224428a332b63f3ac7832ea7d882b37b3 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 13:58:44 +0100 Subject: Preparing build status --- app/controllers/projects/merge_requests_controller.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app') diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index ae613f5e093..9addcdf3f91 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -237,6 +237,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController end end + status = "preparing" if status == nil + response = { title: merge_request.title, sha: merge_request.last_commit_short_sha, -- cgit v1.2.1 From ce0678faa5a1e4688aa7491c49cebd4b172244af Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 14:50:34 +0100 Subject: Rubocop fix --- app/controllers/projects/merge_requests_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 9addcdf3f91..3e0cfc6aa65 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -237,7 +237,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController end end - status = "preparing" if status == nil + status = "preparing" if status.nil? response = { title: merge_request.title, -- cgit v1.2.1 From 99fe9c7b7703b1594c9cda571f43f20198f96b0f Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 14:58:50 +0100 Subject: Corrects the button color on build status change --- app/assets/javascripts/merge_request_widget.js.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index 1e3a5847521..63f75be2dad 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -111,6 +111,8 @@ class @MergeRequestWidget @setMergeButtonClass('btn-danger') when "running", "pending" @setMergeButtonClass('btn-warning') + when "success" + @setMergeButtonClass('btn-create') else $('.ci_widget.ci-error').show() @setMergeButtonClass('btn-danger') @@ -120,4 +122,6 @@ class @MergeRequestWidget $('.ci_widget:visible .ci-coverage').text(text) setMergeButtonClass: (css_class) -> - $('.accept_merge_request').removeClass("btn-create").addClass(css_class) + $('.accept_merge_request') + .removeClass('btn-danger btn-warning btn-create') + .addClass(css_class) -- cgit v1.2.1 From 552cde76fa96282dec4ba002cd1850d003a5b29f Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 15:06:27 +0100 Subject: Hides notification after X amount of seconds --- app/assets/javascripts/lib/notify.js.coffee | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app') diff --git a/app/assets/javascripts/lib/notify.js.coffee b/app/assets/javascripts/lib/notify.js.coffee index 3f9ca39912c..9e28353ac34 100644 --- a/app/assets/javascripts/lib/notify.js.coffee +++ b/app/assets/javascripts/lib/notify.js.coffee @@ -2,6 +2,11 @@ notificationGranted = (message, opts, onclick) -> notification = new Notification(message, opts) + # Hide the notification after X amount of seconds + setTimeout -> + notification.close() + , 8000 + if onclick notification.onclick = onclick -- cgit v1.2.1 From 843bc44aa9dea8a19af21dd13a82ecc02bf8840c Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 17:04:22 +0100 Subject: Preparing build text --- app/assets/javascripts/merge_request_widget.js.coffee | 16 +++++++++++++--- app/views/projects/merge_requests/widget/_show.html.haml | 9 ++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index 63f75be2dad..a522f9189ab 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -47,7 +47,7 @@ class @MergeRequestWidget $('.mr-state-widget').replaceWith(data) ciLabelForStatus: (status) -> - if status == 'success' + if status is 'success' 'passed' else status @@ -86,12 +86,22 @@ class @MergeRequestWidget @showCICoverage data.coverage if showNotification - message = @opts.ci_message.replace('{{status}}', @ciLabelForStatus(data.status)) + status = @ciLabelForStatus(data.status) + + if status is "preparing" + title = @opts.ci_title.preparing + status = status.charAt(0).toUpperCase() + status.slice(1); + message = @opts.ci_message.preparing.replace('{{status}}', status) + else + title = @opts.ci_title.normal + message = @opts.ci_message.normal.replace('{{status}}', status) + + title = title.replace('{{status}}', status) message = message.replace('{{sha}}', data.sha) message = message.replace('{{title}}', data.title) notify( - "Build #{@ciLabelForStatus(data.status)}", + title, message, @opts.gitlab_icon, -> diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml index 003477dda1a..804ca3783e3 100644 --- a/app/views/projects/merge_requests/widget/_show.html.haml +++ b/app/views/projects/merge_requests/widget/_show.html.haml @@ -14,8 +14,15 @@ ci_status_url: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", gitlab_icon: "#{asset_path 'gitlab_logo.png'}", ci_status: "", - ci_message: "Build {{status}} for \"{{title}}\"", + ci_message: { + normal: "Build {{status}} for \"{{title}}\"", + preparing: "{{status}} build for \"{{title}}\"" + }, ci_enable: #{@project.ci_service ? "true" : "false"}, + ci_title: { + preparing: "{{status}} build", + normal: "Build {{status}}" + }, builds_path: "#{builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}" }; -- cgit v1.2.1 From 6a13b372224a5f7ae03dde92f455645441b62f84 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 7 Apr 2016 15:32:46 +0100 Subject: Fixed missed conflict --- app/assets/javascripts/merge_request_widget.js.coffee | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index a522f9189ab..065626beeb8 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -72,15 +72,11 @@ class @MergeRequestWidget @firstCICheck = false @opts.ci_status = data.status -<<<<<<< a918e8bf277418048776a5d9c34a64b39f4e56f3 if @opts.ci_status is '' @opts.ci_status = data.status return - if data.status isnt @opts.ci_status -======= if data.status isnt @opts.ci_status and data.status? ->>>>>>> Build notification null check @showCIStatus data.status if data.coverage @showCICoverage data.coverage -- cgit v1.2.1 From 1b4a56bdb05afdb68b99067c60b9b453b2ecdc24 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 11 Apr 2016 17:28:54 +0100 Subject: Fixed failing tests --- app/views/projects/merge_requests/widget/_show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml index 804ca3783e3..3c68d61c4b5 100644 --- a/app/views/projects/merge_requests/widget/_show.html.haml +++ b/app/views/projects/merge_requests/widget/_show.html.haml @@ -26,4 +26,4 @@ builds_path: "#{builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}" }; - new MergeRequestWidget(opts); + merge_request_widget = new MergeRequestWidget(opts); -- cgit v1.2.1 From 6333ebe619848aaec3811c9e8908c017317c019f Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 10:16:39 +0100 Subject: Prefills commit message in edit file See #14488 --- app/views/shared/_commit_message_container.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/shared/_commit_message_container.html.haml b/app/views/shared/_commit_message_container.html.haml index 7afbaeddee8..eeb4e2f5563 100644 --- a/app/views/shared/_commit_message_container.html.haml +++ b/app/views/shared/_commit_message_container.html.haml @@ -6,7 +6,7 @@ .commit-message-container .max-width-marker = text_area_tag 'commit_message', - (params[:commit_message] || local_assigns[:text]), + (params[:commit_message] || local_assigns[:placeholder]), class: 'form-control js-commit-message', placeholder: local_assigns[:placeholder], required: true, rows: (local_assigns[:rows] || 3), id: "commit_message-#{nonce}" -- cgit v1.2.1 From 44a95c5dea278d9d835030e3cab8e9e7bead0b44 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 11 Apr 2016 17:41:47 +0100 Subject: Added back text used on merge commit message --- app/views/shared/_commit_message_container.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/shared/_commit_message_container.html.haml b/app/views/shared/_commit_message_container.html.haml index eeb4e2f5563..0a38327baa2 100644 --- a/app/views/shared/_commit_message_container.html.haml +++ b/app/views/shared/_commit_message_container.html.haml @@ -6,7 +6,7 @@ .commit-message-container .max-width-marker = text_area_tag 'commit_message', - (params[:commit_message] || local_assigns[:placeholder]), + (params[:commit_message] || local_assigns[:text] || local_assigns[:placeholder]), class: 'form-control js-commit-message', placeholder: local_assigns[:placeholder], required: true, rows: (local_assigns[:rows] || 3), id: "commit_message-#{nonce}" -- cgit v1.2.1 From 38a4f5cec6ab85525ab9db1d7d2669a77171f768 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Mon, 11 Apr 2016 16:45:03 -0500 Subject: Rename method and initialize .timeago inside --- app/assets/javascripts/application.js.coffee | 4 +--- app/assets/javascripts/lib/datetime_utility.js.coffee | 4 +++- app/assets/javascripts/merge_request_tabs.js.coffee | 12 +++--------- app/assets/javascripts/notes.js.coffee | 9 +++------ 4 files changed, 10 insertions(+), 19 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 922a28b4ef5..b05138ac1ac 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -164,9 +164,7 @@ $ -> $('.trigger-submit').on 'change', -> $(@).parents('form').submit() - $timeago = $('abbr.timeago, .js-timeago') - gl.utils.updateFormatDate($timeago) - $timeago.timeago() + gl.utils.localTimeAgo($('abbr.timeago, .js-timeago'), false) # Flash if (flash = $(".flash-container")).length > 0 diff --git a/app/assets/javascripts/lib/datetime_utility.js.coffee b/app/assets/javascripts/lib/datetime_utility.js.coffee index ef9406fc331..ad1d1c70481 100644 --- a/app/assets/javascripts/lib/datetime_utility.js.coffee +++ b/app/assets/javascripts/lib/datetime_utility.js.coffee @@ -6,10 +6,12 @@ w.gl.utils.formatDate = (datetime) -> dateFormat(datetime, 'mmm d, yyyy h:MMtt Z') - w.gl.utils.updateFormatDate = ($timeagoEls) -> + w.gl.utils.localTimeAgo = ($timeagoEls, setTimeago = true) -> $timeagoEls.each( -> $el = $(@) $el.attr('title', gl.utils.formatDate($el.attr('datetime'))) ) + $timeagoEls.timeago() if setTimeago + ) window diff --git a/app/assets/javascripts/merge_request_tabs.js.coffee b/app/assets/javascripts/merge_request_tabs.js.coffee index fdf084a8a82..0ae6e244602 100644 --- a/app/assets/javascripts/merge_request_tabs.js.coffee +++ b/app/assets/javascripts/merge_request_tabs.js.coffee @@ -141,9 +141,7 @@ class @MergeRequestTabs url: "#{source}.json" success: (data) => document.querySelector("div#commits").innerHTML = data.html - $timeago = $('.js-timeago', 'div#commits') - gl.utils.updateFormatDate($timeago) - $timeago.timeago() + gl.utils.localTimeAgo($('.js-timeago', 'div#commits')) @commitsLoaded = true @scrollToElement("#commits") @@ -154,9 +152,7 @@ class @MergeRequestTabs url: "#{source}.json" + @_location.search success: (data) => document.querySelector("div#diffs").innerHTML = data.html - $timeago = $('.js-timeago', 'div#diffs') - gl.utils.updateFormatDate($timeago) - $timeago.timeago() + gl.utils.localTimeAgo($('.js-timeago', 'div#diffs')) $('div#diffs .js-syntax-highlight').syntaxHighlight() @expandViewContainer() if @diffViewType() is 'parallel' @diffsLoaded = true @@ -169,9 +165,7 @@ class @MergeRequestTabs url: "#{source}.json" success: (data) => document.querySelector("div#builds").innerHTML = data.html - $timeago = $('.js-timeago', 'div#builds') - gl.utils.updateFormatDate($timeago) - $timeago.timeago() + gl.utils.localTimeAgo($('.js-timeago', 'div#builds')) @buildsLoaded = true @scrollToElement("#builds") diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee index 02e52040e3c..a67890200dd 100644 --- a/app/assets/javascripts/notes.js.coffee +++ b/app/assets/javascripts/notes.js.coffee @@ -170,8 +170,7 @@ class @Notes .syntaxHighlight() # Update datetime format on the recent note - $timeago = $notesList.find("#note_#{note.id} .js-timeago") - gl.utils.updateFormatDate($timeago) + gl.utils.localTimeAgo($notesList.find("#note_#{note.id} .js-timeago"), false) @initTaskList() @updateNotesCount(1) @@ -224,7 +223,7 @@ class @Notes # append new note to all matching discussions discussionContainer.append note_html - gl.utils.updateFormatDate($('.js-timeago', note_html)) + gl.utils.localTimeAgo($('.js-timeago', note_html), false) @updateNotesCount(1) @@ -355,9 +354,7 @@ class @Notes # Convert returned HTML to a jQuery object so we can modify it further $html = $(note.html) - $timeago = $('.js-timeago', $html) - gl.utils.updateFormatDate($timeago) - $timeago.timeago() + gl.utils.localTimeAgo($('.js-timeago', $html)) $html.syntaxHighlight() $html.find('.js-task-list-container').taskList('enable') -- cgit v1.2.1 From 476cf23fc37d6db8d3fb412ce0b646f228d9aac4 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Mon, 11 Apr 2016 16:21:32 -0300 Subject: Allow to close invalid merge request --- app/models/commit.rb | 8 +++++--- app/models/merge_request.rb | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/models/commit.rb b/app/models/commit.rb index d09876a07d9..11ecfcace14 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -150,13 +150,11 @@ class Commit end def hook_attrs(with_changed_files: false) - path_with_namespace = project.path_with_namespace - data = { id: id, message: safe_message, timestamp: committed_date.xmlschema, - url: "#{Gitlab.config.gitlab.url}/#{path_with_namespace}/commit/#{id}", + url: commit_url, author: { name: author_name, email: author_email @@ -170,6 +168,10 @@ class Commit data end + def commit_url + project.present? ? "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/commit/#{id}" : "" + end + # Discover issues should be closed when this commit is pushed to a project's # default branch. def closes_issues(current_user = self.committer) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index bf185cb5dd8..8292445bcac 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -213,6 +213,8 @@ class MergeRequest < ActiveRecord::Base end def validate_branches + return if allow_broken + if target_project == source_project && target_branch == source_branch errors.add :branch_conflict, "You can not use same project/branch for source and target" end @@ -344,9 +346,12 @@ class MergeRequest < ActiveRecord::Base end def hook_attrs + source_hook_attrs = source_project.hook_attrs if source_project.present? + target_hook_attrs = target_project.hook_attrs if target_project.present? + attrs = { - source: source_project.hook_attrs, - target: target_project.hook_attrs, + source: source_hook_attrs, + target: target_hook_attrs, last_commit: nil, work_in_progress: work_in_progress? } -- cgit v1.2.1 From 93a10f17e0c84074580eaf1b101af2a0fffd19ed Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 11 Apr 2016 18:23:12 -0300 Subject: Reuse `User#notification_settings_for` when it's possible --- app/controllers/groups/notification_settings_controller.rb | 2 +- app/controllers/projects/notification_settings_controller.rb | 7 +++---- app/models/member.rb | 2 +- app/services/notification_service.rb | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/controllers/groups/notification_settings_controller.rb b/app/controllers/groups/notification_settings_controller.rb index 20405a05190..1b46f26a378 100644 --- a/app/controllers/groups/notification_settings_controller.rb +++ b/app/controllers/groups/notification_settings_controller.rb @@ -1,6 +1,6 @@ class Groups::NotificationSettingsController < Groups::ApplicationController def update - notification_setting = group.notification_settings.find_by(user_id: current_user) + notification_setting = current_user.notification_settings_for(group) saved = notification_setting.update_attributes(notification_setting_params) render json: { saved: saved } diff --git a/app/controllers/projects/notification_settings_controller.rb b/app/controllers/projects/notification_settings_controller.rb index da9034380af..90d294a4624 100644 --- a/app/controllers/projects/notification_settings_controller.rb +++ b/app/controllers/projects/notification_settings_controller.rb @@ -1,14 +1,13 @@ class Projects::NotificationSettingsController < Projects::ApplicationController def create - notification_setting = project.notification_settings.new(notification_setting_params) - notification_setting.user = current_user - saved = notification_setting.save + notification_setting = current_user.notification_settings_for(project) + saved = notification_setting.update_attributes(notification_setting_params) render json: { saved: saved } end def update - notification_setting = project.notification_settings.find_by(user_id: current_user) + notification_setting = current_user.notification_settings_for(project) saved = notification_setting.update_attributes(notification_setting_params) render json: { saved: saved } diff --git a/app/models/member.rb b/app/models/member.rb index 7d5af1d5c8a..60efafef211 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -167,7 +167,7 @@ class Member < ActiveRecord::Base end def notification_setting - @notification_setting ||= user.notification_settings.find_by(source: source) + @notification_setting ||= user.notification_settings_for(source) end private diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 0928dda349e..42ec1ac9e1a 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -355,10 +355,10 @@ class NotificationService users.reject do |user| next user.notification_level == level unless project - setting = user.notification_settings.find_by(source: project) + setting = user.notification_settings_for(project) if !setting && project.group - setting = user.notification_settings.find_by(source: project.group) + setting = user.notification_settings_for(project.group) end # reject users who globally set mention notification and has no setting per project/group -- cgit v1.2.1 From bee28e1785ad7844bd518c19106beee7d8a4c560 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 11 Apr 2016 18:57:18 -0300 Subject: Requires user to be signed in when changing notification settings --- app/controllers/groups/notification_settings_controller.rb | 2 ++ app/controllers/projects/notification_settings_controller.rb | 2 ++ 2 files changed, 4 insertions(+) (limited to 'app') diff --git a/app/controllers/groups/notification_settings_controller.rb b/app/controllers/groups/notification_settings_controller.rb index 1b46f26a378..de13b16ccf2 100644 --- a/app/controllers/groups/notification_settings_controller.rb +++ b/app/controllers/groups/notification_settings_controller.rb @@ -1,4 +1,6 @@ class Groups::NotificationSettingsController < Groups::ApplicationController + before_action :authenticate_user! + def update notification_setting = current_user.notification_settings_for(group) saved = notification_setting.update_attributes(notification_setting_params) diff --git a/app/controllers/projects/notification_settings_controller.rb b/app/controllers/projects/notification_settings_controller.rb index 90d294a4624..e536725c5b1 100644 --- a/app/controllers/projects/notification_settings_controller.rb +++ b/app/controllers/projects/notification_settings_controller.rb @@ -1,4 +1,6 @@ class Projects::NotificationSettingsController < Projects::ApplicationController + before_action :authenticate_user! + def create notification_setting = current_user.notification_settings_for(project) saved = notification_setting.update_attributes(notification_setting_params) -- cgit v1.2.1 From fe58c1f13cc0758bbbd8f85b8794b458b3a72b55 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 11 Apr 2016 19:29:31 -0300 Subject: Fix partial for update project notifications --- app/views/projects/buttons/_notifications.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index 2b9d8f2ac81..49f541399f2 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -1,5 +1,5 @@ - if @notification_setting - = form_for [@project.namespace.becomes(Namespace), @project, @notification_setting], remote: true, html: { class: 'inline', id: 'notification-form' } do |f| + = form_for @notification_setting, url: namespace_project_notification_setting_path(@project.namespace.becomes(Namespace), @project), remote: true, html: { class: 'inline', id: 'notification-form' } do |f| = f.hidden_field :level %span.dropdown %a.dropdown-new.btn.notifications-btn#notifications-button{href: '#', "data-toggle" => "dropdown"} -- cgit v1.2.1 From c162e0278cb845f6209e926d49474926b6a45956 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 11 Apr 2016 23:07:06 -0700 Subject: Check and report import job status to help diagnose issues with forking --- app/models/project.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 3e1f04b4158..6298dc8d1c8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -388,9 +388,15 @@ class Project < ActiveRecord::Base def add_import_job if forked? - RepositoryForkWorker.perform_async(self.id, forked_from_project.path_with_namespace, self.namespace.path) + job_id = RepositoryForkWorker.perform_async(self.id, forked_from_project.path_with_namespace, self.namespace.path) else - RepositoryImportWorker.perform_async(self.id) + job_id = RepositoryImportWorker.perform_async(self.id) + end + + if job_id + Rails.logger.info "Import job started for #{path_with_namespace} with job ID #{job_id}" + else + Rails.logger.error "Import job failed to start for #{path_with_namespace}" end end -- cgit v1.2.1 From a6ba94dbd109637b996246601f1bc2b62dc0a8d7 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 12 Apr 2016 09:32:12 +0100 Subject: Filtering by any label keeps the text on the toggle button --- app/assets/javascripts/labels_select.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/assets/javascripts/labels_select.js.coffee b/app/assets/javascripts/labels_select.js.coffee index d1fe116397a..90385621879 100644 --- a/app/assets/javascripts/labels_select.js.coffee +++ b/app/assets/javascripts/labels_select.js.coffee @@ -218,7 +218,7 @@ class @LabelsSelect selectable: true toggleLabel: (selected) -> - if selected and selected.title isnt 'Any Label' + if selected and selected.title? selected.title else defaultLabel -- cgit v1.2.1 From ef22b76b732c2bf4ce52b8a73570ac2921f9caa4 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 11 Apr 2016 19:33:26 -0300 Subject: Simplify Projects::NotificationSettingsController --- app/controllers/projects/notification_settings_controller.rb | 7 ------- app/views/projects/buttons/_notifications.html.haml | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'app') diff --git a/app/controllers/projects/notification_settings_controller.rb b/app/controllers/projects/notification_settings_controller.rb index e536725c5b1..7d81cc03c73 100644 --- a/app/controllers/projects/notification_settings_controller.rb +++ b/app/controllers/projects/notification_settings_controller.rb @@ -1,13 +1,6 @@ class Projects::NotificationSettingsController < Projects::ApplicationController before_action :authenticate_user! - def create - notification_setting = current_user.notification_settings_for(project) - saved = notification_setting.update_attributes(notification_setting_params) - - render json: { saved: saved } - end - def update notification_setting = current_user.notification_settings_for(project) saved = notification_setting.update_attributes(notification_setting_params) diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index 49f541399f2..c1e3e5b73a2 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -1,5 +1,5 @@ - if @notification_setting - = form_for @notification_setting, url: namespace_project_notification_setting_path(@project.namespace.becomes(Namespace), @project), remote: true, html: { class: 'inline', id: 'notification-form' } do |f| + = form_for @notification_setting, url: namespace_project_notification_setting_path(@project.namespace.becomes(Namespace), @project), method: :patch, remote: true, html: { class: 'inline', id: 'notification-form' } do |f| = f.hidden_field :level %span.dropdown %a.dropdown-new.btn.notifications-btn#notifications-button{href: '#', "data-toggle" => "dropdown"} -- cgit v1.2.1 From cba2c437e582dd5880ec45cc4ff2fccda2315ad5 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 11 Apr 2016 15:38:36 -0400 Subject: Move RepositoryArchiveCacheWorker to sidekiq-cron Closes #15105 --- app/controllers/projects/repositories_controller.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app') diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb index 5c7614cfbaf..bb7a6b6a5ab 100644 --- a/app/controllers/projects/repositories_controller.rb +++ b/app/controllers/projects/repositories_controller.rb @@ -11,7 +11,6 @@ class Projects::RepositoriesController < Projects::ApplicationController end def archive - RepositoryArchiveCacheWorker.perform_async headers.store(*Gitlab::Workhorse.send_git_archive(@project, params[:ref], params[:format])) head :ok rescue => ex -- cgit v1.2.1 From dca50ac1d4a6da5724b66643bcb18a4a2e3f5558 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 22 Mar 2016 11:33:38 +0000 Subject: Project dropdown in header uses new dropdown --- app/assets/javascripts/gl_dropdown.js.coffee | 4 +++- app/assets/javascripts/project_select.js.coffee | 32 +++++++++++++++++++++++++ app/assets/stylesheets/framework/header.scss | 5 ++++ app/helpers/projects_helper.rb | 14 ++--------- app/views/layouts/header/_default.html.haml | 2 ++ app/views/layouts/project.html.haml | 7 ++++++ 6 files changed, 51 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index ee1d0fad289..2dc37257e22 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -122,7 +122,9 @@ class GitLabDropdown FILTER_INPUT = '.dropdown-input .dropdown-input-field' constructor: (@el, @options) -> - @dropdown = $(@el).parent() + self = @ + selector = $(@el).data "target" + @dropdown = if selector? then $(selector) else $(@el).parent() # Set Defaults { diff --git a/app/assets/javascripts/project_select.js.coffee b/app/assets/javascripts/project_select.js.coffee index be8ab9b428d..704bd8dee53 100644 --- a/app/assets/javascripts/project_select.js.coffee +++ b/app/assets/javascripts/project_select.js.coffee @@ -1,5 +1,37 @@ class @ProjectSelect constructor: -> + $('.js-projects-dropdown-toggle').each (i, dropdown) -> + $dropdown = $(dropdown) + + $dropdown.glDropdown( + filterable: true + filterRemote: true + search: + fields: ['name_with_namespace'] + data: (term, callback) -> + finalCallback = (projects) -> + callback projects + + if @includeGroups + projectsCallback = (projects) -> + groupsCallback = (groups) -> + data = groups.concat(projects) + finalCallback(data) + + Api.groups term, false, groupsCallback + else + projectsCallback = finalCallback + + if @groupId + Api.groupProjects @groupId, term, projectsCallback + else + Api.projects term, @orderBy, projectsCallback + url: (project) -> + project.web_url + text: (project) -> + project.name_with_namespace + ) + $('.ajax-project-select').each (i, select) -> @groupId = $(select).data('group-id') @includeGroups = $(select).data('include-groups') diff --git a/app/assets/stylesheets/framework/header.scss b/app/assets/stylesheets/framework/header.scss index b3397d16016..3f015427d07 100644 --- a/app/assets/stylesheets/framework/header.scss +++ b/app/assets/stylesheets/framework/header.scss @@ -69,6 +69,7 @@ header { } .header-content { + position: relative; height: $header-height; padding-right: 20px; @@ -76,6 +77,10 @@ header { padding-right: 0; } + .dropdown-menu { + margin-top: -5px; + } + .title { margin: 0; font-size: 19px; diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 4e4c6e301d5..3621b943f3c 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -65,18 +65,8 @@ module ProjectsHelper link_to(simple_sanitize(owner.name), user_path(owner)) end - project_link = link_to project_path(project), { class: "project-item-select-holder" } do - link_output = simple_sanitize(project.name) - - if current_user - link_output += project_select_tag :project_path, - class: "project-item-select js-projects-dropdown", - data: { include_groups: false, order_by: 'last_activity_at' } - end - - link_output - end - project_link += icon "chevron-down", class: "dropdown-toggle-caret js-projects-dropdown-toggle" if current_user + project_link = link_to simple_sanitize(project.name), project_path(project), { class: "project-item-select-holder"} + project_link += icon "chevron-down", class: "dropdown-toggle-caret js-projects-dropdown-toggle", data: { target: ".header-content", toggle: "dropdown" } if current_user full_title = namespace_link + ' / ' + project_link full_title += ' · '.html_safe + link_to(simple_sanitize(name), url) if name diff --git a/app/views/layouts/header/_default.html.haml b/app/views/layouts/header/_default.html.haml index 0f3b8119379..44339293095 100644 --- a/app/views/layouts/header/_default.html.haml +++ b/app/views/layouts/header/_default.html.haml @@ -45,6 +45,8 @@ %h1.title= title + = yield :header_content + = render 'shared/outdated_browser' - if @project && !@project.empty_repo? diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index a7ef31acd3d..35be616b174 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -17,4 +17,11 @@ - content_for :scripts_body do = render "layouts/init_auto_complete" if current_user +- content_for :header_content do + .dropdown-menu.dropdown-select + = dropdown_title("Go to a project") + = dropdown_filter("Search your projects") + = dropdown_content + = dropdown_loading + = render template: "layouts/application" -- cgit v1.2.1 From f870857dddd7630dc19a77ded7784a2261e046e3 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 24 Mar 2016 16:28:46 +0000 Subject: Updated tests --- app/helpers/projects_helper.rb | 2 +- app/views/layouts/project.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 3621b943f3c..83ebc124171 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -65,7 +65,7 @@ module ProjectsHelper link_to(simple_sanitize(owner.name), user_path(owner)) end - project_link = link_to simple_sanitize(project.name), project_path(project), { class: "project-item-select-holder"} + project_link = link_to simple_sanitize(project.name), project_path(project), { class: "project-item-select-holder" } project_link += icon "chevron-down", class: "dropdown-toggle-caret js-projects-dropdown-toggle", data: { target: ".header-content", toggle: "dropdown" } if current_user full_title = namespace_link + ' / ' + project_link diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index 35be616b174..2c5911fa2fb 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -18,7 +18,7 @@ = render "layouts/init_auto_complete" if current_user - content_for :header_content do - .dropdown-menu.dropdown-select + .dropdown-menu.dropdown-select.dropdown-menu-projects = dropdown_title("Go to a project") = dropdown_filter("Search your projects") = dropdown_content -- cgit v1.2.1 From 6416f8eab17556871984118c2dde04714a52bdf6 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 4 Apr 2016 10:44:51 +0100 Subject: Updated based on Ruby feedback --- app/helpers/projects_helper.rb | 4 ++-- app/views/layouts/project.html.haml | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 83ebc124171..cc411da459f 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -66,10 +66,10 @@ module ProjectsHelper end project_link = link_to simple_sanitize(project.name), project_path(project), { class: "project-item-select-holder" } - project_link += icon "chevron-down", class: "dropdown-toggle-caret js-projects-dropdown-toggle", data: { target: ".header-content", toggle: "dropdown" } if current_user + project_link << icon("chevron-down", class: "dropdown-toggle-caret js-projects-dropdown-toggle", data: { target: ".js-dropdown-menu-projects", toggle: "dropdown" }) if current_user full_title = namespace_link + ' / ' + project_link - full_title += ' · '.html_safe + link_to(simple_sanitize(name), url) if name + full_title << ' · '.html_safe + link_to(simple_sanitize(name), url) if name full_title end diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index 2c5911fa2fb..6dfe7fbdae8 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -18,10 +18,11 @@ = render "layouts/init_auto_complete" if current_user - content_for :header_content do - .dropdown-menu.dropdown-select.dropdown-menu-projects - = dropdown_title("Go to a project") - = dropdown_filter("Search your projects") - = dropdown_content - = dropdown_loading + .js-dropdown-menu-projects + .dropdown-menu.dropdown-select.dropdown-menu-projects + = dropdown_title("Go to a project") + = dropdown_filter("Search your projects") + = dropdown_content + = dropdown_loading = render template: "layouts/application" -- cgit v1.2.1 From 4293485a22bfdbd2afdbb20dcf5d777f379fac87 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 7 Apr 2016 15:20:22 +0100 Subject: Updated Ruby Added CHANGELOG item --- app/helpers/projects_helper.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index cc411da459f..ab77853da1a 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -66,10 +66,13 @@ module ProjectsHelper end project_link = link_to simple_sanitize(project.name), project_path(project), { class: "project-item-select-holder" } - project_link << icon("chevron-down", class: "dropdown-toggle-caret js-projects-dropdown-toggle", data: { target: ".js-dropdown-menu-projects", toggle: "dropdown" }) if current_user - full_title = namespace_link + ' / ' + project_link - full_title << ' · '.html_safe + link_to(simple_sanitize(name), url) if name + if current_user + project_link << icon("chevron-down", class: "dropdown-toggle-caret js-projects-dropdown-toggle", data: { target: ".js-dropdown-menu-projects", toggle: "dropdown" }) + end + + full_title = namespace_link + ' / ' << project_link + full_title << ' · '.html_safe << link_to(simple_sanitize(name), url) if name full_title end -- cgit v1.2.1 From 63e54f1555f02b93347588fbf332c7521d19d2a6 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 8 Apr 2016 19:44:23 +0100 Subject: Updated based on Ruby feedback --- app/helpers/projects_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index ab77853da1a..7e00aacceaa 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -71,7 +71,7 @@ module ProjectsHelper project_link << icon("chevron-down", class: "dropdown-toggle-caret js-projects-dropdown-toggle", data: { target: ".js-dropdown-menu-projects", toggle: "dropdown" }) end - full_title = namespace_link + ' / ' << project_link + full_title = "#{namespace_link} / #{project_link}".html_safe full_title << ' · '.html_safe << link_to(simple_sanitize(name), url) if name full_title -- cgit v1.2.1 From a64f1c763615c049e551c82a9f3a7c53525a172c Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 12 Apr 2016 15:39:33 -0300 Subject: Add changelog entry, improve specs and model code --- app/models/merge_request.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 8292445bcac..e410febdfff 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -128,7 +128,7 @@ class MergeRequest < ActiveRecord::Base validates :target_project, presence: true validates :target_branch, presence: true validates :merge_user, presence: true, if: :merge_when_build_succeeds? - validate :validate_branches + validate :validate_branches, unless: :allow_broken validate :validate_fork scope :by_branch, ->(branch_name) { where("(source_branch LIKE :branch) OR (target_branch LIKE :branch)", branch: branch_name) } @@ -213,14 +213,12 @@ class MergeRequest < ActiveRecord::Base end def validate_branches - return if allow_broken - if target_project == source_project && target_branch == source_branch errors.add :branch_conflict, "You can not use same project/branch for source and target" end if opened? || reopened? - similar_mrs = self.target_project.merge_requests.where(source_branch: source_branch, target_branch: target_branch, source_project_id: source_project.id).opened + similar_mrs = self.target_project.merge_requests.where(source_branch: source_branch, target_branch: target_branch, source_project_id: source_project.try(:id)).opened similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id if similar_mrs.any? errors.add :validate_branches, @@ -346,12 +344,9 @@ class MergeRequest < ActiveRecord::Base end def hook_attrs - source_hook_attrs = source_project.hook_attrs if source_project.present? - target_hook_attrs = target_project.hook_attrs if target_project.present? - attrs = { - source: source_hook_attrs, - target: target_hook_attrs, + source: source_project.try(:hook_attrs), + target: target_project.hook_attrs, last_commit: nil, work_in_progress: work_in_progress? } -- cgit v1.2.1 From 447f3613b78ac4ba4ad6bda1811447b48e126b0c Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Fri, 8 Apr 2016 15:48:18 -0700 Subject: Wrap text in notes box if longer than code in diff --- app/assets/stylesheets/pages/notes.scss | 1 + 1 file changed, 1 insertion(+) (limited to 'app') diff --git a/app/assets/stylesheets/pages/notes.scss b/app/assets/stylesheets/pages/notes.scss index 7295fe51121..88ba5e53a0d 100644 --- a/app/assets/stylesheets/pages/notes.scss +++ b/app/assets/stylesheets/pages/notes.scss @@ -155,6 +155,7 @@ ul.notes { border-width: 1px 0; padding: 0; vertical-align: top; + white-space: normal; &.parallel { border-width: 1px; } -- cgit v1.2.1 From d3ff7ca0846a88961d3f954c62398c54aa69c059 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Mon, 11 Apr 2016 10:00:45 -0500 Subject: Input updates --- app/assets/stylesheets/pages/merge_requests.scss | 1 + app/assets/stylesheets/pages/note_form.scss | 22 ++++++++++++++++- app/assets/stylesheets/pages/notes.scss | 31 +++++++++++++++++++++--- 3 files changed, 49 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index b79335eab91..4ef548ffbe7 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -142,6 +142,7 @@ overflow: hidden; font-size: 90%; margin: 0 3px; + word-break: break-all; } .mr-list { diff --git a/app/assets/stylesheets/pages/note_form.scss b/app/assets/stylesheets/pages/note_form.scss index 4d4d508396d..5e5722c2c33 100644 --- a/app/assets/stylesheets/pages/note_form.scss +++ b/app/assets/stylesheets/pages/note_form.scss @@ -16,6 +16,7 @@ .new-note { margin: 0; border: none; + border-right: 1px solid $table-border-gray; } } @@ -71,12 +72,25 @@ border-color: $focus-border-color; } } + + p { + code { + white-space: normal; + } + + pre { + code { + white-space: pre; + } + } + } } } .discussion-form { padding: $gl-padding-top $gl-padding; - background-color: #fff; + background-color: $white-light; + border-right: 1px solid $table-border-gray; } .note-edit-form { @@ -118,7 +132,13 @@ .discussion-reply-holder { background-color: $white-light; + border-right: 1px solid $table-border-gray; padding: 10px 16px; + max-width: 800px; + + .new-note { + border-right: none; + } } } diff --git a/app/assets/stylesheets/pages/notes.scss b/app/assets/stylesheets/pages/notes.scss index 88ba5e53a0d..07dd0292453 100644 --- a/app/assets/stylesheets/pages/notes.scss +++ b/app/assets/stylesheets/pages/notes.scss @@ -81,9 +81,15 @@ ul.notes { @include md-typography; // On diffs code should wrap nicely and not overflow - pre { + p { code { - white-space: pre; + white-space: normal; + } + + pre { + code { + white-space: pre; + } } } @@ -112,6 +118,10 @@ ul.notes { margin: 10px 0; } } + + a { + word-break: break-all; + } } .note-header { @@ -127,7 +137,7 @@ ul.notes { margin-right: 10px; } .line_content { - white-space: pre-wrap; + white-space: pre; } } @@ -145,20 +155,33 @@ ul.notes { background: $background-color; color: $text-color; } + &.notes_line2 { text-align: center; padding: 10px 0; border-left: 1px solid #ddd !important; } + &.notes_content { - background-color: #fff; + background-color: $background-color; border-width: 1px 0; padding: 0; vertical-align: top; white-space: normal; + &.parallel { border-width: 1px; } + + .new-note { + max-width: 800px; + } + + .notes { + max-width: 800px; + background-color: $white-light; + border-right: 1px solid $table-border-gray; + } } } } -- cgit v1.2.1 From 60736db429666f4145004408b722799ef144eb5f Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Tue, 12 Apr 2016 15:07:24 -0500 Subject: Remove max-width from comments --- app/assets/stylesheets/pages/note_form.scss | 8 -------- app/assets/stylesheets/pages/notes.scss | 6 ------ 2 files changed, 14 deletions(-) (limited to 'app') diff --git a/app/assets/stylesheets/pages/note_form.scss b/app/assets/stylesheets/pages/note_form.scss index 5e5722c2c33..f4da17fadaa 100644 --- a/app/assets/stylesheets/pages/note_form.scss +++ b/app/assets/stylesheets/pages/note_form.scss @@ -16,7 +16,6 @@ .new-note { margin: 0; border: none; - border-right: 1px solid $table-border-gray; } } @@ -90,7 +89,6 @@ .discussion-form { padding: $gl-padding-top $gl-padding; background-color: $white-light; - border-right: 1px solid $table-border-gray; } .note-edit-form { @@ -132,13 +130,7 @@ .discussion-reply-holder { background-color: $white-light; - border-right: 1px solid $table-border-gray; padding: 10px 16px; - max-width: 800px; - - .new-note { - border-right: none; - } } } diff --git a/app/assets/stylesheets/pages/notes.scss b/app/assets/stylesheets/pages/notes.scss index 07dd0292453..e421a31549a 100644 --- a/app/assets/stylesheets/pages/notes.scss +++ b/app/assets/stylesheets/pages/notes.scss @@ -173,14 +173,8 @@ ul.notes { border-width: 1px; } - .new-note { - max-width: 800px; - } - .notes { - max-width: 800px; background-color: $white-light; - border-right: 1px solid $table-border-gray; } } } -- cgit v1.2.1 From 6a238c37e002c9d8dcc51af2cb3dff44c900139c Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Tue, 12 Apr 2016 18:06:52 -0300 Subject: Fix todo_target_path for todos where target was removed --- app/assets/javascripts/todos.js.coffee | 2 ++ app/helpers/todos_helper.rb | 2 ++ 2 files changed, 4 insertions(+) (limited to 'app') diff --git a/app/assets/javascripts/todos.js.coffee b/app/assets/javascripts/todos.js.coffee index 886da72e261..00d2b641723 100644 --- a/app/assets/javascripts/todos.js.coffee +++ b/app/assets/javascripts/todos.js.coffee @@ -59,6 +59,8 @@ class @Todos goToTodoUrl: (e)-> todoLink = $(this).data('url') + return unless todoLink + if e.metaKey e.preventDefault() window.open(todoLink,'_blank') diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index edc5686cf08..2f066682180 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -20,6 +20,8 @@ module TodosHelper end def todo_target_path(todo) + return unless todo.target.present? + anchor = dom_id(todo.note) if todo.note.present? if todo.for_commit? -- cgit v1.2.1 From d8296f873871120b7f4134bdcf8854a09b9e8be8 Mon Sep 17 00:00:00 2001 From: connorshea Date: Tue, 12 Apr 2016 16:11:58 -0600 Subject: Remove Bootstrap Carousel The Bootstrap carousel module is used for image carousels, and we don't use it anywhere on the site. Also separated the Bootstrap JavaScript into separate components and removed the carousel component. Fixes #14670. --- app/assets/javascripts/application.js.coffee | 12 +++++++++++- app/assets/stylesheets/framework/tw_bootstrap.scss | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index b05138ac1ac..6f435e4c542 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -22,7 +22,17 @@ #= require cal-heatmap #= require turbolinks #= require autosave -#= require bootstrap +#= require bootstrap/affix +#= require bootstrap/alert +#= require bootstrap/button +#= require bootstrap/collapse +#= require bootstrap/dropdown +#= require bootstrap/modal +#= require bootstrap/scrollspy +#= require bootstrap/tab +#= require bootstrap/transition +#= require bootstrap/tooltip +#= require bootstrap/popover #= require select2 #= require raphael #= require g.raphael diff --git a/app/assets/stylesheets/framework/tw_bootstrap.scss b/app/assets/stylesheets/framework/tw_bootstrap.scss index dd42db1840f..96bab7880c2 100644 --- a/app/assets/stylesheets/framework/tw_bootstrap.scss +++ b/app/assets/stylesheets/framework/tw_bootstrap.scss @@ -43,7 +43,6 @@ @import "bootstrap/modals"; @import "bootstrap/tooltip"; @import "bootstrap/popovers"; -@import "bootstrap/carousel"; // Utility classes .clearfix { -- cgit v1.2.1 From 2ce7559d70e228963280df1f50176e9b2fa1e7b8 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 13 Apr 2016 00:00:15 -0700 Subject: Fix repository cache invalidation issue when project is recreated with an empty repo To reproduce: 1. Create a project with some content 2. Rename the project 3. Create a new project with the same name. 4. Boom - 404. After step 2, the branch and tag counts were not being cleared. This would cause `repository.has_visible_content?` to erroneously return `true` for the newly-created project. Closes #13384 --- app/models/repository.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app') diff --git a/app/models/repository.rb b/app/models/repository.rb index 462b48118ef..0b2289cfa39 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -253,6 +253,8 @@ class Repository # This ensures this particular cache is flushed after the first commit to a # new repository. expire_emptiness_caches if empty? + expire_branch_count_cache + expire_tag_count_cache end def expire_branch_cache(branch_name = nil) -- cgit v1.2.1 From 3b9edce803c91b5f51675291fdf22f1159cea456 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 13 Apr 2016 15:19:50 +0200 Subject: Instrument the HousekeepingService class This allows us to track how much time is spent in updating the "pushes_since_gc" column as well as the time needed to obtain the lease. --- app/services/projects/housekeeping_service.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/services/projects/housekeeping_service.rb b/app/services/projects/housekeeping_service.rb index a0973c5d260..3b7c36f0908 100644 --- a/app/services/projects/housekeeping_service.rb +++ b/app/services/projects/housekeeping_service.rb @@ -26,7 +26,9 @@ module Projects GitlabShellOneShotWorker.perform_async(:gc, @project.path_with_namespace) ensure - @project.update_column(:pushes_since_gc, 0) + Gitlab::Metrics.measure(:reset_pushes_since_gc) do + @project.update_column(:pushes_since_gc, 0) + end end def needed? @@ -34,14 +36,18 @@ module Projects end def increment! - @project.increment!(:pushes_since_gc) + Gitlab::Metrics.measure(:increment_pushes_since_gc) do + @project.increment!(:pushes_since_gc) + end end private def try_obtain_lease - lease = ::Gitlab::ExclusiveLease.new("project_housekeeping:#{@project.id}", timeout: LEASE_TIMEOUT) - lease.try_obtain + Gitlab::Metrics.measure(:obtain_housekeeping_lease) do + lease = ::Gitlab::ExclusiveLease.new("project_housekeeping:#{@project.id}", timeout: LEASE_TIMEOUT) + lease.try_obtain + end end end end -- cgit v1.2.1