]>
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
):
26 async def get(self
, uuid
):
27 build
= self
.backend
.builds
.get_by_uuid(uuid
)
29 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
31 # Fetch any fixed Bugs
32 bugs
= await build
.get_bugs()
34 self
.render("builds/show.html", build
=build
, pkg
=build
.pkg
,
35 distro
=build
.distro
, bugs
=bugs
, repo
=build
.repo
)
38 class BuildDeleteHandler(BuildBaseHandler
):
39 @tornado.web
.authenticated
41 build
= self
.get_build(uuid
)
43 # Check if the user has got sufficient rights to do this modification.
44 if not build
.has_perm(self
.current_user
):
45 raise tornado
.web
.HTTPError(403)
47 # Check if the user confirmed the action.
48 confirmed
= self
.get_argument("confirmed", None)
50 # Save the name of the package to redirect the user
51 # to the other packages of that name.
52 package_name
= build
.pkg
.name
54 # Delete the build and everything that comes with it.
55 with self
.db
.transaction():
58 return self
.redirect("/package/%s" % package_name
)
60 self
.render("build-delete.html", build
=build
)
63 class BuildStateHandler(base
.BaseHandler
):
65 build
= self
.backend
.builds
.get_by_uuid(uuid
)
67 raise tornado
.web
.HTTPError(404, "No such build: %s" % uuid
)
69 self
.render("build-state.html", build
=build
)
71 @tornado.web
.authenticated
73 build
= self
.backend
.builds
.get_by_uuid(uuid
)
75 raise tornado
.web
.HTTPError(404, "No such build: %s" % uuid
)
77 # Check if user has the right to perform this action.
78 if not build
.has_perm(self
.current_user
):
79 raise tornado
.web
.HTTPError(403, "User is not allowed to perform this action")
81 # Check if given state is valid.
82 state
= self
.get_argument("state", None)
83 if not state
in ("broken", "unbreak", "obsolete"):
84 raise tornado
.web
.HTTPError(400, "Invalid argument given: %s" % state
)
86 # XXX this is not quite accurate
87 if state
== "unbreak":
90 rem_from_repo
= self
.get_argument("rem_from_repo", False)
91 if rem_from_repo
== "on":
94 # Perform the state change.
95 build
.update_state(state
, user
=self
.current_user
, remove
=rem_from_repo
)
97 self
.redirect("/build/%s" % build
.uuid
)
100 class BuildDetailCommentHandler(base
.BaseHandler
):
101 @tornado.web
.authenticated
102 def post(self
, uuid
):
103 build
= self
.backend
.builds
.get_by_uuid(uuid
)
106 raise tornado
.web
.HTTPError(404, "Build not found")
108 vote
= self
.get_argument("vote", "none")
117 text
= self
.get_argument("text", "")
119 # Add a new comment to the build.
121 build
.comment(self
.current_user
, text
, vote
)
123 # Redirect to the build detail page.
124 self
.redirect("/build/%s" % build
.uuid
)
127 class BuildManageHandler(base
.BaseHandler
):
128 @tornado.web
.authenticated
130 build
= self
.backend
.builds
.get_by_uuid(uuid
)
132 raise tornado
.web
.HTTPError(404, "Build not found: %s" % uuid
)
135 if self
.current_user
.is_admin():
136 mode
= self
.get_argument("mode", "user")
140 next_repo
= build
.repo
.__next
__
142 next_repo
= build
.distro
.first_repo
144 self
.render("build-manage.html", mode
=mode
, build
=build
,
145 distro
=build
.distro
, repo
=build
.repo
, next_repo
=next_repo
)
147 @tornado.web
.authenticated
148 def post(self
, uuid
):
149 build
= self
.backend
.builds
.get_by_uuid(uuid
)
151 raise tornado
.web
.HTTPError(404, "Build not found: %s" % uuid
)
153 # check for sufficient permissions
154 if not build
.has_perm(self
.current_user
):
155 raise tornado
.web
.HTTPError(403)
157 action
= self
.get_argument("action")
158 assert action
in ("push", "unpush")
160 current_repo
= build
.repo
162 if action
== "unpush":
163 current_repo
.rem_build(build
, user
=self
.current_user
)
165 elif action
== "push":
166 repo_name
= self
.get_argument("repo")
167 next_repo
= build
.distro
.get_repo(repo_name
)
170 raise tornado
.web
.HTTPError(404, "No such repository: %s" % next_repo
)
172 if not self
.current_user
.is_admin():
173 if not distro
.repo
.__next
__ == next_repo
:
174 raise tornado
.web
.HTTPError(403)
177 current_repo
.move_build(build
, next_repo
, user
=self
.current_user
)
179 next_repo
.add_build(build
, user
=self
.current_user
)
181 self
.redirect("/build/%s" % build
.uuid
)
184 class BuildWatchersHandler(base
.BaseHandler
):
186 build
= self
.backend
.builds
.get_by_uuid(uuid
)
189 raise tornado
.web
.HTTPError(404, "Build not found")
191 # Get a list of all watchers and sort them by their realname.
192 watchers
= build
.get_watchers()
193 watchers
.sort(key
=lambda watcher
: watcher
.realname
)
195 self
.render("builds-watchers-list.html", build
=build
, watchers
=watchers
)
198 class BuildWatchersAddHandler(base
.BaseHandler
):
199 @tornado.web
.authenticated
200 def get(self
, uuid
, error_msg
=None):
201 build
= self
.backend
.builds
.get_by_uuid(uuid
)
204 raise tornado
.web
.HTTPError(404, "Build not found")
206 # Get a list of all users that are currently watching this build.
207 watchers
= build
.get_watchers()
209 self
.render("builds-watchers-add.html", error_msg
=error_msg
,
210 build
=build
, users
=self
.backend
.users
, watchers
=watchers
)
212 @tornado.web
.authenticated
213 def post(self
, uuid
):
214 build
= self
.backend
.builds
.get_by_uuid(uuid
)
217 raise tornado
.web
.HTTPError(404, "Build not found")
219 # Get the user id of the new watcher.
220 user_id
= self
.current_user
.id
222 if self
.current_user
.is_admin():
223 user_id
= self
.get_argument("user_id", self
.current_user
.id)
226 user
= self
.backend
.users
.get_by_id(user_id
)
228 _
= self
.locale
.translate
229 error_msg
= _("User not found.")
231 return self
.get(uuid
, error_msg
=error_msg
)
233 # Actually add the user to the list of watchers.
234 build
.add_watcher(user
)
236 # Send user back to the build detail page.
237 self
.redirect("/build/%s" % build
.uuid
)
240 class ListModule(ui_modules
.UIModule
):
241 def render(self
, builds
):
242 return self
.render_string("builds/modules/list.html", builds
=builds
)