| 1 | |
|
| 2 | |
|
| 3 | | use super::settings::{csrf, require}; |
| 4 | | use super::{filters, lookup, lookup_role, Error, Page, RepoShell, Shell}; |
| 5 | | use crate::auth::{Access, Role, Viewer}; |
| 6 | | use crate::repos::view; |
| 7 | | use crate::{db, Shared}; |
| 8 | | use askama::Template; |
| 9 | | use axum::extract::{Form, Path, State}; |
| 10 | | use serde::Deserialize; |
| 11 | |
|
| 12 | | #[derive(Template)] |
| 13 | | #[template(path = "bookmarks.html")] |
| 14 | | pub struct BookmarksPage { |
| 15 | | shell: Shell, |
| 16 | | repo: RepoShell, |
| 17 | | bookmarks: Vec<view::BookmarkView>, |
| 18 | | |
| 19 | | can_delete: bool, |
| 20 | | |
| 21 | | can_run: bool, |
| 22 | | notice: Option<String>, |
| 23 | | error: Option<String>, |
| 24 | | } |
| 25 | |
|
| 26 | 16× | async fn bookmarks_page( |
| 27 | 16× | app: &Shared, |
| 28 | 16× | shell: Shell, |
| 29 | 16× | repo: crate::repos::RepoName, |
| 30 | 16× | row: db::repos::RepoRow, |
| 31 | 16× | role: Role, |
| 32 | 16× | notice: Option<String>, |
| 33 | 16× | error: Option<String>, |
| 34 | 16× | ) -> Result<Page<BookmarksPage>, Error> { |
| 35 | 16× | let default = row.default_bookmark.clone(); |
| 36 | 16× | let bookmarks = |
| 37 | 16× | app.repos.read(&repo, move |r, cache| view::bookmarks(r, cache, &default)).await.map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 38 | 16× | let can_delete = shell.user.is_some() && role >= Role::Write; |
| 39 | 16× | let can_run = super::flow::why_not_run(crate::flow::enabled(app, &row), shell.user.is_some(), role).is_none(); |
| 40 | 16× | Ok(Page(BookmarksPage { |
| 41 | 16× | shell, |
| 42 | 16× | repo: RepoShell::new(app, &row, "bookmarks").with_role(role), |
| 43 | 16× | bookmarks, |
| 44 | 16× | can_delete, |
| 45 | 16× | can_run, |
| 46 | 16× | notice, |
| 47 | 16× | error, |
| 48 | 16× | })) |
| 49 | 16× | } |
| 50 | |
|
| 51 | 8× | pub async fn bookmarks( |
| 52 | 8× | State(app): State<Shared>, |
| 53 | 8× | viewer: Viewer, |
| 54 | 8× | Path((owner, name)): Path<(String, String)>, |
| 55 | 8× | ) -> Result<Page<BookmarksPage>, Error> { |
| 56 | 8× | let shell = Shell::new(&app, &format!("/{owner}/{name}/bookmarks"), &viewer); |
| 57 | 8× | let (repo, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| 58 | 8× | bookmarks_page(&app, shell, repo, row, role, None, None).await |
| 59 | 8× | } |
| 60 | |
|
| 61 | | #[derive(Deserialize)] |
| 62 | | pub struct DeleteBookmarkForm { |
| 63 | | #[serde(rename = "_csrf")] |
| 64 | | csrf_token: String, |
| 65 | | bookmark: String, |
| 66 | | } |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | 5× | pub async fn delete_bookmark( |
| 72 | 5× | State(app): State<Shared>, |
| 73 | 5× | viewer: Viewer, |
| 74 | 5× | Path((owner, name)): Path<(String, String)>, |
| 75 | 5× | Form(f): Form<DeleteBookmarkForm>, |
| 76 | 5× | ) -> Result<Page<BookmarksPage>, Error> { |
| 77 | 5× | let shell = Shell::new(&app, &format!("/{owner}/{name}/bookmarks"), &viewer); |
| 78 | 5× | let me = require(&viewer, &shell)?; |
| 79 | 4× | let (repo, row, role) = lookup_role(&app, &shell, &viewer, &owner, &name, Access::Write).await?; |
| 80 | 4× | csrf(&viewer, &f.csrf_token, &shell)?; |
| 81 | 4× | let bookmark = f.bookmark.trim().to_string(); |
| 82 | 4× | if bookmark == row.default_bookmark { |
| 83 | 1× | let msg = format!("{bookmark} is the default bookmark; choose another default in Settings first."); |
| 84 | 1× | return bookmarks_page(&app, shell, repo, row, role, None, Some(msg)).await; |
| 85 | 3× | } |
| 86 | 3× | let target = bookmark.clone(); |
| 87 | 3× | let outcome = app |
| 88 | 3× | .repos |
| 89 | 3× | .write(&repo, move |r, _| { |
| 90 | 3× | let Some(state) = r.view()?.bookmarks.get(&target).copied() else { |
| 91 | 1× | return Ok(Err(format!("There is no bookmark {target}."))); |
| 92 | | }; |
| 93 | 2× | let update = oxy_core::protocol::RefUpdate { |
| 94 | 2× | name: target.clone(), |
| 95 | 2× | old_state: state, |
| 96 | 2× | new_state: oxy_core::hash::ObjectRef::ZERO, |
| 97 | 2× | force: true, |
| 98 | 2× | attestation: None, |
| 99 | 2× | }; |
| 100 | 2× | let report = r.receive_push_report(Default::default(), vec![update], None, vec![])?; |
| 101 | 2× | Ok(match report.results.first() { |
| 102 | 2× | Some(res) if res.ok => Ok(state.to_hex()), |
| 103 | 0× | Some(res) => Err(res.reason.clone()), |
| 104 | 0× | None => Err("nothing happened".into()), |
| 105 | | }) |
| 106 | 3× | }) |
| 107 | 3× | .await |
| 108 | 3× | .map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 109 | 3× | let old_state = match outcome { |
| 110 | 2× | Ok(s) => s, |
| 111 | 1× | Err(msg) => return bookmarks_page(&app, shell, repo, row, role, None, Some(format!("Could not delete {bookmark}: {msg}"))).await, |
| 112 | | }; |
| 113 | 2× | let result = db::repos::PushOutcome { |
| 114 | 2× | reference: bookmark.clone(), |
| 115 | 2× | ok: true, |
| 116 | 2× | reason: "deleted on the web".into(), |
| 117 | 2× | old_state: old_state.clone(), |
| 118 | 2× | new_state: oxy_core::hash::ObjectRef::ZERO.to_hex(), |
| 119 | 2× | heads: 0, |
| 120 | 2× | changes: 0, |
| 121 | 2× | }; |
| 122 | 2× | db::repos::record_push(&app.db, row.id, Some((me.account.id, &me.account.username)), &[result]).await.ok(); |
| 123 | 2× | crate::hooks::emit( |
| 124 | 2× | &app, |
| 125 | 2× | &row, |
| 126 | 2× | "push", |
| 127 | 2× | &me.account.username, |
| 128 | 2× | serde_json::json!({ "updates": [{ "reference": bookmark, "old_state": old_state, "new_state": oxy_core::hash::ObjectRef::ZERO.to_hex(), "heads": 0, "changes": 0, "deleted": true }], "via": "web" }), |
| 129 | 2× | ) |
| 130 | 2× | .await; |
| 131 | 2× | db::accounts::audit(&app.db, Some(&me.account), "bookmark.deleted", &format!("{owner}/{name}"), &bookmark).await.ok(); |
| 132 | 2× | bookmarks_page( |
| 133 | 2× | &app, |
| 134 | 2× | shell, |
| 135 | 2× | repo, |
| 136 | 2× | row, |
| 137 | 2× | role, |
| 138 | 2× | Some(format!("Deleted {bookmark}. Its changes stay while anything else reaches them.")), |
| 139 | 2× | None, |
| 140 | 2× | ) |
| 141 | 2× | .await |
| 142 | 5× | } |
| 143 | |
|
| 144 | | #[derive(Deserialize)] |
| 145 | | pub struct CreateBookmarkForm { |
| 146 | | #[serde(rename = "_csrf")] |
| 147 | | csrf_token: String, |
| 148 | | name: String, |
| 149 | | |
| 150 | | #[serde(default)] |
| 151 | | from: String, |
| 152 | | } |
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | 4× | pub async fn create_bookmark( |
| 158 | 4× | State(app): State<Shared>, |
| 159 | 4× | viewer: Viewer, |
| 160 | 4× | Path((owner, name)): Path<(String, String)>, |
| 161 | 4× | Form(f): Form<CreateBookmarkForm>, |
| 162 | 4× | ) -> Result<Page<BookmarksPage>, Error> { |
| 163 | 4× | let shell = Shell::new(&app, &format!("/{owner}/{name}/bookmarks"), &viewer); |
| 164 | 4× | let me = require(&viewer, &shell)?; |
| 165 | 4× | let (repo, row, role) = lookup_role(&app, &shell, &viewer, &owner, &name, Access::Write).await?; |
| 166 | 4× | csrf(&viewer, &f.csrf_token, &shell)?; |
| 167 | 4× | let bookmark = f.name.trim().to_string(); |
| 168 | 4× | let from = match f.from.trim() { |
| 169 | 4× | "" => row.default_bookmark.clone(), |
| 170 | 3× | s => s.to_string(), |
| 171 | | }; |
| 172 | 4× | if bookmark.is_empty() || bookmark.chars().any(char::is_whitespace) { |
| 173 | 1× | return bookmarks_page(&app, shell, repo, row, role, None, Some("A bookmark's name has no spaces.".into())).await; |
| 174 | 3× | } |
| 175 | 3× | let (wanted, spec) = (bookmark.clone(), from.clone()); |
| 176 | 3× | let found = app |
| 177 | 3× | .repos |
| 178 | 3× | .read(&repo, move |r, cache| { |
| 179 | 3× | if r.view()?.bookmarks.contains_key(&wanted) { |
| 180 | 1× | return Ok(Err(format!("{wanted} is a bookmark already."))); |
| 181 | 2× | } |
| 182 | 2× | Ok(view::resolve(r, cache, &spec).map(|t| t.heads).map_err(|e| e.to_string())) |
| 183 | 3× | }) |
| 184 | 3× | .await |
| 185 | 3× | .map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 186 | 1× | let heads = match found { |
| 187 | 1× | Ok(heads) if !heads.is_empty() => heads, |
| 188 | 0× | Ok(_) => return bookmarks_page(&app, shell, repo, row, role, None, Some(format!("{from} holds no changes to start from."))).await, |
| 189 | 2× | Err(msg) => return bookmarks_page(&app, shell, repo, row, role, None, Some(msg)).await, |
| 190 | | }; |
| 191 | 1× | let made = set_bookmark(&app, &repo, me.account.id, &bookmark, heads.clone()).await; |
| 192 | 1× | if let Err(e) = made { |
| 193 | 0× | return bookmarks_page(&app, shell, repo, row, role, None, Some(format!("Could not create {bookmark}: {e}"))).await; |
| 194 | 1× | } |
| 195 | 1× | let made = bookmark.clone(); |
| 196 | 1× | let new_state = app |
| 197 | 1× | .repos |
| 198 | 1× | .read(&repo, move |r, _| Ok(r.view()?.bookmarks.get(&made).map(|s| s.to_hex()).unwrap_or_default())) |
| 199 | 1× | .await |
| 200 | 1× | .unwrap_or_default(); |
| 201 | 1× | let result = db::repos::PushOutcome { |
| 202 | 1× | reference: bookmark.clone(), |
| 203 | 1× | ok: true, |
| 204 | 1× | reason: format!("created on the web from {from}"), |
| 205 | 1× | old_state: oxy_core::hash::ObjectRef::ZERO.to_hex(), |
| 206 | 1× | new_state: new_state.clone(), |
| 207 | 1× | heads: heads.len() as i64, |
| 208 | 1× | changes: 0, |
| 209 | 1× | }; |
| 210 | 1× | db::repos::record_push(&app.db, row.id, Some((me.account.id, &me.account.username)), &[result]).await.ok(); |
| 211 | 1× | crate::hooks::emit( |
| 212 | 1× | &app, |
| 213 | 1× | &row, |
| 214 | 1× | "push", |
| 215 | 1× | &me.account.username, |
| 216 | 1× | serde_json::json!({ "updates": [{ "reference": bookmark, "old_state": oxy_core::hash::ObjectRef::ZERO.to_hex(), "new_state": new_state, "heads": heads.len(), "changes": 0, "created": true }], "via": "web" }), |
| 217 | 1× | ) |
| 218 | 1× | .await; |
| 219 | 1× | db::accounts::audit(&app.db, Some(&me.account), "bookmark.created", &format!("{owner}/{name}"), &format!("{bookmark} from {from}")) |
| 220 | 1× | .await |
| 221 | 1× | .ok(); |
| 222 | 1× | let notice = format!("Created {bookmark} from {from}. Propose changes into it, or make it the default in Settings."); |
| 223 | 1× | bookmarks_page(&app, shell, repo, row, role, Some(notice), None).await |
| 224 | 4× | } |
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | 2× | pub async fn set_bookmark( |
| 230 | 2× | app: &Shared, |
| 231 | 2× | repo: &crate::repos::RepoName, |
| 232 | 2× | account_id: i64, |
| 233 | 2× | bookmark: &str, |
| 234 | 2× | heads: Vec<oxy_core::hash::ChangeHash>, |
| 235 | 2× | ) -> Result<(), String> { |
| 236 | 2× | match super::edit::signer_for(app, account_id).await { |
| 237 | 1× | Ok(signer) => crate::repos::edits::move_bookmark(&app.repos, repo, bookmark.to_string(), heads, signer) |
| 238 | 1× | .await |
| 239 | 1× | .map(|_| ()) |
| 240 | 1× | .map_err(|e| e.to_string()), |
| 241 | 1× | Err(why) => { |
| 242 | 1× | let target = bookmark.to_string(); |
| 243 | 1× | let unsigned = app |
| 244 | 1× | .repos |
| 245 | 1× | .write(repo, move |r, _| { |
| 246 | 1× | let update = r.host_ref_update(&target, &heads, None)?; |
| 247 | 1× | let report = r.receive_push_report(Default::default(), vec![update], None, vec![])?; |
| 248 | 1× | Ok(match report.results.first() { |
| 249 | 1× | Some(res) if res.ok => Ok(()), |
| 250 | 0× | Some(res) => Err(res.reason.clone()), |
| 251 | 0× | None => Err("nothing happened".to_string()), |
| 252 | | }) |
| 253 | 1× | }) |
| 254 | 1× | .await |
| 255 | 1× | .map_err(|e| e.to_string()) |
| 256 | 1× | .and_then(|r| r); |
| 257 | 1× | unsigned.map_err(|refused| format!("{refused}. {why}")) |
| 258 | | } |
| 259 | | } |
| 260 | 2× | } |
| 261 | |
|
| 262 | | #[derive(Template)] |
| 263 | | #[template(path = "tags.html")] |
| 264 | | pub struct TagsPage { |
| 265 | | shell: Shell, |
| 266 | | repo: RepoShell, |
| 267 | | tags: Vec<view::TagView>, |
| 268 | | withdrawn: Vec<view::WithdrawnView>, |
| 269 | | |
| 270 | | released: Vec<String>, |
| 271 | | can_create: bool, |
| 272 | | can_withdraw: bool, |
| 273 | | notice: Option<String>, |
| 274 | | error: Option<String>, |
| 275 | | } |
| 276 | |
|
| 277 | | impl TagsPage { |
| 278 | 25× | fn released(&self, tag: &str) -> bool { |
| 279 | 25× | self.released.iter().any(|t| t == tag) |
| 280 | 25× | } |
| 281 | | } |
| 282 | |
|
| 283 | 9× | async fn tags_page( |
| 284 | 9× | app: &Shared, |
| 285 | 9× | shell: Shell, |
| 286 | 9× | repo: crate::repos::RepoName, |
| 287 | 9× | row: db::repos::RepoRow, |
| 288 | 9× | role: Role, |
| 289 | 9× | notice: Option<String>, |
| 290 | 9× | error: Option<String>, |
| 291 | 9× | ) -> Result<Page<TagsPage>, Error> { |
| 292 | 9× | let (tags, withdrawn) = app |
| 293 | 9× | .repos |
| 294 | 9× | .read(&repo, |r, _| Ok((view::tags(r)?, view::withdrawn_tags(r)?))) |
| 295 | 9× | .await |
| 296 | 9× | .map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 297 | 9× | let released = db::releases::list(&app.db, row.id).await.unwrap_or_default().into_iter().map(|r| r.tag).collect(); |
| 298 | 9× | let signed_in = shell.user.is_some(); |
| 299 | | Ok(Page(TagsPage { |
| 300 | 9× | shell, |
| 301 | 9× | repo: RepoShell::new(app, &row, "tags").with_role(role), |
| 302 | 9× | tags, |
| 303 | 9× | withdrawn, |
| 304 | 9× | released, |
| 305 | 9× | can_create: signed_in && role >= Role::Write, |
| 306 | 9× | can_withdraw: signed_in && role >= Role::Maintain, |
| 307 | 9× | notice, |
| 308 | 9× | error, |
| 309 | | })) |
| 310 | 9× | } |
| 311 | |
|
| 312 | 3× | pub async fn tags(State(app): State<Shared>, viewer: Viewer, Path((owner, name)): Path<(String, String)>) -> Result<Page<TagsPage>, Error> { |
| 313 | 3× | let shell = Shell::new(&app, &format!("/{owner}/{name}/tags"), &viewer); |
| 314 | 3× | let (repo, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| 315 | 3× | tags_page(&app, shell, repo, row, role, None, None).await |
| 316 | 3× | } |
| 317 | |
|
| 318 | | #[derive(Deserialize)] |
| 319 | | pub struct CreateTagForm { |
| 320 | | #[serde(rename = "_csrf")] |
| 321 | | csrf_token: String, |
| 322 | | name: String, |
| 323 | | #[serde(default)] |
| 324 | | target: String, |
| 325 | | #[serde(default)] |
| 326 | | message: String, |
| 327 | | } |
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | 4× | pub async fn create_tag( |
| 332 | 4× | State(app): State<Shared>, |
| 333 | 4× | viewer: Viewer, |
| 334 | 4× | Path((owner, name)): Path<(String, String)>, |
| 335 | 4× | Form(f): Form<CreateTagForm>, |
| 336 | 4× | ) -> Result<Page<TagsPage>, Error> { |
| 337 | 4× | let shell = Shell::new(&app, &format!("/{owner}/{name}/tags"), &viewer); |
| 338 | 4× | let me = require(&viewer, &shell)?; |
| 339 | 4× | let (repo, row, role) = lookup_role(&app, &shell, &viewer, &owner, &name, Access::Write).await?; |
| 340 | 4× | csrf(&viewer, &f.csrf_token, &shell)?; |
| 341 | 4× | match crate::tags::create(&app, &row, &repo, &me.account, &f.name, &f.target, &f.message).await { |
| 342 | 2× | Ok(t) => { |
| 343 | 2× | let notice = format!( |
| 344 | | "Tagged {} ({} head{}). Start a release from it under Releases.", |
| 345 | | t.name, |
| 346 | 2× | t.heads.len(), |
| 347 | 2× | if t.heads.len() == 1 { "" } else { "s" } |
| 348 | | ); |
| 349 | 2× | tags_page(&app, shell, repo, row, role, Some(notice), None).await |
| 350 | | } |
| 351 | 2× | Err(e) => tags_page(&app, shell, repo, row, role, None, Some(format!("Could not create the tag: {e}"))).await, |
| 352 | | } |
| 353 | 4× | } |
| 354 | |
|
| 355 | | #[derive(Deserialize)] |
| 356 | | pub struct WithdrawTagForm { |
| 357 | | #[serde(rename = "_csrf")] |
| 358 | | csrf_token: String, |
| 359 | | tag: String, |
| 360 | | #[serde(default)] |
| 361 | | reason: String, |
| 362 | | } |
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | 2× | pub async fn withdraw_tag( |
| 368 | 2× | State(app): State<Shared>, |
| 369 | 2× | viewer: Viewer, |
| 370 | 2× | Path((owner, name)): Path<(String, String)>, |
| 371 | 2× | Form(f): Form<WithdrawTagForm>, |
| 372 | 2× | ) -> Result<Page<TagsPage>, Error> { |
| 373 | 2× | let shell = Shell::new(&app, &format!("/{owner}/{name}/tags"), &viewer); |
| 374 | 2× | let me = require(&viewer, &shell)?; |
| 375 | 2× | let (repo, row, role) = lookup_role(&app, &shell, &viewer, &owner, &name, Access::Maintain).await?; |
| 376 | 2× | csrf(&viewer, &f.csrf_token, &shell)?; |
| 377 | 2× | match crate::tags::withdraw(&app, &row, &repo, &me.account, &f.tag, &f.reason).await { |
| 378 | 1× | Ok(t) => { |
| 379 | 1× | let notice = format!("Withdrew {}. Clones drop it on their next fetch; the name is not used again.", t.name); |
| 380 | 1× | tags_page(&app, shell, repo, row, role, Some(notice), None).await |
| 381 | | } |
| 382 | 1× | Err(e) => tags_page(&app, shell, repo, row, role, None, Some(format!("Could not withdraw {}: {e}", f.tag.trim()))).await, |
| 383 | | } |
| 384 | 2× | } |
| 385 | |
|
| 386 | | #[derive(Template)] |
| 387 | | #[template(path = "conflicts.html")] |
| 388 | | pub struct ConflictsPage { |
| 389 | | shell: Shell, |
| 390 | | repo: RepoShell, |
| 391 | | conflicts: Vec<view::ConflictView>, |
| 392 | | } |
| 393 | |
|
| 394 | 8× | pub async fn conflicts( |
| 395 | 8× | State(app): State<Shared>, |
| 396 | 8× | viewer: Viewer, |
| 397 | 8× | Path((owner, name)): Path<(String, String)>, |
| 398 | 8× | ) -> Result<Page<ConflictsPage>, Error> { |
| 399 | 8× | let shell = Shell::new(&app, &format!("/{owner}/{name}/conflicts"), &viewer); |
| 400 | 8× | let (repo, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| 401 | 8× | let conflicts = app.repos.read(&repo, view::conflicts).await.map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 402 | 8× | Ok(Page(ConflictsPage { shell, repo: RepoShell::new(&app, &row, "conflicts").with_role(role).with_sky(&app, &row).await, conflicts })) |
| 403 | 8× | } |
| 404 | |
|
| 405 | | #[derive(Template)] |
| 406 | | #[template(path = "trust.html")] |
| 407 | | pub struct TrustPage { |
| 408 | | shell: Shell, |
| 409 | | repo: RepoShell, |
| 410 | | t: view::Trust, |
| 411 | | } |
| 412 | |
|
| 413 | 2× | pub async fn trust( |
| 414 | 2× | State(app): State<Shared>, |
| 415 | 2× | viewer: Viewer, |
| 416 | 2× | Path((owner, name)): Path<(String, String)>, |
| 417 | 2× | ) -> Result<Page<TrustPage>, Error> { |
| 418 | 2× | let shell = Shell::new(&app, &format!("/{owner}/{name}/trust"), &viewer); |
| 419 | 2× | let (repo, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| 420 | 2× | let key = app.hub_key.key; |
| 421 | 2× | let t = app.repos.read(&repo, move |r, cache| view::trust(r, cache, &key)).await.map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 422 | 2× | Ok(Page(TrustPage { shell, repo: RepoShell::new(&app, &row, "trust").with_role(role), t })) |
| 423 | 2× | } |
| 424 | |
|
| 425 | | #[derive(Template)] |
| 426 | | #[template(path = "pushes.html")] |
| 427 | | pub struct PushesPage { |
| 428 | | shell: Shell, |
| 429 | | repo: RepoShell, |
| 430 | | pushes: Vec<db::repos::PushRow>, |
| 431 | | } |
| 432 | |
|
| 433 | 6× | pub async fn pushes( |
| 434 | 6× | State(app): State<Shared>, |
| 435 | 6× | viewer: Viewer, |
| 436 | 6× | Path((owner, name)): Path<(String, String)>, |
| 437 | 6× | ) -> Result<Page<PushesPage>, Error> { |
| 438 | 6× | let shell = Shell::new(&app, &format!("/{owner}/{name}/pushes"), &viewer); |
| 439 | 6× | let (_, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| 440 | 6× | let pushes = db::repos::pushes(&app.db, row.id, 200).await.map_err(|e| Error::from_db(shell.clone(), e))?; |
| 441 | 6× | Ok(Page(PushesPage { shell, repo: RepoShell::new(&app, &row, "pushes").with_role(role), pushes })) |
| 442 | 6× | } |