This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

update_context.rb 861 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Projects
  class UpdateContext < BaseContext
    def execute(role = :default)
      namespace_id = params[:project].delete(:namespace_id)
      params[:project].delete(:public) unless can?(current_user, :change_public_mode, project)

      allowed_transfer = can?(current_user, :change_namespace, project) || role == :admin

      if allowed_transfer && namespace_id.present?
        if namespace_id == Namespace.global_id
          if project.namespace.present?
            # Transfer to global namespace from anyone
            project.transfer(nil)
          end
        elsif namespace_id.to_i != project.namespace_id
          # Transfer to someone namespace
          namespace = Namespace.find(namespace_id)
          project.transfer(namespace)
        end
      end

      project.update_attributes(params[:project], as: role)
    end
  end
end