]>
git.ipfire.org Git - pbs.git/blob - src/web/builds.py
6 from . import ui_modules
8 class BuildBaseHandler(base
.BaseHandler
):
9 def get_build(self
, uuid
):
10 build
= self
.backend
.builds
.get_by_uuid(uuid
)
12 raise tornado
.web
.HTTPError(404, "No such build: %s" % uuid
)
17 class IndexHandler(base
.BaseHandler
):
19 # Fetch the most recent builds
20 builds
= self
.backend
.builds
.get_recent(limit
=25)
22 self
.render("builds/index.html", builds
=builds
)
25 class ShowHandler(BuildBaseHandler
):
27 build
= self
.backend
.builds
.get_by_uuid(uuid
)
29 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
35 bugs
= build
.get_bugs()
37 self
.render("builds/show.html", build
=build
, log
=log
, pkg
=build
.pkg
,
38 distro
=build
.distro
, bugs
=bugs
, repo
=build
.repo
)
41 class BuildDeleteHandler(BuildBaseHandler
):
42 @tornado.web
.authenticated
44 build
= self
.get_build(uuid
)
46 # Check if the user has got sufficient rights to do this modification.
47 if not build
.has_perm(self
.current_user
):
48 raise tornado
.web
.HTTPError(403)
50 # Check if the user confirmed the action.
51 confirmed
= self
.get_argument("confirmed", None)
53 # Save the name of the package to redirect the user
54 # to the other packages of that name.
55 package_name
= build
.pkg
.name
57 # Delete the build and everything that comes with it.
58 with self
.db
.transaction():
61 return self
.redirect("/package/%s" % package_name
)
63 self
.render("build-delete.html", build
=build
)
66 class BuildBugsHandler(base
.BaseHandler
):
67 @tornado.web
.authenticated
69 build
= self
.backend
.builds
.get_by_uuid(uuid
)
71 raise tornado
.web
.HTTPError(404, "No such build: %s" % uuid
)
73 # Check if the user has got the right to alter this build.
74 if not build
.has_perm(self
.current_user
):
75 raise tornado
.web
.HTTPError(403)
78 fixed_bugs
= build
.get_bugs()
81 for bug
in self
.backend
.bugzilla
.get_bugs_from_component(build
.pkg
.name
):
87 self
.render("build-bugs.html", build
=build
, pkg
=build
.pkg
,
88 fixed_bugs
=fixed_bugs
, open_bugs
=open_bugs
)
90 @tornado.web
.authenticated
92 build
= self
.backend
.builds
.get_by_uuid(uuid
)
94 raise tornado
.web
.HTTPError(404, "No such build: %s" % uuid
)
96 # Check if the user has got the right to alter this build.
97 if not build
.has_perm(self
.current_user
):
98 raise tornado
.web
.HTTPError(403)
100 action
= self
.get_argument("action", None)
101 bugid
= self
.get_argument("bugid")
103 # Convert the bug id to integer.
107 raise tornado
.web
.HTTPError(400, "Bad bug id given: %s" % bugid
)
110 # Add bug to the build.
111 build
.add_bug(bugid
, user
=self
.current_user
)
113 elif action
== "remove":
114 # Remove bug from the build.
115 build
.rem_bug(bugid
, user
=self
.current_user
)
118 raise tornado
.web
.HTTPError(400, "Unhandled action: %s" % action
)
120 self
.redirect("/build/%s/bugs" % build
.uuid
)
123 class BuildStateHandler(base
.BaseHandler
):
125 build
= self
.backend
.builds
.get_by_uuid(uuid
)
127 raise tornado
.web
.HTTPError(404, "No such build: %s" % uuid
)
129 self
.render("build-state.html", build
=build
)
131 @tornado.web
.authenticated
132 def post(self
, uuid
):
133 build
= self
.backend
.builds
.get_by_uuid(uuid
)
135 raise tornado
.web
.HTTPError(404, "No such build: %s" % uuid
)
137 # Check if user has the right to perform this action.
138 if not build
.has_perm(self
.current_user
):
139 raise tornado
.web
.HTTPError(403, "User is not allowed to perform this action")
141 # Check if given state is valid.
142 state
= self
.get_argument("state", None)
143 if not state
in ("broken", "unbreak", "obsolete"):
144 raise tornado
.web
.HTTPError(400, "Invalid argument given: %s" % state
)
146 # XXX this is not quite accurate
147 if state
== "unbreak":
150 rem_from_repo
= self
.get_argument("rem_from_repo", False)
151 if rem_from_repo
== "on":
154 # Perform the state change.
155 build
.update_state(state
, user
=self
.current_user
, remove
=rem_from_repo
)
157 self
.redirect("/build/%s" % build
.uuid
)
160 class BuildDetailCommentHandler(base
.BaseHandler
):
161 @tornado.web
.authenticated
162 def post(self
, uuid
):
163 build
= self
.backend
.builds
.get_by_uuid(uuid
)
166 raise tornado
.web
.HTTPError(404, "Build not found")
168 vote
= self
.get_argument("vote", "none")
177 text
= self
.get_argument("text", "")
179 # Add a new comment to the build.
181 build
.add_comment(self
.current_user
, text
, vote
)
183 # Redirect to the build detail page.
184 self
.redirect("/build/%s" % build
.uuid
)
187 class BuildManageHandler(base
.BaseHandler
):
188 @tornado.web
.authenticated
190 build
= self
.backend
.builds
.get_by_uuid(uuid
)
192 raise tornado
.web
.HTTPError(404, "Build not found: %s" % uuid
)
195 if self
.current_user
.is_admin():
196 mode
= self
.get_argument("mode", "user")
200 next_repo
= build
.repo
.__next
__
202 next_repo
= build
.distro
.first_repo
204 self
.render("build-manage.html", mode
=mode
, build
=build
,
205 distro
=build
.distro
, repo
=build
.repo
, next_repo
=next_repo
)
207 @tornado.web
.authenticated
208 def post(self
, uuid
):
209 build
= self
.backend
.builds
.get_by_uuid(uuid
)
211 raise tornado
.web
.HTTPError(404, "Build not found: %s" % uuid
)
213 # check for sufficient permissions
214 if not build
.has_perm(self
.current_user
):
215 raise tornado
.web
.HTTPError(403)
217 action
= self
.get_argument("action")
218 assert action
in ("push", "unpush")
220 current_repo
= build
.repo
222 if action
== "unpush":
223 current_repo
.rem_build(build
, user
=self
.current_user
)
225 elif action
== "push":
226 repo_name
= self
.get_argument("repo")
227 next_repo
= build
.distro
.get_repo(repo_name
)
230 raise tornado
.web
.HTTPError(404, "No such repository: %s" % next_repo
)
232 if not self
.current_user
.is_admin():
233 if not distro
.repo
.__next
__ == next_repo
:
234 raise tornado
.web
.HTTPError(403)
237 current_repo
.move_build(build
, next_repo
, user
=self
.current_user
)
239 next_repo
.add_build(build
, user
=self
.current_user
)
241 self
.redirect("/build/%s" % build
.uuid
)
244 class BuildWatchersHandler(base
.BaseHandler
):
246 build
= self
.backend
.builds
.get_by_uuid(uuid
)
249 raise tornado
.web
.HTTPError(404, "Build not found")
251 # Get a list of all watchers and sort them by their realname.
252 watchers
= build
.get_watchers()
253 watchers
.sort(key
=lambda watcher
: watcher
.realname
)
255 self
.render("builds-watchers-list.html", build
=build
, watchers
=watchers
)
258 class BuildWatchersAddHandler(base
.BaseHandler
):
259 @tornado.web
.authenticated
260 def get(self
, uuid
, error_msg
=None):
261 build
= self
.backend
.builds
.get_by_uuid(uuid
)
264 raise tornado
.web
.HTTPError(404, "Build not found")
266 # Get a list of all users that are currently watching this build.
267 watchers
= build
.get_watchers()
269 self
.render("builds-watchers-add.html", error_msg
=error_msg
,
270 build
=build
, users
=self
.backend
.users
, watchers
=watchers
)
272 @tornado.web
.authenticated
273 def post(self
, uuid
):
274 build
= self
.backend
.builds
.get_by_uuid(uuid
)
277 raise tornado
.web
.HTTPError(404, "Build not found")
279 # Get the user id of the new watcher.
280 user_id
= self
.current_user
.id
282 if self
.current_user
.is_admin():
283 user_id
= self
.get_argument("user_id", self
.current_user
.id)
286 user
= self
.backend
.users
.get_by_id(user_id
)
288 _
= self
.locale
.translate
289 error_msg
= _("User not found.")
291 return self
.get(uuid
, error_msg
=error_msg
)
293 # Actually add the user to the list of watchers.
294 build
.add_watcher(user
)
296 # Send user back to the build detail page.
297 self
.redirect("/build/%s" % build
.uuid
)
300 class BuildListHandler(base
.BaseHandler
):
302 builder
= self
.get_argument("builder", None)
303 state
= self
.get_argument("state", None)
305 builds
= self
.backend
.builds
.get_latest(state
=state
, builder
=builder
,
308 self
.render("build-list.html", builds
=builds
)
311 class ListModule(ui_modules
.UIModule
):
312 def render(self
, builds
):
313 return self
.render_string("builds/modules/list.html", builds
=builds
)