-
Notifications
You must be signed in to change notification settings - Fork 441
/
source_project_controller.rb
116 lines (99 loc) · 3.8 KB
/
source_project_controller.rb
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
class SourceProjectController < SourceController
# GET /source/:project
def show
project_name = params[:project]
if params.key?(:deleted)
unless Project.find_by_name(project_name)
# project is deleted or not accessable
validate_visibility_of_deleted_project(project_name)
end
pass_to_backend
return
end
if Project.is_remote_project?(project_name)
# not a local project, hand over to backend
pass_to_backend
return
end
@project = Project.find_by_name(project_name)
raise Project::UnknownObjectError, "Project not found: #{project_name}" unless @project
# we let the backend list the packages after we verified the project is visible
if params.key?(:view)
case params[:view]
when 'verboseproductlist'
@products = Product.all_products(@project, params[:expand])
render 'source/verboseproductlist'
return
when 'productlist'
@products = Product.all_products(@project, params[:expand])
render 'source/productlist'
return
when 'issues'
render_project_issues
else
pass_to_backend
end
return
end
render_project_packages
end
def render_project_issues
set_issues_default
render partial: 'source/project_issues'
end
def render_project_packages
@packages = params.key?(:expand) ? @project.expand_all_packages : @project.packages.pluck(:name)
render locals: { expand: params.key?(:expand) }, formats: [:xml]
end
# DELETE /source/:project
def delete
project = Project.get_by_name(params[:project])
# checks
unless project.is_a?(Project) && User.session!.can_modify?(project)
logger.debug "No permission to delete project #{project}"
render_error status: 403, errorcode: 'delete_project_no_permission',
message: "Permission denied (delete project #{project})"
return
end
project.check_weak_dependencies!
opts = { no_write_to_backend: true,
force: params[:force].present?,
recursive_remove: params[:remove_linking_repositories].present? }
check_and_remove_repositories!(project.repositories, opts)
logger.info "destroying project object #{project.name}"
project.commit_opts = { comment: params[:comment] }
begin
project.destroy
rescue ActiveRecord::RecordNotDestroyed => e
exception_message = "Destroying Project #{project.name} failed: #{e.record.errors.full_messages.to_sentence}"
logger.debug exception_message
raise ActiveRecord::RecordNotDestroyed, exception_message
end
render_ok
end
# POST /source/:project?cmd
#-----------------
def project_command
# init and validation
#--------------------
required_parameters(:cmd)
valid_commands = ['undelete', 'showlinked', 'remove_flag', 'set_flag', 'createpatchinfo',
'createkey', 'extendkey', 'copy', 'createmaintenanceincident', 'lock',
'unlock', 'release', 'addchannels', 'modifychannels', 'move', 'freezelink']
raise IllegalRequest, 'invalid_command' unless valid_commands.include?(params[:cmd])
command = params[:cmd]
project_name = params[:project]
params[:user] = User.session!.login
return dispatch_command(:project_command, command) if command.in?(['undelete', 'release', 'copy', 'move'])
@project = Project.get_by_name(project_name)
# unlock
if command == 'unlock' && User.session!.can_modify?(@project, true)
dispatch_command(:project_command, command)
elsif command == 'showlinked' || User.session!.can_modify?(@project)
# command: showlinked, set_flag, remove_flag, ...?
dispatch_command(:project_command, command)
else
raise CmdExecutionNoPermission, "no permission to execute command '#{command}'"
end
end
end