2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
module Groups
class UpdateService < Groups :: BaseService
2018-03-17 18:26:18 +05:30
include UpdateVisibilityLevel
2016-06-02 11:05:42 +05:30
def execute
2017-08-17 22:00:37 +05:30
reject_parent_id!
2019-07-07 11:18:12 +05:30
remove_unallowed_params
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
return false unless valid_visibility_level_change? ( group , params [ :visibility_level ] )
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
return false unless valid_share_with_group_lock_change?
2016-06-02 11:05:42 +05:30
2019-03-02 22:35:43 +05:30
before_assignment_hook ( group , params )
2016-06-02 11:05:42 +05:30
group . assign_attributes ( params )
2017-08-17 22:00:37 +05:30
begin
2018-12-13 13:39:08 +05:30
success = group . save
2018-11-18 11:00:15 +05:30
2018-12-13 13:39:08 +05:30
after_update if success
success
2017-08-17 22:00:37 +05:30
rescue Gitlab :: UpdatePathError = > e
group . errors . add ( :base , e . message )
false
end
end
private
2019-03-02 22:35:43 +05:30
def before_assignment_hook ( group , params )
2019-07-07 11:18:12 +05:30
# overridden in EE
2019-03-02 22:35:43 +05:30
end
2018-11-18 11:00:15 +05:30
def after_update
if group . previous_changes . include? ( :visibility_level ) && group . private?
# don't enqueue immediately to prevent todos removal in case of a mistake
2019-01-03 12:48:30 +05:30
TodosDestroyer :: GroupPrivateWorker . perform_in ( Todo :: WAIT_FOR_DELETE , group . id )
2018-11-18 11:00:15 +05:30
end
end
2017-08-17 22:00:37 +05:30
def reject_parent_id!
2019-02-15 15:39:39 +05:30
params . delete ( :parent_id )
2016-06-02 11:05:42 +05:30
end
2018-03-17 18:26:18 +05:30
2019-10-12 21:52:04 +05:30
# overridden in EE
def remove_unallowed_params
params . delete ( :emails_disabled ) unless can? ( current_user , :set_emails_disabled , group )
end
2018-03-17 18:26:18 +05:30
def valid_share_with_group_lock_change?
return true unless changing_share_with_group_lock?
return true if can? ( current_user , :change_share_with_group_lock , group )
group . errors . add ( :share_with_group_lock , s_ ( 'GroupSettings|cannot be disabled when the parent group "Share with group lock" is enabled, except by the owner of the parent group' ) )
false
end
def changing_share_with_group_lock?
return false if params [ :share_with_group_lock ] . nil?
params [ :share_with_group_lock ] != group . share_with_group_lock
end
2016-06-02 11:05:42 +05:30
end
end
2019-12-04 20:38:33 +05:30
Groups :: UpdateService . prepend_if_ee ( 'EE::Groups::UpdateService' )