]>
git.ipfire.org Git - pbs.git/blob - src/web/builds.py
5 from ..errors
import NoSuchDistroError
8 from . import ui_modules
10 class APIv1IndexHandler(base
.APIMixin
, base
.BaseHandler
):
11 # Allow users to create builds
14 @tornado.web
.authenticated
17 upload
= self
.get_argument_upload("upload_id")
19 raise tornado
.web
.HTTPError(404, "Could not find upload")
21 # Check permissions of the upload
22 if not upload
.has_perm(self
.current_user
):
23 raise tornado
.web
.HTTPError(403, "No permission for using upload %s" % upload
)
25 # Fetch the repository
26 repo_name
= self
.get_argument("repo", None)
28 with self
.db
.transaction():
31 package
= await self
.backend
.packages
.create(upload
)
33 # If the distribution that is coded into the package could not be found,
34 # we will send that error to the user...
35 except NoSuchDistroError
as e
:
36 raise tornado
.web
.HTTPError(404, "Could not find distribution: %s" % e
)
39 repo
= self
.current_user
.get_repo(package
.distro
, repo_name
)
41 raise tornado
.web
.HTTPError(404, "Could not find repository")
44 build
= await self
.backend
.builds
.create(repo
, package
, owner
=self
.current_user
)
49 # Send some data about the build
52 "name" : "%s" % build
,
55 # Run dependency check on all jobs (in the background)
56 self
.backend
.run_task(self
.backend
.jobs
.depcheck
, build
.jobs
)
59 class IndexHandler(base
.BaseHandler
):
62 user
= self
.get_argument_user("user", None)
64 # Fetch the most recent builds
66 builds
= self
.backend
.builds
.get_by_user(user
, limit
=25)
68 builds
= self
.backend
.builds
.get_recent(limit
=25)
70 self
.render("builds/index.html", builds
=builds
, user
=user
)
73 class ShowHandler(base
.BaseHandler
):
74 async def get(self
, uuid
):
75 build
= self
.backend
.builds
.get_by_uuid(uuid
)
77 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
79 # Fetch any fixed Bugs
80 bugs
= await build
.get_bugs()
82 self
.render("builds/show.html", build
=build
, pkg
=build
.pkg
,
83 distro
=build
.distro
, bugs
=bugs
)
86 class DeleteHandler(base
.BaseHandler
):
87 @tornado.web
.authenticated
89 build
= self
.backend
.builds
.get_by_uuid(uuid
)
91 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
94 if not build
.can_be_deleted(self
.current_user
):
95 raise tornado
.web
.HTTPError(403, "%s cannot delete build %s" \
96 % (self
.current_user
, build
))
98 self
.render("builds/delete.html", build
=build
)
100 @tornado.web
.authenticated
101 async def post(self
, uuid
):
102 build
= self
.backend
.builds
.get_by_uuid(uuid
)
104 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
107 if not build
.can_be_deleted(self
.current_user
):
108 raise tornado
.web
.HTTPError(403, "%s cannot delete build %s" \
109 % (self
.current_user
, build
))
112 with self
.db
.transaction():
113 await build
.delete(self
.current_user
)
115 self
.redirect("/builds")
118 class WatchHandler(base
.BaseHandler
):
119 @tornado.web
.authenticated
120 def post(self
, uuid
):
121 build
= self
.backend
.builds
.get_by_uuid(uuid
)
123 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
125 with self
.db
.transaction():
126 build
.add_watcher(self
.current_user
)
128 self
.redirect("/builds/%s" % build
.uuid
)
131 class UnwatchHandler(base
.BaseHandler
):
132 @tornado.web
.authenticated
133 def post(self
, uuid
):
134 build
= self
.backend
.builds
.get_by_uuid(uuid
)
136 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
138 with self
.db
.transaction():
139 build
.remove_watcher(self
.current_user
)
141 self
.redirect("/builds/%s" % build
.uuid
)
144 class BuildDetailCommentHandler(base
.BaseHandler
):
145 @tornado.web
.authenticated
146 def post(self
, uuid
):
147 build
= self
.backend
.builds
.get_by_uuid(uuid
)
150 raise tornado
.web
.HTTPError(404, "Build not found")
152 vote
= self
.get_argument("vote", "none")
161 text
= self
.get_argument("text", "")
163 # Add a new comment to the build.
165 build
.comment(self
.current_user
, text
, vote
)
167 # Redirect to the build detail page.
168 self
.redirect("/build/%s" % build
.uuid
)
171 class ListModule(ui_modules
.UIModule
):
172 def render(self
, builds
):
173 return self
.render_string("builds/modules/list.html", builds
=builds
)