forge
Explore
Log in

Don't you dare go Hollow

The sidebar links to New organization for those the instance lets create one

Browse files at this commit

2596bea3292bf5f8655eb286f7961c8a780df03dAhmet Kaan GümüşParent: 910da97
All checks have passed
Show checks
  • feat
    • the sidebar links to New organization for those the instance lets create one
    • commit pages, the commit list and compare show the email stored in git next to the name
    • the bell's popover lists unread notifications only and has a Clear action that marks all read, with Open notifications as a full-width footer
  • fix
    • the error box above the new repo and import forms matches their width, and the importer's rate limit message says the wait in minutes and hours
Show full message
✨ feat: the sidebar links to New organization for those the instance lets create one; commit pages, the commit list and compare show the email stored in git next to the name; the bell's popover lists unread notifications only and has a Clear action that marks all read, with Open notifications as a full-width footer; 🐛 fix: the error box above the new repo and import forms matches their width, and the importer's rate limit message says the wait in minutes and hours
crates/forge-web/src/i18n/misc.rsmodified+4 -0
@@ -88,6 +88,7 @@ pub enum K {
8888 // Notifications: inbox page.
8989 MarkAllAsRead,
9090 MarkAllRead,
91+ ClearNotifications,
9192 MarkRead,
9293 NoNotificationsYet,
9394 NoUnreadNotifications,
@@ -256,6 +257,7 @@ const ALL: &[K] = &[
256257 K::NotReceivingThread,
257258 K::MarkAllAsRead,
258259 K::MarkAllRead,
260+ K::ClearNotifications,
259261 K::MarkRead,
260262 K::NoNotificationsYet,
261263 K::NoUnreadNotifications,
@@ -492,6 +494,8 @@ pub fn t(lang: Lang, key: K) -> &'static str {
492494 (MarkAllAsRead, Tr) => "Tümünü okundu olarak işaretle",
493495 (MarkAllRead, En) => "Mark all read",
494496 (MarkAllRead, Tr) => "Tümünü okundu işaretle",
497+ (ClearNotifications, En) => "Clear",
498+ (ClearNotifications, Tr) => "Temizle",
495499 (MarkRead, En) => "Mark read",
496500 (MarkRead, Tr) => "Okundu işaretle",
497501 (NoNotificationsYet, En) => "No notifications yet.",
crates/forge-web/src/importer/api.rsmodified+26 -1
@@ -48,7 +48,8 @@ impl fmt::Display for ApiError {
4848 ApiError::Unauthorized(what) => write!(f, "access denied: {what}"),
4949 ApiError::RateLimited { wait_secs } => write!(
5050 f,
51- "the rate limit is used up and resets in {wait_secs} seconds; retry then, nothing imported is lost"
51+ "the rate limit is used up and resets in {}; retry then, nothing imported is lost",
52+ wait_text(*wait_secs)
5253 ),
5354 ApiError::TooLarge => write!(f, "the file is larger than the allowed size"),
5455 ApiError::Http(msg) => write!(f, "request failed: {msg}"),
@@ -57,6 +58,21 @@ impl fmt::Display for ApiError {
5758 }
5859 }
5960
61+/// `secs` as a reader would say it, rounded up to the minute so a retry at that time is not early.
62+fn wait_text(secs: u64) -> String {
63+ let plural = |n: u64| if n == 1 { "" } else { "s" };
64+ if secs < 60 {
65+ return format!("{secs} second{}", plural(secs));
66+ }
67+ let minutes = secs.div_ceil(60);
68+ let (hours, rest) = (minutes / 60, minutes % 60);
69+ match (hours, rest) {
70+ (0, m) => format!("{m} minute{}", plural(m)),
71+ (h, 0) => format!("{h} hour{}", plural(h)),
72+ (h, m) => format!("{h} hour{} {m} minute{}", plural(h), plural(m)),
73+ }
74+}
75+
6076 pub type ApiResult<T> = Result<T, ApiError>;
6177
6278 #[derive(Debug, Clone, PartialEq, Eq, Default)]
@@ -1427,6 +1443,15 @@ mod tests {
14271443 assert!(valid_path("grp/sub/proj", 2, 20));
14281444 }
14291445
1446+ #[test]
1447+ fn wait_text_reads_naturally() {
1448+ assert_eq!(wait_text(45), "45 seconds");
1449+ assert_eq!(wait_text(60), "1 minute");
1450+ assert_eq!(wait_text(3188), "54 minutes");
1451+ assert_eq!(wait_text(3600), "1 hour");
1452+ assert_eq!(wait_text(3661), "1 hour 2 minutes");
1453+ }
1454+
14301455 #[test]
14311456 fn rate_limit_waits_follow_the_headers() {
14321457 assert_eq!(rate_wait(Some("30"), None, None, 100), Some(30));
crates/forge-web/src/pages/ci_tests.rsmodified+1 -1
@@ -752,7 +752,7 @@ async fn job_page_log_tail() {
752752 assert!(!text.contains("HEAD-MARK"));
753753 assert!(text.contains("Showing the last 512 KiB"));
754754 assert!(
755- page.body.len() < 530 * 1024,
755+ page.body.len() < 540 * 1024,
756756 "page is {} bytes",
757757 page.body.len()
758758 );
crates/forge-web/src/pages/commit.rsmodified+14 -1
@@ -31,6 +31,7 @@ path_param!(oid);
3131 /// Author, committer or parent line data.
3232 struct Person {
3333 name: String,
34+ email: String,
3435 relative: String,
3536 absolute: String,
3637 iso: String,
@@ -145,6 +146,7 @@ async fn commit_page(cx: &Cx) -> Result<impl View> {
145146 let now = now_secs();
146147 let author = Person {
147148 name: info.author_name.clone(),
149+ email: info.author_email.clone(),
148150 relative: relative_time(lang, info.author_time, now),
149151 absolute: format_in_tz(info.author_time, &tz),
150152 iso: iso_time(info.author_time),
@@ -153,6 +155,7 @@ async fn commit_page(cx: &Cx) -> Result<impl View> {
153155 info.committer_name != info.author_name || info.committer_email != info.author_email;
154156 let committer = Person {
155157 name: info.committer_name.clone(),
158+ email: info.committer_email.clone(),
156159 relative: relative_time(lang, info.committer_time, now),
157160 absolute: format_in_tz(info.committer_time, &tz),
158161 iso: iso_time(info.committer_time),
@@ -225,6 +228,8 @@ async fn commit_page(cx: &Cx) -> Result<impl View> {
225228 };
226229 let mut header = ctx.head(state, "commits").await?;
227230 header.live = ref_live::live_url(&owner_name, &repo_name);
231+ let author_mailto = format!("mailto:{}", author.email);
232+ let committer_mailto = format!("mailto:{}", committer.email);
228233 Ok(view! {
229234 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
230235 repo_head(head: header)
@@ -244,6 +249,9 @@ async fn commit_page(cx: &Cx) -> Result<impl View> {
244249 checks_summary(summary: summary, lang: StatusLang(lang))
245250 }
246251 <div class="muted commit-author-line">(g::t(lang, K::AuthorLabel)) <strong>(author.name.as_str())</strong>
252+ if !author.email.is_empty() {
253+ " " <a class="commit-email" href=(author_mailto.as_str())>(author.email.as_str())</a>
254+ }
247255 if has_coauthors {
248256 (g::t(lang, K::CoAuthorAnd))
249257 for c in coauthors.iter() {
@@ -285,7 +293,11 @@ async fn commit_page(cx: &Cx) -> Result<impl View> {
285293 " · " <time data-rel="true" datetime=(author.iso.as_str()) title=(author.absolute.as_str())>(author.relative.as_str())</time>
286294 </div>
287295 if committer_differs {
288- <p class="muted">(g::t(lang, K::CommitterLabel)) <strong>(committer.name.as_str())</strong> " · " <time data-rel="true" datetime=(committer.iso.as_str()) title=(committer.absolute.as_str())>(committer.relative.as_str())</time></p>
296+ <p class="muted">(g::t(lang, K::CommitterLabel)) <strong>(committer.name.as_str())</strong>
297+ if !committer.email.is_empty() {
298+ " " <a class="commit-email" href=(committer_mailto.as_str())>(committer.email.as_str())</a>
299+ }
300+ " · " <time data-rel="true" datetime=(committer.iso.as_str()) title=(committer.absolute.as_str())>(committer.relative.as_str())</time></p>
289301 }
290302 if is_root {
291303 <p class="muted">(g::t(lang, K::RootCommit))</p>
@@ -357,6 +369,7 @@ mod tests {
357369 )
358370 .await;
359371 assert_eq!(status, 200);
372+ assert!(String::from_utf8_lossy(&body).contains("tester@example.com"));
360373 let html = doc(&body);
361374
362375 let rows = rows(&html, "tr.diff-line");
crates/forge-web/src/pages/commits.rsmodified+5 -0
@@ -107,6 +107,7 @@ pub(crate) fn short_oid(oid: &str) -> &str {
107107 pub(crate) struct CommitRow {
108108 pub summary: String,
109109 pub author: String,
110+ pub email: String,
110111 pub commit_href: String,
111112 pub tree_href: String,
112113 pub short: String,
@@ -156,6 +157,7 @@ impl CommitRow {
156157 Self {
157158 summary: emojify(&info.summary).into_owned(),
158159 author: info.author_name.clone(),
160+ email: info.author_email.clone(),
159161 commit_href: format!("/{owner}/{repo}/commit/{}", info.oid),
160162 tree_href: format!("/{owner}/{repo}/tree/{}", info.oid),
161163 short: short_oid(&info.oid).to_owned(),
@@ -299,6 +301,9 @@ async fn commits_page(cx: &Cx) -> Result<impl View> {
299301 <a class="commit-summary" href=(row.commit_href.as_str())>(row.summary.as_str())</a>
300302 <div class="commit-meta muted small">
301303 <span class="commit-author">(row.author.as_str())</span>
304+ if !row.email.is_empty() {
305+ <span class="commit-email">(row.email.as_str())</span>
306+ }
302307 if lang == Lang::Tr {
303308 <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
304309 <span>(g::t(lang, K::Committed))</span>
crates/forge-web/src/pages/compare.rsmodified+3 -0
@@ -348,6 +348,9 @@ async fn compare_view(
348348 <a class="commit-summary" href=(row.commit_href.as_str())>(row.summary.as_str())</a>
349349 <div class="commit-meta muted small">
350350 <span class="commit-author">(row.author.as_str())</span>
351+ if !row.email.is_empty() {
352+ <span class="commit-email">(row.email.as_str())</span>
353+ }
351354 if lang == i18n::Lang::Tr {
352355 <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
353356 <span>(g::t(lang, K::Committed))</span>
crates/forge-web/src/pages/notifications.rsmodified+7 -34
@@ -149,15 +149,6 @@ impl Entry {
149149 }
150150 }
151151
152- fn unread(&self) -> bool {
153- match self {
154- Entry::Issue(note) => note.unread,
155- Entry::Discussion(note) => note.unread,
156- Entry::Advisory(note) => note.unread,
157- Entry::Admin(note) => note.unread,
158- }
159- }
160-
161152 fn updated_at(&self) -> &str {
162153 match self {
163154 Entry::Issue(note) => &note.updated_at,
@@ -373,26 +364,12 @@ async fn list_entries(
373364 Ok(entries)
374365 }
375366
376-/// The bell's popover rows: the viewer's newest entries, unread ones first, then read ones, each
377-/// newest first. Entries the viewer can no longer read are left out and stay as they are.
367+/// The bell's popover rows: the viewer's newest unread entries, newest first. Read entries are
368+/// left out, and so are entries the viewer can no longer read.
378369 async fn peek_rows(state: &AppState, user: &User, lang: Lang, now: i64) -> Result<Vec<RowView>> {
379370 let tz = user.timezone.clone();
380371 let mut entries = list_entries(state, user, true, PEEK_SIZE).await?;
381- // Under PEEK_SIZE unread entries in all, every list was read to its end, so none is missing;
382- // the read ones come from the newest of each list.
383- if entries.len() < PEEK_SIZE as usize {
384- entries.extend(
385- list_entries(state, user, false, PEEK_SIZE)
386- .await?
387- .into_iter()
388- .filter(|entry| !entry.unread()),
389- );
390- }
391- entries.sort_by(|a, b| {
392- b.unread()
393- .cmp(&a.unread())
394- .then_with(|| b.updated_at().cmp(a.updated_at()))
395- });
372+ entries.sort_by(|a, b| b.updated_at().cmp(a.updated_at()));
396373 let mut readable = HashMap::new();
397374 let mut rows = Vec::new();
398375 for entry in &entries {
@@ -569,7 +546,7 @@ async fn inbox(cx: &Cx) -> Result<impl View> {
569546 })
570547 }
571548
572-/// `GET /notifications/peek`: the bell's popover, the viewer's newest notifications as an HTML
549+/// `GET /notifications/peek`: the bell's popover, the viewer's newest unread notifications as an HTML
573550 /// fragment. Anonymous viewers get a bare 401.
574551 #[route(GET "/notifications/peek")]
575552 async fn peek(cx: &Cx) -> Result<Response> {
@@ -585,8 +562,8 @@ async fn peek(cx: &Cx) -> Result<Response> {
585562 fragment.first().await?.into_response(cx)
586563 }
587564
588-/// The bell's popover list: each row opens through its open route, which marks it read. An empty
589-/// list says the viewer is all caught up.
565+/// The bell's popover list of unread rows: each row opens through its open route, which marks it
566+/// read. An empty list says the viewer is all caught up.
590567 #[component]
591568 async fn peek_list(lang: Lang, rows: Vec<RowView>) -> Result<impl View> {
592569 let empty = rows.is_empty();
@@ -598,11 +575,7 @@ async fn peek_list(lang: Lang, rows: Vec<RowView>) -> Result<impl View> {
598575 for row in rows.into_iter() {
599576 <li>
600577 <a class="bell-item" href=(row.open_href.as_str())>
601- if row.unread {
602- <span class="bell-dot unread" aria-hidden="true"></span>
603- } else {
604- <span class="bell-dot" aria-hidden="true"></span>
605- }
578+ <span class="bell-dot unread" aria-hidden="true"></span>
606579 <span class="bell-text">
607580 <span class="bell-line">(row.title_line.as_str())</span>
608581 <span class="bell-meta muted">
crates/forge-web/src/pages/org_new.rsmodified+1 -1
@@ -33,7 +33,7 @@ struct NewOrgForm {
3333 }
3434
3535 /// Whether `user` may create an organization under the instance's policy.
36-fn may_create_org(state: &AppState, user: &User) -> bool {
36+pub(crate) fn may_create_org(state: &AppState, user: &User) -> bool {
3737 match state.live().orgs.creation {
3838 OrgCreation::All => true,
3939 OrgCreation::Admin => user.is_admin,
crates/forge-web/src/views/mod.rsmodified+29 -5
@@ -105,9 +105,12 @@ struct SideRepo {
105105 href: String,
106106 }
107107
108-/// The global nav item for a request path: `dashboard` for `/`, otherwise the first segment when
109-/// it is a global page. Empty for repo pages and everything else.
108+/// The global nav item for a request path: `dashboard` for `/`, `new-org` for `/org/new`, otherwise
109+/// the first segment when it is a global page. Empty for repo pages and everything else.
110110 fn nav_key(path: &str) -> &'static str {
111+ if path.trim_matches('/') == "org/new" {
112+ return "new-org";
113+ }
111114 match path.trim_matches('/').split('/').next().unwrap_or("") {
112115 "" => "dashboard",
113116 "explore" => "explore",
@@ -357,6 +360,8 @@ async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View>
357360 let logout_label = t(lang, Key::LogOut);
358361 let bell_title = i18n::t(lang, Key::Notifications);
359362 let open_label = mi::t(lang, MK::OpenNotifications);
363+ let clear_label = mi::t(lang, MK::ClearNotifications);
364+ let clear_title = mi::t(lang, MK::MarkAllRead);
360365 let loading_label = mi::t(lang, MK::PeekLoading);
361366 let error_label = mi::t(lang, MK::PeekError);
362367 Ok(view! {
@@ -407,7 +412,13 @@ async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View>
407412 <a class="corner-bell" href="/notifications" title=(bell_label) aria-label=(bell_label) aria-expanded="false"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/></svg></a>
408413 <div class="bell-pop" popover="auto" role="dialog" aria-label=(bell_title) data-loading=(loading_label) data-error=(error_label)>
409414 <div class="bell-box">
410- <div class="bell-head">(bell_title)</div>
415+ <div class="bell-head">
416+ <span>(bell_title)</span>
417+ <form method="post" action="/notifications/mark_all_read" class="bell-clear">
418+ <input type="hidden" name="csrf" value=(corner.csrf.as_str())>
419+ <button type="submit" class="link-button" title=(clear_title)>(clear_label)</button>
420+ </form>
421+ </div>
411422 <div class="bell-list"></div>
412423 <a class="button bell-open" href="/notifications">(open_label)</a>
413424 </div>
@@ -454,6 +465,11 @@ pub async fn shell(
454465 },
455466 None => (0, (Vec::new(), 0), InboxKinds::default(), no_runs(), Vec::new()),
456467 };
468+ // The sidebar offers New organization only to those the instance's policy lets create one.
469+ let can_create_org = match (viewer, try_app_context::<AppState>(__cx)) {
470+ (Some((user, _)), Some(state)) => crate::pages::org_new::may_create_org(state, user),
471+ _ => false,
472+ };
457473 let unread_badge = (unread > 0).then(|| unread.to_string());
458474 let side_repos: Vec<SideRepo> = listed
459475 .iter()
@@ -684,7 +700,7 @@ pub async fn shell(
684700 if let Some(section) = section_menu {
685701 section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live)
686702 } else {
687- side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_menu, repos: side_repos_menu)
703+ side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_menu, repos: side_repos_menu, can_create_org: can_create_org)
688704 }
689705 if let Some(corner) = corner_panel {
690706 profile_corner(lang: lang, corner: corner)
@@ -790,7 +806,7 @@ pub async fn shell(
790806 if let Some(section) = section {
791807 section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live)
792808 } else {
793- side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_aside, repos: side_repos)
809+ side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_aside, repos: side_repos, can_create_org: can_create_org)
794810 }
795811 if let Some(corner) = corner_aside {
796812 profile_corner(lang: lang, corner: corner)
@@ -836,6 +852,7 @@ async fn side_nav(
836852 profile_repos_href: &str,
837853 unread: Option<String>,
838854 repos: Vec<SideRepo>,
855+ can_create_org: bool,
839856 ) -> Result<impl View> {
840857 let dashboard = current == "dashboard";
841858 let explore = current == "explore";
@@ -843,6 +860,7 @@ async fn side_nav(
843860 let notifications = current == "notifications";
844861 let snippets = current == "snippets";
845862 let new_repo = current == "new";
863+ let new_org = current == "new-org";
846864 let settings = current == "settings";
847865 let empty = repos.is_empty();
848866 Ok(view! {
@@ -874,6 +892,12 @@ async fn side_nav(
874892 <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 8v8M8 12h8"/></svg>
875893 (t(lang, Key::NewRepository))
876894 </a>
895+ if can_create_org {
896+ <a class=(side_class(new_org)) href="/org/new" aria-current=(new_org.then_some("page"))>
897+ <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 21V5l8-2v18"/><path d="M12 9l8 2v10"/><path d="M2 21h20"/><path d="M8 8v.01M8 12v.01M8 16v.01M16 14v.01M16 18v.01"/></svg>
898+ (o::t(lang, OK::NewOrganization))
899+ </a>
900+ }
877901 <a class=(side_class(settings)) href="/settings/profile" aria-current=(settings.then_some("page"))>
878902 <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3M5.3 5.3l2.1 2.1M16.6 16.6l2.1 2.1M5.3 18.7l2.1-2.1M16.6 7.4l2.1-2.1"/></svg>
879903 (o::t(lang, OK::Settings))
crates/forge-web/tests/e2e/orgs_ui_e2e.rsmodified+16 -0
@@ -490,6 +490,22 @@ async fn org_creation_can_be_limited_to_admins() {
490490 let tahinli = login(&http, "tahinli", PW).await;
491491 let root_session = login(&http, "root", PW).await;
492492
493+ assert!(
494+ !http
495+ .get("/", Some(&tahinli))
496+ .await
497+ .body
498+ .contains("href=\"/org/new\""),
499+ "a person who may not create orgs sees no New organization link"
500+ );
501+ assert!(
502+ http.get("/", Some(&root_session))
503+ .await
504+ .body
505+ .contains("href=\"/org/new\""),
506+ "an admin sees the New organization link"
507+ );
508+
493509 assert_eq!(
494510 http.get("/org/new", Some(&tahinli)).await.status,
495511 403,
style/_import.scssmodified+4 -0
@@ -11,6 +11,10 @@
1111 border-bottom: 1px solid var(--border);
1212 }
1313
14+.import-tabs + .alert {
15+ max-width: 960px;
16+}
17+
1418 .import-tab {
1519 margin-bottom: -1px;
1620 padding: 8px 14px;
style/_repo.scssmodified+5 -0
@@ -1252,6 +1252,11 @@ html.tree-resizing .repo-split::before {
12521252 }
12531253 }
12541254
1255+.commit-email {
1256+ overflow-wrap: anywhere;
1257+ font-size: 0.9em;
1258+}
1259+
12551260 // The full commit hash in its copy box: one line, truncated with an ellipsis when the screen is
12561261 // narrow, so the hash never breaks in the middle. The Copy button always copies the whole hash.
12571262 .commit-info .commit-full-oid {
style/_shell.scssmodified+20 -3
@@ -821,17 +821,33 @@ a.chip {
821821 }
822822
823823 .bell-head {
824+ display: flex;
825+ align-items: center;
826+ justify-content: space-between;
827+ gap: 8px;
824828 padding: 10px 14px 8px;
825829 border-bottom: 1px solid var(--border);
826830 font-size: 14px;
827831 font-weight: 600;
828832 }
829833
834+.bell-clear {
835+ display: none;
836+ margin: 0;
837+ font-size: 13px;
838+ font-weight: 400;
839+}
840+
841+.bell-box:has(.bell-item) .bell-clear {
842+ display: block;
843+}
844+
830845 .bell-list {
831846 flex: 1 1 auto;
832847 min-height: 0;
833848 overflow-y: auto;
834849 padding: 4px;
850+ border-bottom: 1px solid var(--border);
835851 }
836852
837853 .bell-rows {
@@ -897,9 +913,10 @@ a.chip {
897913 }
898914
899915 .bell-open {
900- display: block;
901- margin: 4px;
902- text-align: center;
916+ flex: none;
917+ align-self: stretch;
918+ justify-content: center;
919+ margin: 8px;
903920 text-decoration: none;
904921 }
905922