steid

@jamesgill /

steid/src/infrastructure/web/repo_settings.rs
Rust32.5 KBCode·Blame·History·Raw
1//! Repository settings — `/{handle}/repos/{name}/settings`.
2//!
3//! Owner-only: change the description, change visibility, choose the default branch,
4//! archive, rename, delete.
5//!
6//! `settings` sits in the verb position after `{name}`, where nothing user-controlled
7//! ever appears, so unlike `new` it needs no reservation in
8//! [`RepoName`](crate::domain::RepoName).
9//!
10//! **A non-owner gets a 404, not a 403.** That is the rule
11//! [`view_repo`](crate::application::view_repo) already sets for repositories: a 403
12//! would confirm that a private repository by that name exists, and there is no reason
13//! for the settings page to be more talkative than the repository page it belongs to.
14
15use serde::Deserialize;
16use topcoat::{
17 Result,
18 context::Cx,
19 router::{StatusCode, content::Form, error::not_found, page, query_params},
20 view::{attributes, component, view},
21};
22
23use crate::{
24 application::{
25 Error, RepoView, Stores, list_branches,
26 repo::{
27 RepoEdit, delete_repo, rename_repo, set_default_branch, set_repo_archived, update_repo,
28 },
29 },
30 components::{
31 button::{ButtonVariant, button},
32 flash::{FlashKind, flash},
33 input::input,
34 label::label,
35 select::select,
36 textarea::textarea,
37 },
38 domain::{BranchRow, DomainError, RepoName, Repository, Visibility},
39};
40
41use super::{
42 context::{
43 current_actor, location, memberships, orgs, owned_repo, queries, repos, server_error,
44 storage,
45 },
46 csrf::{csrf_field, csrf_verified},
47 format::optional,
48 layout::narrow,
49};
50
51#[derive(Debug, Deserialize)]
52struct SettingsForm {
53 /// The hidden field every form carries; see [`csrf`](super::csrf).
54 ///
55 /// `default` so that a submission with no token at all is refused by
56 /// `csrf_verified` — a 403 saying what happened — rather than failing
57 /// deserialization into a bare 400 that says nothing.
58 #[serde(default)]
59 csrf_token: String,
60 description: String,
61 visibility: String,
62 /// A checkbox: present when ticked, absent entirely when not. `Option` is the shape
63 /// the browser actually sends, so it is the shape parsed.
64 pinned: Option<String>,
65}
66
67/// Which way the archive button is pointing. A hidden field rather than two routes,
68/// so the form that renders the button also states what it does.
69#[derive(Debug, Deserialize)]
70struct ArchiveForm {
71 /// The hidden field every form carries; see [`csrf`](super::csrf).
72 ///
73 /// `default` so that a submission with no token at all is refused by
74 /// `csrf_verified` — a 403 saying what happened — rather than failing
75 /// deserialization into a bare 400 that says nothing.
76 #[serde(default)]
77 csrf_token: String,
78 archived: String,
79}
80
81#[derive(Debug, Deserialize)]
82struct DefaultBranchForm {
83 /// The hidden field every form carries; see [`csrf`](super::csrf).
84 ///
85 /// `default` so that a submission with no token at all is refused by
86 /// `csrf_verified` — a 403 saying what happened — rather than failing
87 /// deserialization into a bare 400 that says nothing.
88 #[serde(default)]
89 csrf_token: String,
90 branch: String,
91}
92
93#[derive(Debug, Deserialize)]
94struct RenameForm {
95 /// The hidden field every form carries; see [`csrf`](super::csrf).
96 ///
97 /// `default` so that a submission with no token at all is refused by
98 /// `csrf_verified` — a 403 saying what happened — rather than failing
99 /// deserialization into a bare 400 that says nothing.
100 #[serde(default)]
101 csrf_token: String,
102 name: String,
103}
104
105#[derive(Debug, Deserialize)]
106struct DeleteForm {
107 /// The hidden field every form carries; see [`csrf`](super::csrf).
108 ///
109 /// `default` so that a submission with no token at all is refused by
110 /// `csrf_verified` — a 403 saying what happened — rather than failing
111 /// deserialization into a bare 400 that says nothing.
112 #[serde(default)]
113 csrf_token: String,
114 confirm: String,
115}
116
117/// Set after a successful save so the confirmation survives the redirect.
118///
119/// Post-redirect-get: reloading after a save must not resubmit it.
120#[query_params(error = bad_request)]
121struct Saved {
122 saved: Option<String>,
123}
124
125/// The repository's branches, for the default-branch control.
126///
127/// **One `git` process** — two on an empty repository, which is the case that spends
128/// the least elsewhere. The rows already say which branch `HEAD` names, so nothing has
129/// to ask `symbolic-ref` as well.
130///
131/// An empty list means an empty repository, and the control is left out rather than
132/// rendered with nothing in it.
133async fn branches_of(cx: &Cx, repo: &RepoView) -> Result<Vec<BranchRow>> {
134 // **Before git is asked.** A repository being imported has a directory
135 // `git clone --mirror` is still writing into, or none at all, and `for-each-ref`
136 // against one that is not there is a failed process rather than an empty list — the
137 // settings page would 500 on exactly the repository whose settings someone is
138 // checking. The view says so instead.
139 if repo.import.is_some() {
140 return Ok(Vec::new());
141 }
142
143 // Every branch, not a page of them: this is the default-branch `<select>`, and an
144 // option missing from it is a branch that cannot be chosen — see `one_page`.
145 Ok(list_branches(
146 &repo.handle,
147 &repo.name,
148 None,
149 &current_actor(cx).await?,
150 &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)),
151 &queries(cx),
152 )
153 .await
154 .map_err(server_error)?
155 .map(|page| page.rows.items)
156 .unwrap_or_default())
157}
158
159#[page("/{handle}/repos/{name}/settings")]
160async fn repo_settings_page(cx: &Cx) -> Result {
161 let repo = owned_repo(cx).await?;
162 let saved = query_params::<Saved>(cx)?.saved.is_some();
163 let branches = branches_of(cx, &repo).await?;
164
165 view! {
166 settings_view(
167 handle: repo.handle.as_str(),
168 name: repo.name.as_str(),
169 fields: Fields {
170 description: repo.description.as_deref().unwrap_or(""),
171 visibility: repo.visibility,
172 pinned: repo.pinned,
173 rename_to: repo.name.as_str(),
174 archived: repo.archived,
175 importing: repo.import.is_some(),
176 },
177 branches: &branches,
178 saved: saved,
179 error: "",
180 )
181 }
182}
183
184/// Saves the description and visibility.
185///
186/// Success replies 303 so a reload cannot resubmit — see
187/// [`location`](super::context::location) for why it is spelled this way rather than
188/// with `redirect()`, which is a 307 and would re-POST this form to itself.
189///
190/// Failure re-renders with the reason and **what was typed**, rather than bouncing back
191/// to the stored values and hiding what went wrong.
192#[page(POST "/{handle}/repos/{name}/settings")]
193async fn save(cx: &Cx, Form(submitted): Form<SettingsForm>) -> Result {
194 csrf_verified(cx, &submitted.csrf_token).await?;
195
196 let repo = owned_repo(cx).await?;
197
198 // An unparseable value is a tampered form, not something to default: defaulting
199 // here could publish a repository the owner asked to keep private.
200 let visibility = submitted
201 .visibility
202 .parse::<Visibility>()
203 .map_err(|_| topcoat::router::error::bad_request("unknown visibility"))?;
204
205 let outcome = update_repo(
206 &current_actor(cx).await?,
207 &repo.handle,
208 &repo.name,
209 &RepoEdit {
210 description: optional(&submitted.description),
211 visibility,
212 pinned: submitted.pinned.is_some(),
213 },
214 &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)),
215 )
216 .await;
217
218 let message = match outcome {
219 Ok(_) => {
220 return view! {
221 (StatusCode::SEE_OTHER)
222 (location(&format!(
223 "/{}/repos/{}/settings?saved",
224 repo.handle, repo.name
225 ))?)
226 };
227 }
228 // The visitor's to fix, so it is shown.
229 Err(Error::Domain(DomainError::Validation { field, reason })) => {
230 format!("That {field} is no good: {reason}.")
231 }
232 // Both mean "not yours" here, and both look like a page that is not there.
233 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
234 return Err(not_found().into());
235 }
236 // Ours, so it is logged and answered generically.
237 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
238 };
239
240 let branches = branches_of(cx, &repo).await?;
241
242 view! {
243 settings_view(
244 handle: repo.handle.as_str(),
245 name: repo.name.as_str(),
246 fields: Fields {
247 description: submitted.description.as_str(),
248 visibility,
249 pinned: submitted.pinned.is_some(),
250 rename_to: repo.name.as_str(),
251 archived: repo.archived,
252 importing: repo.import.is_some(),
253 },
254 branches: &branches,
255 saved: false,
256 error: message.as_str(),
257 )
258 }
259}
260
261/// Archives or unarchives the repository.
262///
263/// Both directions through one route, because they are one state with two values and
264/// splitting them would put the rule in the router rather than in the use case.
265#[page(POST "/{handle}/repos/{name}/settings/archive")]
266async fn archive(cx: &Cx, Form(submitted): Form<ArchiveForm>) -> Result {
267 csrf_verified(cx, &submitted.csrf_token).await?;
268
269 let repo = owned_repo(cx).await?;
270
271 // An unparseable value is a tampered form, not something to default: defaulting
272 // here could reopen a repository its owner closed.
273 let archived = match submitted.archived.as_str() {
274 "true" => true,
275 "false" => false,
276 _ => return Err(topcoat::router::error::bad_request("unknown archive state").into()),
277 };
278
279 let message = match set_repo_archived(
280 &current_actor(cx).await?,
281 &repo.handle,
282 &repo.name,
283 archived,
284 &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)),
285 )
286 .await
287 {
288 Ok(_) => {
289 return view! {
290 (StatusCode::SEE_OTHER)
291 (location(&format!(
292 "/{}/repos/{}/settings?saved",
293 repo.handle, repo.name
294 ))?)
295 };
296 }
297 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
298 return Err(not_found().into());
299 }
300 // Reached by a form replayed after the import started — the page renders the
301 // button disabled — so it re-renders with the reason rather than 500ing.
302 Err(Error::Domain(DomainError::Unavailable { reason, .. })) => {
303 format!("Nothing was changed — {reason}")
304 }
305 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
306 };
307
308 let branches = branches_of(cx, &repo).await?;
309
310 view! {
311 settings_view(
312 handle: repo.handle.as_str(),
313 name: repo.name.as_str(),
314 fields: Fields {
315 description: repo.description.as_deref().unwrap_or(""),
316 visibility: repo.visibility,
317 pinned: repo.pinned,
318 rename_to: repo.name.as_str(),
319 archived: repo.archived,
320 importing: repo.import.is_some(),
321 },
322 branches: &branches,
323 saved: false,
324 error: message.as_str(),
325 )
326 }
327}
328
329/// Points `HEAD` at the chosen branch.
330///
331/// No column is written — see
332/// [`set_default_branch`](crate::application::repo::set_default_branch). The landing
333/// page follows `HEAD` on the next request.
334#[page(POST "/{handle}/repos/{name}/settings/default-branch")]
335async fn default_branch(cx: &Cx, Form(submitted): Form<DefaultBranchForm>) -> Result {
336 csrf_verified(cx, &submitted.csrf_token).await?;
337
338 let repo = owned_repo(cx).await?;
339
340 let outcome = set_default_branch(
341 &current_actor(cx).await?,
342 &repo.handle,
343 &repo.name,
344 &submitted.branch,
345 &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)),
346 &queries(cx),
347 &storage(cx),
348 )
349 .await;
350
351 let message = match outcome {
352 Ok(_) => {
353 return view! {
354 (StatusCode::SEE_OTHER)
355 (location(&format!(
356 "/{}/repos/{}/settings?saved",
357 repo.handle, repo.name
358 ))?)
359 };
360 }
361 // A branch that is gone is the one failure a visitor can act on: the select was
362 // rendered from a list that has since changed under them.
363 Err(Error::Domain(DomainError::NotFound { entity: "branch" })) => format!(
364 "{} is not a branch of this repository any more. Nothing changed.",
365 submitted.branch.trim()
366 ),
367 Err(Error::Domain(DomainError::Validation { field, reason })) => {
368 format!("That {field} is no good: {reason}.")
369 }
370 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
371 return Err(not_found().into());
372 }
373 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
374 };
375
376 let branches = branches_of(cx, &repo).await?;
377
378 view! {
379 settings_view(
380 handle: repo.handle.as_str(),
381 name: repo.name.as_str(),
382 fields: Fields {
383 description: repo.description.as_deref().unwrap_or(""),
384 visibility: repo.visibility,
385 pinned: repo.pinned,
386 rename_to: repo.name.as_str(),
387 archived: repo.archived,
388 importing: repo.import.is_some(),
389 },
390 branches: &branches,
391 saved: false,
392 error: message.as_str(),
393 )
394 }
395}
396
397/// Renames the repository, then sends the owner to the new settings URL.
398///
399/// The old URL is gone rather than redirected — see
400/// [`rename_repo`](crate::application::repo::rename_repo) — so the 303 has to name the
401/// new one or the owner lands on their own 404.
402#[page(POST "/{handle}/repos/{name}/settings/rename")]
403async fn rename(cx: &Cx, Form(submitted): Form<RenameForm>) -> Result {
404 csrf_verified(cx, &submitted.csrf_token).await?;
405
406 let repo = owned_repo(cx).await?;
407
408 let outcome = rename_repo(
409 &current_actor(cx).await?,
410 &repo.handle,
411 &repo.name,
412 &submitted.name,
413 &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)),
414 &storage(cx),
415 )
416 .await;
417
418 let message = match outcome {
419 // The **returned** name, not what was typed: it normalised on the way in, and
420 // sending someone to `/MyForge/settings` would 404 on their own repository.
421 Ok(renamed) => {
422 return view! {
423 (StatusCode::SEE_OTHER)
424 (location(&format!(
425 "/{}/repos/{}/settings?saved",
426 repo.handle, renamed.name
427 ))?)
428 };
429 }
430 Err(Error::Domain(DomainError::Validation { field, reason })) => {
431 format!("That {field} is no good: {reason}.")
432 }
433 Err(Error::Domain(DomainError::AlreadyExists { .. })) => {
434 format!(
435 "You already have a repository called {}. Nothing was renamed.",
436 submitted.name.trim()
437 )
438 }
439 // The import owns the directory this would move. Transient, so it says when to
440 // come back rather than what went wrong.
441 Err(Error::Domain(DomainError::Unavailable { reason, .. })) => {
442 format!("Nothing was renamed — {reason}")
443 }
444 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
445 return Err(not_found().into());
446 }
447 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
448 };
449
450 let branches = branches_of(cx, &repo).await?;
451
452 view! {
453 settings_view(
454 handle: repo.handle.as_str(),
455 name: repo.name.as_str(),
456 fields: Fields {
457 description: repo.description.as_deref().unwrap_or(""),
458 visibility: repo.visibility,
459 pinned: repo.pinned,
460 rename_to: submitted.name.as_str(),
461 archived: repo.archived,
462 importing: repo.import.is_some(),
463 },
464 branches: &branches,
465 saved: false,
466 error: message.as_str(),
467 )
468 }
469}
470
471/// Deletes the repository, then sends the owner back to their profile.
472///
473/// The repository page no longer exists, so there is nowhere else to go.
474///
475/// **Guarded by typing the name.** Deletion takes the git history with it and there is
476/// no undo; a single button is too easy to hit by accident for something unrecoverable.
477/// The typed value goes through [`RepoName::new`], so it is compared the same way the
478/// name was normalised on the way in — `MyRepo` confirms `myrepo`, and stray whitespace
479/// is not a reason to refuse.
480#[page(POST "/{handle}/repos/{name}/settings/delete")]
481async fn delete(cx: &Cx, Form(submitted): Form<DeleteForm>) -> Result {
482 csrf_verified(cx, &submitted.csrf_token).await?;
483
484 let repo = owned_repo(cx).await?;
485
486 let confirmed = RepoName::new(&submitted.confirm).is_ok_and(|typed| typed == repo.name);
487
488 if !confirmed {
489 let message = format!(
490 "Type {} exactly to confirm. Nothing was deleted.",
491 repo.name
492 );
493
494 let branches = branches_of(cx, &repo).await?;
495
496 return view! {
497 settings_view(
498 handle: repo.handle.as_str(),
499 name: repo.name.as_str(),
500 fields: Fields {
501 description: repo.description.as_deref().unwrap_or(""),
502 visibility: repo.visibility,
503 pinned: repo.pinned,
504 rename_to: repo.name.as_str(),
505 archived: repo.archived,
506 importing: repo.import.is_some(),
507 },
508 branches: &branches,
509 saved: false,
510 error: message.as_str(),
511 )
512 };
513 }
514
515 match delete_repo(
516 &current_actor(cx).await?,
517 &repo.handle,
518 &repo.name,
519 &Stores::new(&orgs(cx), &memberships(cx), &repos(cx)),
520 &storage(cx),
521 )
522 .await
523 {
524 Ok(()) => {}
525 Err(Error::Domain(DomainError::Forbidden | DomainError::NotFound { .. })) => {
526 return Err(not_found().into());
527 }
528 Err(other) => return Err(server_error(std::io::Error::other(other.to_string()))),
529 }
530
531 view! {
532 (StatusCode::SEE_OTHER)
533 (location(&format!("/{}", repo.handle))?)
534 }
535}
536
537/// The values the forms edit, grouped so the view takes one argument for them rather
538/// than four that must be kept in the same order at five call sites.
539#[derive(Debug, Clone, Copy)]
540struct Fields<'a> {
541 description: &'a str,
542 visibility: Visibility,
543 pinned: bool,
544 /// What the rename field holds. The stored name almost always, and what was typed
545 /// when a rename was refused — a form that discards the attempt hides the reason.
546 rename_to: &'a str,
547 /// Whether the repository is archived. Read-only here: the control is a button that
548 /// flips it, not a field the description form can carry along.
549 archived: bool,
550 /// Whether an import is still landing.
551 ///
552 /// Rename and Archive are refused while one is
553 /// ([`Repository::refuse_writes`](crate::domain::Repository::refuse_writes)), so the
554 /// page must not offer them: a button that always fails is worse than one that is
555 /// visibly not available yet. Description, visibility and pin are unaffected — they
556 /// touch neither the directory nor what the import is landing into.
557 importing: bool,
558}
559
560/// The settings page.
561///
562/// Values arrive as parameters rather than being read back from storage, so a rejected
563/// submission can re-render exactly what was typed.
564#[component]
565async fn settings_view(
566 handle: &str,
567 name: &str,
568 fields: Fields<'_>,
569 /// Every branch, the default first. Empty for a repository with nothing pushed.
570 branches: &[BranchRow],
571 saved: bool,
572 error: &str,
573) -> Result {
574 let Fields {
575 description,
576 visibility,
577 pinned,
578 rename_to,
579 archived,
580 importing,
581 } = fields;
582
583 view! {
584 narrow(
585 <h1 class="text-xl font-semibold tracking-tight">"Repository settings"</h1>
586 <p class="mt-1 font-mono text-sm text-muted-foreground">
587 "@" (handle) " / " (name)
588 </p>
589
590 // The section list. One entry today, and the slot a second lands in — the
591 // page is otherwise a single form and a new feature would have nowhere to
592 // announce itself.
593 <nav class="mt-4 flex items-center gap-4 border-b border-border pb-2 text-sm">
594 <span class="border-b-2 border-primary -mb-2.5 pb-2">"General"</span>
595 <a
596 href=(format!("/{handle}/repos/{name}/settings/hooks"))
597 class="text-muted-foreground hover:text-foreground"
598 >"Webhooks"</a>
599 // Labels live under the Issues tab, not under Settings — they are
600 // reached while looking at issues. This is the second door, because
601 // "where do I change a thing about this repository" is a question people
602 // bring here first.
603 <a
604 href=(format!("/{handle}/repos/{name}/labels"))
605 class="text-muted-foreground hover:text-foreground"
606 >"Labels"</a>
607 </nav>
608
609 if saved {
610 <div class="mt-6">
611 flash(kind: FlashKind::Success, "Repository updated.")
612 </div>
613 }
614
615 // Said once, at the top, rather than beside each disabled control: two
616 // sections are affected and the reason is the same one.
617 if importing {
618 <div class="mt-6">
619 flash(
620 kind: FlashKind::Info,
621 "This repository is still being imported. Its name and its archived \
622 state cannot change until the import finishes."
623 )
624 </div>
625 }
626
627 if !error.is_empty() {
628 <div class="mt-6">
629 flash(kind: FlashKind::Error, (error))
630 </div>
631 }
632
633 <form
634 method="post"
635 action=(format!("/{handle}/repos/{name}/settings"))
636 class="mt-6 space-y-5"
637 >
638 csrf_field()
639 <div class="space-y-2">
640 label(attrs: attributes! { for="description" }, "Description")
641 textarea(
642 attrs: attributes! {
643 id="description"
644 name="description"
645 rows="2"
646 maxlength=(Repository::MAX_DESCRIPTION_LEN.to_string())
647 placeholder="A sentence for your profile."
648 },
649 (description)
650 )
651 <p class="text-xs text-muted-foreground">
652 "Optional. At most "
653 (Repository::MAX_DESCRIPTION_LEN.to_string()) " characters."
654 </p>
655 </div>
656
657 <div class="space-y-2">
658 label(attrs: attributes! { for="visibility" }, "Visibility")
659 select(
660 attrs: attributes! { id="visibility" name="visibility" },
661 <option value="public" selected=(visibility.is_public())>"Public"</option>
662 <option value="private" selected=(!visibility.is_public())>"Private"</option>
663 )
664 <p class="text-xs text-muted-foreground">
665 "A private repository is hidden from your profile and needs a token "
666 "to clone."
667 </p>
668 </div>
669
670 <div class="space-y-2">
671 <div class="flex items-start gap-2">
672 <input
673 id="pinned"
674 name="pinned"
675 type="checkbox"
676 value="on"
677 checked=(pinned)
678 class="mt-0.5"
679 />
680 label(attrs: attributes! { for="pinned" }, "Lead my profile with this")
681 </div>
682 <p class="text-xs text-muted-foreground">
683 "One repository at a time. Choosing this one lets go of whichever "
684 "was chosen before."
685 </p>
686 </div>
687
688 <div class="flex items-center gap-3">
689 button(attrs: attributes! { type="submit" }, "Save")
690 <a
691 href=(format!("/{handle}/repos/{name}"))
692 class="text-sm text-muted-foreground hover:text-foreground"
693 >"Back to repository"</a>
694 </div>
695 </form>
696
697 <section class="mt-8 border-t border-border pt-6">
698 <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground">
699 "Default branch"
700 </h2>
701
702 if importing {
703 // Not "nothing has been pushed yet", which is a different fact and
704 // would read as an empty repository. The mirror brings `HEAD` with
705 // it, so there is nothing to choose here anyway.
706 <p class="mt-2 text-sm text-muted-foreground">
707 "The import brings the source's default branch with it. Once it "
708 "has landed you can point "<code class="font-mono">"HEAD"</code>
709 " somewhere else."
710 </p>
711 } else if branches.is_empty() {
712 <p class="mt-2 text-sm text-muted-foreground">
713 "Nothing has been pushed yet, so there is no branch to choose. "
714 "The first branch you push becomes the default."
715 </p>
716 } else {
717 <form
718 method="post"
719 action=(format!("/{handle}/repos/{name}/settings/default-branch"))
720 class="mt-3 flex flex-wrap items-center gap-3"
721 >
722 csrf_field()
723 select(
724 attrs: attributes! {
725 id="branch"
726 name="branch"
727 class="font-mono sm:w-64"
728 aria-label="Default branch"
729 },
730 for branch in branches {
731 <option
732 value=(branch.name.as_str())
733 selected=(branch.is_default)
734 >(branch.name.as_str())</option>
735 }
736 )
737 button(
738 attrs: attributes! { type="submit" },
739 variant: ButtonVariant::Outline,
740 "Update"
741 )
742 </form>
743 <p class="mt-2 text-xs text-muted-foreground">
744 "What the repository opens at, and what a fresh clone checks out. "
745 "Stored in git as "<code class="font-mono">"HEAD"</code>", not in Steid."
746 </p>
747 }
748 </section>
749
750 <section class="mt-8 border-t border-border pt-6">
751 <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground">
752 if archived { "Archived" } else { "Archive this repository" }
753 </h2>
754 <p class="mt-2 text-sm text-muted-foreground">
755 if archived {
756 "Pushes are refused. Everything that reads still works — browsing, "
757 "cloning, search and downloads."
758 } else {
759 "Marks it finished. Pushes are refused with a message; browsing, "
760 "cloning, search and downloads carry on unchanged. Reversible."
761 }
762 </p>
763
764 <form
765 method="post"
766 action=(format!("/{handle}/repos/{name}/settings/archive"))
767 class="mt-3"
768 >
769 csrf_field()
770 <input
771 type="hidden"
772 name="archived"
773 value=(if archived { "false" } else { "true" })
774 />
775 button(
776 attrs: attributes! { type="submit" disabled=(importing) },
777 variant: ButtonVariant::Outline,
778 if archived { "Unarchive repository" } else { "Archive repository" }
779 )
780 </form>
781 </section>
782
783 <section class="mt-10 rounded-lg border border-border p-4">
784 <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground">
785 "Rename this repository"
786 </h2>
787 <p class="mt-2 text-sm text-muted-foreground">
788 "The old URL stops working straight away — nothing redirects from it. "
789 "Existing clones must update their remote with "
790 <code class="font-mono text-xs">"git remote set-url origin …"</code>"."
791 </p>
792
793 <form
794 method="post"
795 action=(format!("/{handle}/repos/{name}/settings/rename"))
796 class="mt-4 space-y-2"
797 >
798 csrf_field()
799 label(attrs: attributes! { for="rename" }, "New name")
800 input(attrs: attributes! {
801 id="rename"
802 name="name"
803 type="text"
804 value=(rename_to)
805 maxlength=(RepoName::MAX_LEN.to_string())
806 required=(true)
807 autocomplete="off"
808 class="font-mono"
809 })
810 <div class="pt-1">
811 button(
812 attrs: attributes! { type="submit" disabled=(importing) },
813 variant: ButtonVariant::Outline,
814 "Rename repository"
815 )
816 </div>
817 </form>
818 </section>
819
820 <section class="mt-10 rounded-lg border border-destructive/30 p-4">
821 <h2 class="text-xs font-medium uppercase tracking-wider text-destructive">
822 "Delete this repository"
823 </h2>
824 <p class="mt-2 text-sm text-muted-foreground">
825 "This cannot be undone. The commits, branches and tags go with it, and "
826 "anyone with a clone keeps their copy while this instance keeps nothing."
827 </p>
828
829 <form
830 method="post"
831 action=(format!("/{handle}/repos/{name}/settings/delete"))
832 class="mt-4 space-y-2"
833 >
834 csrf_field()
835 label(
836 attrs: attributes! { for="confirm" },
837 "Type " (name) " to confirm"
838 )
839 input(attrs: attributes! {
840 id="confirm"
841 name="confirm"
842 type="text"
843 value=""
844 placeholder=(name)
845 required=(true)
846 autocomplete="off"
847 })
848 <div class="pt-1">
849 button(
850 attrs: attributes! { type="submit" },
851 variant: ButtonVariant::Destructive,
852 "Delete repository"
853 )
854 </div>
855 </form>
856 </section>
857 )
858 }
859}