]>
Commit | Line | Data |
---|---|---|
f6e6ff79 MT |
1 | #!/usr/bin/python |
2 | ||
3 | import tornado.web | |
4 | ||
2c909128 | 5 | from .handlers_base import BaseHandler |
f6e6ff79 MT |
6 | |
7 | class BuildsHandler(BaseHandler): | |
8 | def get(self): | |
eedc6432 MT |
9 | limit = self.get_argument("limit", None) |
10 | try: | |
11 | limit = int(limit) | |
12 | except (TypeError, ValueError): | |
13 | limit = 25 | |
14 | ||
15 | builds = self.pakfire.builds.get_all(limit=limit) | |
f6e6ff79 MT |
16 | |
17 | self.render("build-index.html", builds=builds) | |
18 | ||
19 | ||
20 | class BuildBaseHandler(BaseHandler): | |
21 | def get_build(self, uuid): | |
22 | build = self.pakfire.builds.get_by_uuid(uuid) | |
23 | if not build: | |
24 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
25 | ||
26 | return build | |
27 | ||
28 | ||
29 | class BuildDetailHandler(BuildBaseHandler): | |
30 | def get(self, uuid): | |
31 | build = self.get_build(uuid) | |
32 | ||
33 | # Cache the log. | |
34 | log = build.get_log() | |
35 | ||
36 | if build.repo: | |
d629da45 | 37 | next_repo = build.repo.next |
f6e6ff79 MT |
38 | else: |
39 | next_repo = None | |
40 | ||
41 | # Bugs. | |
42 | bugs = build.get_bugs() | |
43 | ||
44 | self.render("build-detail.html", build=build, log=log, pkg=build.pkg, | |
45 | distro=build.distro, bugs=bugs, repo=build.repo, next_repo=next_repo) | |
46 | ||
47 | ||
48 | class BuildDeleteHandler(BuildBaseHandler): | |
49 | @tornado.web.authenticated | |
50 | def get(self, uuid): | |
51 | build = self.get_build(uuid) | |
52 | ||
53 | # Check if the user has got sufficient rights to do this modification. | |
54 | if not build.has_perm(self.current_user): | |
55 | raise tornado.web.HTTPError(403) | |
56 | ||
57 | # Check if the user confirmed the action. | |
58 | confirmed = self.get_argument("confirmed", None) | |
59 | if confirmed: | |
60 | # Save the name of the package to redirect the user | |
61 | # to the other packages of that name. | |
62 | package_name = build.pkg.name | |
63 | ||
64 | # Delete the build and everything that comes with it. | |
65 | build.delete() | |
66 | ||
67 | return self.redirect("/package/%s" % package_name) | |
68 | ||
69 | self.render("build-delete.html", build=build) | |
70 | ||
71 | ||
72 | class BuildBugsHandler(BaseHandler): | |
73 | @tornado.web.authenticated | |
74 | def get(self, uuid): | |
75 | build = self.pakfire.builds.get_by_uuid(uuid) | |
76 | if not build: | |
77 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
78 | ||
79 | # Check if the user has got the right to alter this build. | |
80 | if not build.has_perm(self.current_user): | |
81 | raise tornado.web.HTTPError(403) | |
82 | ||
83 | # Bugs. | |
84 | fixed_bugs = build.get_bugs() | |
85 | open_bugs = [] | |
86 | ||
87 | for bug in self.pakfire.bugzilla.get_bugs_from_component(build.pkg.name): | |
88 | if bug in fixed_bugs: | |
89 | continue | |
90 | ||
91 | open_bugs.append(bug) | |
92 | ||
93 | self.render("build-bugs.html", build=build, pkg=build.pkg, | |
94 | fixed_bugs=fixed_bugs, open_bugs=open_bugs) | |
95 | ||
96 | @tornado.web.authenticated | |
97 | def post(self, uuid): | |
98 | build = self.pakfire.builds.get_by_uuid(uuid) | |
99 | if not build: | |
100 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
101 | ||
102 | # Check if the user has got the right to alter this build. | |
103 | if not build.has_perm(self.current_user): | |
104 | raise tornado.web.HTTPError(403) | |
105 | ||
106 | action = self.get_argument("action", None) | |
107 | bugid = self.get_argument("bugid") | |
108 | ||
109 | # Convert the bug id to integer. | |
110 | try: | |
111 | bugid = int(bugid) | |
112 | except ValueError: | |
113 | raise tornado.web.HTTPError(400, "Bad bug id given: %s" % bugid) | |
114 | ||
115 | if action == "add": | |
116 | # Add bug to the build. | |
117 | build.add_bug(bugid, user=self.current_user) | |
118 | ||
119 | elif action == "remove": | |
120 | # Remove bug from the build. | |
121 | build.rem_bug(bugid, user=self.current_user) | |
122 | ||
123 | else: | |
124 | raise tornado.web.HTTPError(400, "Unhandled action: %s" % action) | |
125 | ||
126 | self.redirect("/build/%s/bugs" % build.uuid) | |
127 | ||
128 | ||
62c7e7cd MT |
129 | class BuildsCommentsHandler(BaseHandler): |
130 | def get(self, user_name=None): | |
131 | user = None | |
132 | if user_name: | |
133 | user = self.pakfire.users.get_by_name(user_name) | |
134 | ||
135 | limit = self.get_argument("limit", 10) | |
136 | offset = self.get_argument("offset", 0) | |
137 | ||
138 | try: | |
139 | limit = int(limit) | |
140 | offset = int(offset) | |
141 | except: | |
142 | raise tornado.web.HTTPError(400) | |
143 | ||
144 | # Try to get one more comment than requested and check if there | |
145 | # is a next page that it to be shown. | |
146 | comments = self.pakfire.builds.get_comments(limit=limit + 1, | |
147 | offset=offset, user=user) | |
148 | ||
149 | # Set markers for next and prev pages. | |
150 | have_next = len(comments) > limit | |
151 | have_prev = offset > limit | |
152 | ||
153 | # Remove the extra element from the list. | |
154 | comments = comments[:limit] | |
155 | ||
156 | self.render("builds/comments.html", comments=comments, limit=limit, | |
157 | offset=offset + limit, user=user, have_prev=have_prev, have_next=have_next) | |
158 | ||
159 | ||
f6e6ff79 MT |
160 | class BuildStateHandler(BaseHandler): |
161 | def get(self, uuid): | |
162 | build = self.pakfire.builds.get_by_uuid(uuid) | |
163 | if not build: | |
164 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
165 | ||
166 | self.render("build-state.html", build=build) | |
167 | ||
168 | @tornado.web.authenticated | |
169 | def post(self, uuid): | |
170 | build = self.pakfire.builds.get_by_uuid(uuid) | |
171 | if not build: | |
172 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
173 | ||
174 | # Check if user has the right to perform this action. | |
175 | if not build.has_perm(self.current_user): | |
176 | raise tornado.web.HTTPError(403, "User is not allowed to perform this action") | |
177 | ||
178 | # Check if given state is valid. | |
179 | state = self.get_argument("state", None) | |
180 | if not state in ("broken", "unbreak", "obsolete"): | |
181 | raise tornado.web.HTTPError(400, "Invalid argument given: %s" % state) | |
182 | ||
183 | # XXX this is not quite accurate | |
184 | if state == "unbreak": | |
185 | state = "stable" | |
186 | ||
187 | rem_from_repo = self.get_argument("rem_from_repo", False) | |
188 | if rem_from_repo == "on": | |
189 | rem_from_repo = True | |
190 | ||
191 | # Perform the state change. | |
192 | build.update_state(state, user=self.current_user, remove=rem_from_repo) | |
193 | ||
194 | self.redirect("/build/%s" % build.uuid) | |
195 | ||
196 | ||
197 | class BuildQueueHandler(BaseHandler): | |
198 | def get(self): | |
fd43d5e1 | 199 | self.render("build-queue.html", jobs=self.backend.jobqueue) |
f6e6ff79 MT |
200 | |
201 | ||
202 | class BuildDetailCommentHandler(BaseHandler): | |
203 | @tornado.web.authenticated | |
204 | def post(self, uuid): | |
205 | build = self.pakfire.builds.get_by_uuid(uuid) | |
206 | ||
207 | if not build: | |
208 | raise tornado.web.HTTPError(404, "Build not found") | |
209 | ||
210 | vote = self.get_argument("vote", "none") | |
211 | ||
212 | if vote == "up": | |
213 | vote = 1 | |
214 | elif vote == "down": | |
215 | vote = -1 | |
216 | else: | |
217 | vote = 0 | |
218 | ||
219 | text = self.get_argument("text", "") | |
220 | ||
221 | # Add a new comment to the build. | |
222 | if text or vote: | |
223 | build.add_comment(self.current_user, text, vote) | |
224 | ||
225 | # Redirect to the build detail page. | |
226 | self.redirect("/build/%s" % build.uuid) | |
227 | ||
228 | ||
229 | class BuildManageHandler(BaseHandler): | |
230 | @tornado.web.authenticated | |
231 | def get(self, uuid): | |
232 | build = self.pakfire.builds.get_by_uuid(uuid) | |
233 | if not build: | |
234 | raise tornado.web.HTTPError(404, "Build not found: %s" % uuid) | |
235 | ||
236 | mode = "user" | |
237 | if self.current_user.is_admin(): | |
238 | mode = self.get_argument("mode", "user") | |
239 | ||
240 | # Get the next repo. | |
241 | if build.repo: | |
d629da45 | 242 | next_repo = build.repo.next |
f6e6ff79 MT |
243 | else: |
244 | next_repo = build.distro.first_repo | |
245 | ||
246 | self.render("build-manage.html", mode=mode, build=build, | |
247 | distro=build.distro, repo=build.repo, next_repo=next_repo) | |
248 | ||
249 | @tornado.web.authenticated | |
250 | def post(self, uuid): | |
251 | build = self.pakfire.builds.get_by_uuid(uuid) | |
252 | if not build: | |
253 | raise tornado.web.HTTPError(404, "Build not found: %s" % uuid) | |
254 | ||
255 | # check for sufficient permissions | |
256 | if not build.has_perm(self.current_user): | |
257 | raise tornado.web.HTTPError(403) | |
258 | ||
259 | action = self.get_argument("action") | |
260 | assert action in ("push", "unpush") | |
261 | ||
262 | current_repo = build.repo | |
263 | ||
264 | if action == "unpush": | |
265 | current_repo.rem_build(build, user=self.current_user) | |
266 | ||
267 | elif action == "push": | |
268 | repo_name = self.get_argument("repo") | |
269 | next_repo = build.distro.get_repo(repo_name) | |
270 | ||
271 | if not next_repo: | |
272 | raise tornado.web.HTTPError(404, "No such repository: %s" % next_repo) | |
273 | ||
274 | if not self.current_user.is_admin(): | |
d629da45 | 275 | if not distro.repo.next == next_repo: |
f6e6ff79 MT |
276 | raise tornado.web.HTTPError(403) |
277 | ||
278 | if current_repo: | |
279 | current_repo.move_build(build, next_repo, user=self.current_user) | |
280 | else: | |
281 | next_repo.add_build(build, user=self.current_user) | |
282 | ||
283 | self.redirect("/build/%s" % build.uuid) | |
284 | ||
285 | ||
286 | class BuildPriorityHandler(BaseHandler): | |
287 | @tornado.web.authenticated | |
288 | def get(self, uuid): | |
289 | build = self.pakfire.builds.get_by_uuid(uuid) | |
290 | ||
291 | if not build: | |
292 | raise tornado.web.HTTPError(404, "Build not found") | |
293 | ||
294 | self.render("build-priority.html", build=build) | |
295 | ||
296 | @tornado.web.authenticated | |
297 | def post(self, uuid): | |
298 | build = self.pakfire.builds.get_by_uuid(uuid) | |
299 | ||
300 | if not build: | |
301 | raise tornado.web.HTTPError(404, "Build not found") | |
302 | ||
303 | # Get the priority from the request data and convert it to an integer. | |
304 | # If that cannot be done, we default to zero. | |
305 | prio = self.get_argument("priority") | |
306 | try: | |
307 | prio = int(prio) | |
308 | except TypeError: | |
309 | prio = 0 | |
310 | ||
311 | # Check if the value is in a valid range. | |
312 | if not prio in (-2, -1, 0, 1, 2): | |
313 | prio = 0 | |
314 | ||
315 | # Save priority. | |
316 | build.priority = prio | |
317 | ||
318 | self.redirect("/build/%s" % build.uuid) | |
319 | ||
320 | ||
321 | class BuildWatchersHandler(BaseHandler): | |
322 | def get(self, uuid): | |
323 | build = self.pakfire.builds.get_by_uuid(uuid) | |
324 | ||
325 | if not build: | |
326 | raise tornado.web.HTTPError(404, "Build not found") | |
327 | ||
328 | # Get a list of all watchers and sort them by their realname. | |
329 | watchers = build.get_watchers() | |
330 | watchers.sort(key=lambda watcher: watcher.realname) | |
331 | ||
332 | self.render("builds-watchers-list.html", build=build, watchers=watchers) | |
333 | ||
334 | ||
335 | class BuildWatchersAddHandler(BaseHandler): | |
336 | @tornado.web.authenticated | |
337 | def get(self, uuid, error_msg=None): | |
338 | build = self.pakfire.builds.get_by_uuid(uuid) | |
339 | ||
340 | if not build: | |
341 | raise tornado.web.HTTPError(404, "Build not found") | |
342 | ||
343 | # Get a list of all users that are currently watching this build. | |
344 | watchers = build.get_watchers() | |
345 | ||
346 | self.render("builds-watchers-add.html", error_msg=error_msg, | |
347 | build=build, users=self.pakfire.users.get_all(), watchers=watchers) | |
348 | ||
349 | @tornado.web.authenticated | |
350 | def post(self, uuid): | |
351 | build = self.pakfire.builds.get_by_uuid(uuid) | |
352 | ||
353 | if not build: | |
354 | raise tornado.web.HTTPError(404, "Build not found") | |
355 | ||
356 | # Get the user id of the new watcher. | |
357 | user_id = self.current_user.id | |
358 | ||
359 | if self.current_user.is_admin(): | |
360 | user_id = self.get_argument("user_id", self.current_user.id) | |
361 | assert user_id | |
362 | ||
363 | user = self.pakfire.users.get_by_id(user_id) | |
364 | if not user: | |
365 | _ = self.locale.translate | |
366 | error_msg = _("User not found.") | |
367 | ||
368 | return self.get(uuid, error_msg=error_msg) | |
369 | ||
370 | # Actually add the user to the list of watchers. | |
371 | build.add_watcher(user) | |
372 | ||
373 | # Send user back to the build detail page. | |
374 | self.redirect("/build/%s" % build.uuid) | |
375 | ||
376 | ||
377 | class BuildListHandler(BaseHandler): | |
378 | def get(self): | |
379 | builder = self.get_argument("builder", None) | |
380 | state = self.get_argument("state", None) | |
381 | ||
382 | builds = self.pakfire.builds.get_latest(state=state, builder=builder, | |
383 | limit=25) | |
384 | ||
385 | self.render("build-list.html", builds=builds) | |
386 | ||
387 | ||
388 | class BuildFilterHandler(BaseHandler): | |
389 | def get(self): | |
390 | builders = self.pakfire.builders.get_all() | |
391 | distros = self.pakfire.distros.get_all() | |
392 | ||
393 | self.render("build-filter.html", builders=builders, distros=distros) | |
394 |