diff options
Diffstat (limited to 'app/services/groups')
-rw-r--r-- | app/services/groups/base_service.rb | 9 | ||||
-rw-r--r-- | app/services/groups/create_service.rb | 21 | ||||
-rw-r--r-- | app/services/groups/update_service.rb | 20 |
3 files changed, 50 insertions, 0 deletions
diff --git a/app/services/groups/base_service.rb b/app/services/groups/base_service.rb new file mode 100644 index 00000000000..a8fa098246a --- /dev/null +++ b/app/services/groups/base_service.rb @@ -0,0 +1,9 @@ +module Groups + class BaseService < ::BaseService + attr_accessor :group, :current_user, :params + + def initialize(group, user, params = {}) + @group, @current_user, @params = group, user, params.dup + end + end +end diff --git a/app/services/groups/create_service.rb b/app/services/groups/create_service.rb new file mode 100644 index 00000000000..2bccd584dde --- /dev/null +++ b/app/services/groups/create_service.rb @@ -0,0 +1,21 @@ +module Groups + class CreateService < Groups::BaseService + def initialize(user, params = {}) + @current_user, @params = user, params.dup + end + + def execute + @group = Group.new(params) + + unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level]) + deny_visibility_level(@group) + return @group + end + + @group.name ||= @group.path.dup + @group.save + @group.add_owner(current_user) + @group + end + end +end diff --git a/app/services/groups/update_service.rb b/app/services/groups/update_service.rb new file mode 100644 index 00000000000..99ad12b1003 --- /dev/null +++ b/app/services/groups/update_service.rb @@ -0,0 +1,20 @@ +module Groups + class UpdateService < Groups::BaseService + def execute + # check that user is allowed to set specified visibility_level + new_visibility = params[:visibility_level] + if new_visibility && new_visibility.to_i != group.visibility_level + unless can?(current_user, :change_visibility_level, group) && + Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility) + + deny_visibility_level(group, new_visibility) + return group + end + end + + group.assign_attributes(params) + + group.save + end + end +end |