🔥 remove: repo discussions (threads, categories, answers, discussion notifications, Discussions tab and switch)
Browse files at this commitdd294d6ca323b53443244f2ca10871497ae3cda5Parent: b32181a48 changed files +21 -3891
- crates/forge-core/src/audit.rs +0 -11
- crates/forge-core/src/discussions.rs +0 -114
- crates/forge-core/src/lib.rs +0 -1
- crates/forge-core/src/reactions.rs +0 -4
- crates/forge-core/src/store/discussions.rs +0 -1240
- crates/forge-core/src/store/mod.rs +0 -2
- crates/forge-core/src/store/notifications.rs +2 -7
- crates/forge-core/src/store/reactions.rs +0 -4
- crates/forge-core/src/store/user_delete.rs +0 -101
- crates/forge-e2e/tests/e2e/discussions_e2e.rs +0 -183
- crates/forge-e2e/tests/e2e/main.rs +0 -1
- crates/forge-web-account/src/pages/palette.rs +1 -9
- crates/forge-web-app/src/layers.rs +0 -95
- crates/forge-web-app/src/live.rs +0 -2
- crates/forge-web-app/src/test_support/mod.rs +0 -1
- crates/forge-web-app/src/views/mod.rs +3 -11
- crates/forge-web-base/src/i18n/audit_names.rs +0 -35
- crates/forge-web-base/src/i18n/code.rs +0 -1
- crates/forge-web-base/src/i18n/community.rs +2 -48
- crates/forge-web-base/src/i18n/misc.rs +0 -3
- crates/forge-web-pages/src/pages/code_live.rs +1 -2
- crates/forge-web-pages/src/pages/discussion_settings.rs +0 -88
- crates/forge-web-pages/src/pages/mod.rs +0 -1
- crates/forge-web-pages/src/pages/notifications.rs +1 -109
- crates/forge-web-pages/src/pages/repo.rs +1 -2
- crates/forge-web-pages/src/pages/repo_ctx.rs +0 -3
- crates/forge-web-pages/src/pages/repo_settings.rs +1 -5
- crates/forge-web-repo/Cargo.toml +1 -1
- crates/forge-web-repo/src/pages/discussion_actions.rs +0 -371
- crates/forge-web-repo/src/pages/discussion_live.rs +0 -38
- crates/forge-web-repo/src/pages/discussion_live_tests.rs +0 -223
- crates/forge-web-repo/src/pages/discussion_view.rs +0 -471
- crates/forge-web-repo/src/pages/discussions.rs +0 -511
- crates/forge-web-repo/src/pages/mod.rs +0 -5
- crates/forge-web/assets/nav.js +2 -2
- crates/forge-web/src/boot.rs +0 -1
- crates/forge-web/src/page_route_tests/notifications.rs +0 -71
- crates/forge-web/src/routes.snap +0 -17
- docs/api.md +1 -1
- docs/architecture.md +1 -2
- docs/backlog.md +0 -1
- scripts/audit/seed.py +0 -15
- scripts/audit/shoot.py +1 -3
- style/_min_lists.scss +1 -1
- style/_min_threads.scss +0 -9
- style/_one_threads.scss +2 -36
- style/_pull.scss +0 -13
- style/main.scss +0 -16
crates/forge-core/src/audit.rsmodified+0 -11
| @@ -73,17 +73,6 @@ audit_actions! { | ||
| 73 | 73 | CiRunnerConfigChanged => "ci_runner_config_changed", |
| 74 | 74 | CiRegistrationTokenCreated => "ci_registration_token_created", |
| 75 | 75 | UiPrefsChanged => "ui_prefs_changed", |
| 76 | - DiscussionsEnabled => "discussions_enabled", | |
| 77 | - DiscussionsDisabled => "discussions_disabled", | |
| 78 | - DiscussionCreated => "discussion_created", | |
| 79 | - DiscussionEdited => "discussion_edited", | |
| 80 | - DiscussionDeleted => "discussion_deleted", | |
| 81 | - DiscussionLocked => "discussion_locked", | |
| 82 | - DiscussionUnlocked => "discussion_unlocked", | |
| 83 | - DiscussionAnswered => "discussion_answered", | |
| 84 | - DiscussionCommentCreated => "discussion_comment_created", | |
| 85 | - DiscussionCommentEdited => "discussion_comment_edited", | |
| 86 | - DiscussionCommentDeleted => "discussion_comment_deleted", | |
| 87 | 76 | MailSettingsUpdated => "mail_settings_updated", |
| 88 | 77 | MailTestQueued => "mail_test_queued", |
| 89 | 78 | ServerSettingsUpdated => "server_settings_updated", |
crates/forge-core/src/discussions.rsdeleted+0 -114
| @@ -1,114 +0,0 @@ | ||
| 1 | -use crate::error::{Error, Result}; | |
| 2 | - | |
| 3 | -#[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
| 4 | -pub enum DiscussionCategory { | |
| 5 | - General, | |
| 6 | - Ideas, | |
| 7 | - Qa, | |
| 8 | - Announcements, | |
| 9 | -} | |
| 10 | - | |
| 11 | -pub const DISCUSSION_CATEGORIES: &[DiscussionCategory] = &[ | |
| 12 | - DiscussionCategory::General, | |
| 13 | - DiscussionCategory::Ideas, | |
| 14 | - DiscussionCategory::Qa, | |
| 15 | - DiscussionCategory::Announcements, | |
| 16 | -]; | |
| 17 | - | |
| 18 | -string_enum!(DiscussionCategory { | |
| 19 | - General = "general", | |
| 20 | - Ideas = "ideas", | |
| 21 | - Qa = "qa", | |
| 22 | - Announcements = "announcements", | |
| 23 | -}); | |
| 24 | - | |
| 25 | -impl DiscussionCategory { | |
| 26 | - pub fn label(self) -> &'static str { | |
| 27 | - match self { | |
| 28 | - DiscussionCategory::General => "General", | |
| 29 | - DiscussionCategory::Ideas => "Ideas", | |
| 30 | - DiscussionCategory::Qa => "Q&A", | |
| 31 | - DiscussionCategory::Announcements => "Announcements", | |
| 32 | - } | |
| 33 | - } | |
| 34 | -} | |
| 35 | - | |
| 36 | -#[derive(Debug, Clone, PartialEq, Eq)] | |
| 37 | -pub struct Discussion { | |
| 38 | - pub id: String, | |
| 39 | - pub repo_id: String, | |
| 40 | - pub number: i64, | |
| 41 | - pub category: DiscussionCategory, | |
| 42 | - pub title: String, | |
| 43 | - pub body: String, | |
| 44 | - pub author_id: String, | |
| 45 | - pub answer_comment_id: Option<String>, | |
| 46 | - pub locked: bool, | |
| 47 | - pub comment_count: i64, | |
| 48 | - pub created_at: String, | |
| 49 | - pub updated_at: String, | |
| 50 | -} | |
| 51 | - | |
| 52 | -#[derive(Debug, Clone, PartialEq, Eq)] | |
| 53 | -pub struct DiscussionListItem { | |
| 54 | - pub discussion: Discussion, | |
| 55 | - pub author: String, | |
| 56 | -} | |
| 57 | - | |
| 58 | -#[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
| 59 | -pub enum DiscussionReason { | |
| 60 | - Mention, | |
| 61 | - Reply, | |
| 62 | -} | |
| 63 | - | |
| 64 | -string_enum!(DiscussionReason { | |
| 65 | - Mention = "mention", | |
| 66 | - Reply = "reply", | |
| 67 | -}); | |
| 68 | - | |
| 69 | -#[derive(Debug, Clone, PartialEq, Eq)] | |
| 70 | -pub struct DiscussionNotification { | |
| 71 | - pub discussion_id: String, | |
| 72 | - pub repo_id: String, | |
| 73 | - pub repo_owner: String, | |
| 74 | - pub repo_name: String, | |
| 75 | - pub number: i64, | |
| 76 | - pub title: String, | |
| 77 | - pub reason: DiscussionReason, | |
| 78 | - pub last_actor_name: Option<String>, | |
| 79 | - pub unread: bool, | |
| 80 | - pub updated_at: String, | |
| 81 | -} | |
| 82 | - | |
| 83 | -#[derive(Debug, Clone, PartialEq, Eq)] | |
| 84 | -pub struct DiscussionComment { | |
| 85 | - pub id: String, | |
| 86 | - pub discussion_id: String, | |
| 87 | - pub parent_id: Option<String>, | |
| 88 | - pub author_id: String, | |
| 89 | - pub body: String, | |
| 90 | - pub created_at: String, | |
| 91 | - pub updated_at: String, | |
| 92 | - pub deleted: bool, | |
| 93 | -} | |
| 94 | - | |
| 95 | -#[derive(Debug, Clone, PartialEq, Eq)] | |
| 96 | -pub struct DiscussionFilter { | |
| 97 | - pub category: Option<DiscussionCategory>, | |
| 98 | - pub page: u32, | |
| 99 | - pub per_page: u32, | |
| 100 | -} | |
| 101 | - | |
| 102 | -pub fn validate_discussion(title: &str, body: &str) -> Result<String> { | |
| 103 | - let title = crate::issues::validate_title(title)?; | |
| 104 | - crate::issues::validate_body(body)?; | |
| 105 | - Ok(title) | |
| 106 | -} | |
| 107 | - | |
| 108 | -pub fn validate_comment(body: &str) -> Result<()> { | |
| 109 | - crate::issues::validate_body(body)?; | |
| 110 | - if body.trim().is_empty() { | |
| 111 | - return Err(Error::Invalid("comment is empty".into())); | |
| 112 | - } | |
| 113 | - Ok(()) | |
| 114 | -} |
crates/forge-core/src/lib.rsmodified+0 -1
| @@ -30,7 +30,6 @@ pub mod authz; | ||
| 30 | 30 | pub mod avatar; |
| 31 | 31 | pub mod ci; |
| 32 | 32 | pub mod config; |
| 33 | -pub mod discussions; | |
| 34 | 33 | pub mod error; |
| 35 | 34 | pub mod issue_refs; |
| 36 | 35 | pub mod issues; |
crates/forge-core/src/reactions.rsmodified+0 -4
| @@ -53,15 +53,11 @@ string_enum!(Reaction { | ||
| 53 | 53 | pub enum ReactionTarget { |
| 54 | 54 | Issue, |
| 55 | 55 | Comment, |
| 56 | - Discussion, | |
| 57 | - DiscussionComment, | |
| 58 | 56 | } |
| 59 | 57 | |
| 60 | 58 | string_enum!(ReactionTarget { |
| 61 | 59 | Issue = "issue", |
| 62 | 60 | Comment = "comment", |
| 63 | - Discussion = "discussion", | |
| 64 | - DiscussionComment = "discussion_comment", | |
| 65 | 61 | }); |
| 66 | 62 | |
| 67 | 63 | #[derive(Debug, Clone, PartialEq, Eq)] |
crates/forge-core/src/store/discussions.rsdeleted+0 -1240
| @@ -1,1240 +0,0 @@ | ||
| 1 | -use turso::transaction::Transaction; | |
| 2 | -use turso::{Connection, Row, Value}; | |
| 3 | - | |
| 4 | -use super::finish; | |
| 5 | -use super::issues::parse_db; | |
| 6 | -use super::{ | |
| 7 | - Store, col_int, col_opt_text, col_text, db_err, fetch_all, fetch_opt, insert_err, new_id, | |
| 8 | -}; | |
| 9 | -use crate::discussions::{ | |
| 10 | - Discussion, DiscussionCategory, DiscussionComment, DiscussionFilter, DiscussionListItem, | |
| 11 | - DiscussionNotification, validate_comment, validate_discussion, | |
| 12 | -}; | |
| 13 | -use crate::error::{Error, Result}; | |
| 14 | -use crate::time::now_stamp; | |
| 15 | - | |
| 16 | -const DISCUSSION_COLS: &str = "d.id, d.repo_id, d.number, d.category, d.title, d.body, \ | |
| 17 | - d.author_id, d.answer_comment_id, d.locked, d.comment_count, d.created_at, d.updated_at"; | |
| 18 | -const COMMENT_COLS: &str = "c.id, c.discussion_id, c.parent_id, c.author_id, c.body, \ | |
| 19 | - c.created_at, c.updated_at, c.deleted_at"; | |
| 20 | - | |
| 21 | -fn map_discussion(row: &Row) -> Result<Discussion> { | |
| 22 | - let category = col_text(row, 3)?; | |
| 23 | - Ok(Discussion { | |
| 24 | - id: col_text(row, 0)?, | |
| 25 | - repo_id: col_text(row, 1)?, | |
| 26 | - number: col_int(row, 2)?, | |
| 27 | - category: parse_db(&category)?, | |
| 28 | - title: col_text(row, 4)?, | |
| 29 | - body: col_text(row, 5)?, | |
| 30 | - author_id: col_text(row, 6)?, | |
| 31 | - answer_comment_id: col_opt_text(row, 7)?, | |
| 32 | - locked: col_int(row, 8)? != 0, | |
| 33 | - comment_count: col_int(row, 9)?, | |
| 34 | - created_at: col_text(row, 10)?, | |
| 35 | - updated_at: col_text(row, 11)?, | |
| 36 | - }) | |
| 37 | -} | |
| 38 | - | |
| 39 | -const DISCUSSION_NOTE_SELECT: &str = "SELECT n.discussion_id, n.repo_id, o.username, r.name, \ | |
| 40 | - d.number, d.title, n.reason, a.username, n.unread, n.updated_at FROM discussion_notifications n \ | |
| 41 | - JOIN discussions d ON d.id = n.discussion_id \ | |
| 42 | - JOIN repos r ON r.id = n.repo_id \ | |
| 43 | - JOIN users o ON o.id = r.owner_id \ | |
| 44 | - LEFT JOIN users a ON a.id = n.last_actor_id"; | |
| 45 | - | |
| 46 | -fn map_discussion_note(row: &Row) -> Result<DiscussionNotification> { | |
| 47 | - let reason = col_text(row, 6)?; | |
| 48 | - Ok(DiscussionNotification { | |
| 49 | - discussion_id: col_text(row, 0)?, | |
| 50 | - repo_id: col_text(row, 1)?, | |
| 51 | - repo_owner: col_text(row, 2)?, | |
| 52 | - repo_name: col_text(row, 3)?, | |
| 53 | - number: col_int(row, 4)?, | |
| 54 | - title: col_text(row, 5)?, | |
| 55 | - reason: parse_db(&reason)?, | |
| 56 | - last_actor_name: col_opt_text(row, 7)?, | |
| 57 | - unread: col_int(row, 8)? != 0, | |
| 58 | - updated_at: col_text(row, 9)?, | |
| 59 | - }) | |
| 60 | -} | |
| 61 | - | |
| 62 | -fn map_comment(row: &Row) -> Result<DiscussionComment> { | |
| 63 | - Ok(DiscussionComment { | |
| 64 | - id: col_text(row, 0)?, | |
| 65 | - discussion_id: col_text(row, 1)?, | |
| 66 | - parent_id: col_opt_text(row, 2)?, | |
| 67 | - author_id: col_text(row, 3)?, | |
| 68 | - body: col_text(row, 4)?, | |
| 69 | - created_at: col_text(row, 5)?, | |
| 70 | - updated_at: col_text(row, 6)?, | |
| 71 | - deleted: col_opt_text(row, 7)?.is_some(), | |
| 72 | - }) | |
| 73 | -} | |
| 74 | - | |
| 75 | -async fn discussion_row(conn: &Connection, discussion_id: &str) -> Result<Discussion> { | |
| 76 | - fetch_opt( | |
| 77 | - conn, | |
| 78 | - &format!("SELECT {DISCUSSION_COLS} FROM discussions d WHERE d.id = ?1 LIMIT 1"), | |
| 79 | - (discussion_id.to_string(),), | |
| 80 | - map_discussion, | |
| 81 | - ) | |
| 82 | - .await? | |
| 83 | - .ok_or(Error::NotFound) | |
| 84 | -} | |
| 85 | - | |
| 86 | -pub(super) async fn delete_repo_discussion_rows(tx: &Transaction<'_>, repo_id: &str) -> Result<()> { | |
| 87 | - let id = repo_id.to_string(); | |
| 88 | - for sql in [ | |
| 89 | - "DELETE FROM reactions WHERE target_kind = 'discussion_comment' AND target_id IN \ | |
| 90 | - (SELECT c.id FROM discussion_comments c JOIN discussions d ON d.id = c.discussion_id \ | |
| 91 | - WHERE d.repo_id = ?1)", | |
| 92 | - "DELETE FROM reactions WHERE target_kind = 'discussion' AND target_id IN \ | |
| 93 | - (SELECT id FROM discussions WHERE repo_id = ?1)", | |
| 94 | - "DELETE FROM discussion_notifications WHERE repo_id = ?1", | |
| 95 | - "DELETE FROM discussion_comments WHERE discussion_id IN \ | |
| 96 | - (SELECT id FROM discussions WHERE repo_id = ?1)", | |
| 97 | - "DELETE FROM discussions WHERE repo_id = ?1", | |
| 98 | - ] { | |
| 99 | - tx.execute(sql, (id.clone(),)).await.map_err(db_err)?; | |
| 100 | - } | |
| 101 | - Ok(()) | |
| 102 | -} | |
| 103 | - | |
| 104 | -impl Store { | |
| 105 | - pub async fn discussions_enabled(&self, repo_id: &str) -> Result<bool> { | |
| 106 | - let conn = self.read_conn().await; | |
| 107 | - let flag = fetch_opt( | |
| 108 | - &conn, | |
| 109 | - "SELECT discussions_enabled FROM repos WHERE id = ?1 LIMIT 1", | |
| 110 | - (repo_id.to_string(),), | |
| 111 | - |row| col_int(row, 0), | |
| 112 | - ) | |
| 113 | - .await? | |
| 114 | - .ok_or(Error::NotFound)?; | |
| 115 | - Ok(flag != 0) | |
| 116 | - } | |
| 117 | - | |
| 118 | - pub async fn set_discussions_enabled(&self, repo_id: &str, enabled: bool) -> Result<()> { | |
| 119 | - let conn = self.inner.conn.lock().await; | |
| 120 | - let changed = conn | |
| 121 | - .execute( | |
| 122 | - "UPDATE repos SET discussions_enabled = ?2 WHERE id = ?1", | |
| 123 | - (repo_id.to_string(), i64::from(enabled)), | |
| 124 | - ) | |
| 125 | - .await | |
| 126 | - .map_err(db_err)?; | |
| 127 | - if changed == 0 { | |
| 128 | - return Err(Error::NotFound); | |
| 129 | - } | |
| 130 | - Ok(()) | |
| 131 | - } | |
| 132 | - | |
| 133 | - pub async fn create_discussion( | |
| 134 | - &self, | |
| 135 | - repo_id: &str, | |
| 136 | - author_id: &str, | |
| 137 | - category: DiscussionCategory, | |
| 138 | - title: &str, | |
| 139 | - body: &str, | |
| 140 | - ) -> Result<Discussion> { | |
| 141 | - let title = validate_discussion(title, body)?; | |
| 142 | - let conn = self.inner.conn.lock().await; | |
| 143 | - let tx = conn.unchecked_transaction().await.map_err(db_err)?; | |
| 144 | - let outcome: Result<Discussion> = async { | |
| 145 | - let number = fetch_opt( | |
| 146 | - &tx, | |
| 147 | - "SELECT next_issue_number FROM repos WHERE id = ?1 LIMIT 1", | |
| 148 | - (repo_id.to_string(),), | |
| 149 | - |row| col_int(row, 0), | |
| 150 | - ) | |
| 151 | - .await? | |
| 152 | - .ok_or(Error::NotFound)?; | |
| 153 | - let now = now_stamp(); | |
| 154 | - let id = new_id(); | |
| 155 | - tx.execute( | |
| 156 | - "INSERT INTO discussions (id, repo_id, number, category, title, body, author_id, \ | |
| 157 | - locked, comment_count, created_at, updated_at) \ | |
| 158 | - VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, 0, 0, ?8, ?8)", | |
| 159 | - ( | |
| 160 | - id.clone(), | |
| 161 | - repo_id.to_string(), | |
| 162 | - number, | |
| 163 | - category.as_str().to_string(), | |
| 164 | - title.clone(), | |
| 165 | - body.to_string(), | |
| 166 | - author_id.to_string(), | |
| 167 | - now.clone(), | |
| 168 | - ), | |
| 169 | - ) | |
| 170 | - .await | |
| 171 | - .map_err(|e| insert_err(e, "discussion number already taken"))?; | |
| 172 | - tx.execute( | |
| 173 | - "UPDATE repos SET next_issue_number = next_issue_number + 1 WHERE id = ?1", | |
| 174 | - (repo_id.to_string(),), | |
| 175 | - ) | |
| 176 | - .await | |
| 177 | - .map_err(db_err)?; | |
| 178 | - Ok(Discussion { | |
| 179 | - id, | |
| 180 | - repo_id: repo_id.to_string(), | |
| 181 | - number, | |
| 182 | - category, | |
| 183 | - title, | |
| 184 | - body: body.to_string(), | |
| 185 | - author_id: author_id.to_string(), | |
| 186 | - answer_comment_id: None, | |
| 187 | - locked: false, | |
| 188 | - comment_count: 0, | |
| 189 | - created_at: now.clone(), | |
| 190 | - updated_at: now, | |
| 191 | - }) | |
| 192 | - } | |
| 193 | - .await; | |
| 194 | - finish(tx, outcome).await | |
| 195 | - } | |
| 196 | - | |
| 197 | - pub async fn discussion_by_number( | |
| 198 | - &self, | |
| 199 | - repo_id: &str, | |
| 200 | - number: i64, | |
| 201 | - ) -> Result<Option<Discussion>> { | |
| 202 | - let conn = self.read_conn().await; | |
| 203 | - fetch_opt( | |
| 204 | - &conn, | |
| 205 | - &format!( | |
| 206 | - "SELECT {DISCUSSION_COLS} FROM discussions d WHERE d.repo_id = ?1 AND d.number = ?2 \ | |
| 207 | - LIMIT 1" | |
| 208 | - ), | |
| 209 | - (repo_id.to_string(), number), | |
| 210 | - map_discussion, | |
| 211 | - ) | |
| 212 | - .await | |
| 213 | - } | |
| 214 | - | |
| 215 | - pub async fn list_discussions( | |
| 216 | - &self, | |
| 217 | - repo_id: &str, | |
| 218 | - f: &DiscussionFilter, | |
| 219 | - ) -> Result<(Vec<DiscussionListItem>, u64)> { | |
| 220 | - let mut clauses: Vec<&str> = vec!["d.repo_id = ?"]; | |
| 221 | - let mut params: Vec<Value> = vec![Value::Text(repo_id.to_string())]; | |
| 222 | - if let Some(category) = f.category { | |
| 223 | - clauses.push("d.category = ?"); | |
| 224 | - params.push(Value::Text(category.as_str().to_string())); | |
| 225 | - } | |
| 226 | - let where_sql = clauses.join(" AND "); | |
| 227 | - let per_page = f.per_page.clamp(1, 100); | |
| 228 | - let page = f.page.clamp(1, 1000); | |
| 229 | - let offset = i64::from(page - 1) * i64::from(per_page); | |
| 230 | - | |
| 231 | - let conn = self.read_conn().await; | |
| 232 | - let total = fetch_opt( | |
| 233 | - &conn, | |
| 234 | - &format!("SELECT COUNT(*) FROM discussions d WHERE {where_sql}"), | |
| 235 | - params.clone(), | |
| 236 | - |row| col_int(row, 0), | |
| 237 | - ) | |
| 238 | - .await? | |
| 239 | - .unwrap_or(0); | |
| 240 | - | |
| 241 | - let mut page_params = params; | |
| 242 | - page_params.push(Value::Integer(i64::from(per_page))); | |
| 243 | - page_params.push(Value::Integer(offset)); | |
| 244 | - let items = fetch_all( | |
| 245 | - &conn, | |
| 246 | - &format!( | |
| 247 | - "SELECT {DISCUSSION_COLS}, u.username FROM discussions d \ | |
| 248 | - JOIN users u ON u.id = d.author_id WHERE {where_sql} \ | |
| 249 | - ORDER BY d.updated_at DESC, d.number DESC LIMIT ? OFFSET ?" | |
| 250 | - ), | |
| 251 | - page_params, | |
| 252 | - |row| { | |
| 253 | - Ok(DiscussionListItem { | |
| 254 | - discussion: map_discussion(row)?, | |
| 255 | - author: col_text(row, 12)?, | |
| 256 | - }) | |
| 257 | - }, | |
| 258 | - ) | |
| 259 | - .await?; | |
| 260 | - Ok((items, u64::try_from(total).unwrap_or(0))) | |
| 261 | - } | |
| 262 | - | |
| 263 | - pub async fn edit_discussion( | |
| 264 | - &self, | |
| 265 | - discussion_id: &str, | |
| 266 | - title: &str, | |
| 267 | - body: &str, | |
| 268 | - ) -> Result<()> { | |
| 269 | - let title = validate_discussion(title, body)?; | |
| 270 | - let conn = self.inner.conn.lock().await; | |
| 271 | - let changed = conn | |
| 272 | - .execute( | |
| 273 | - "UPDATE discussions SET title = ?2, body = ?3, updated_at = ?4 WHERE id = ?1", | |
| 274 | - ( | |
| 275 | - discussion_id.to_string(), | |
| 276 | - title, | |
| 277 | - body.to_string(), | |
| 278 | - now_stamp(), | |
| 279 | - ), | |
| 280 | - ) | |
| 281 | - .await | |
| 282 | - .map_err(db_err)?; | |
| 283 | - if changed == 0 { | |
| 284 | - return Err(Error::NotFound); | |
| 285 | - } | |
| 286 | - Ok(()) | |
| 287 | - } | |
| 288 | - | |
| 289 | - pub async fn set_discussion_locked(&self, discussion_id: &str, locked: bool) -> Result<bool> { | |
| 290 | - let conn = self.inner.conn.lock().await; | |
| 291 | - let changed = conn | |
| 292 | - .execute( | |
| 293 | - "UPDATE discussions SET locked = ?2 WHERE id = ?1 AND locked != ?2", | |
| 294 | - (discussion_id.to_string(), i64::from(locked)), | |
| 295 | - ) | |
| 296 | - .await | |
| 297 | - .map_err(db_err)?; | |
| 298 | - if changed > 0 { | |
| 299 | - return Ok(true); | |
| 300 | - } | |
| 301 | - discussion_row(&conn, discussion_id).await?; | |
| 302 | - Ok(false) | |
| 303 | - } | |
| 304 | - | |
| 305 | - pub async fn set_discussion_answer( | |
| 306 | - &self, | |
| 307 | - discussion_id: &str, | |
| 308 | - comment_id: Option<&str>, | |
| 309 | - ) -> Result<()> { | |
| 310 | - let conn = self.inner.conn.lock().await; | |
| 311 | - let discussion = discussion_row(&conn, discussion_id).await?; | |
| 312 | - if discussion.category != DiscussionCategory::Qa { | |
| 313 | - return Err(Error::Invalid("only Q&A discussions have an answer".into())); | |
| 314 | - } | |
| 315 | - if let Some(comment_id) = comment_id { | |
| 316 | - let live = fetch_opt( | |
| 317 | - &conn, | |
| 318 | - "SELECT 1 FROM discussion_comments WHERE id = ?1 AND discussion_id = ?2 \ | |
| 319 | - AND deleted_at IS NULL LIMIT 1", | |
| 320 | - (comment_id.to_string(), discussion_id.to_string()), | |
| 321 | - |row| col_int(row, 0), | |
| 322 | - ) | |
| 323 | - .await?; | |
| 324 | - if live.is_none() { | |
| 325 | - return Err(Error::Invalid( | |
| 326 | - "the answer must be a comment on this discussion".into(), | |
| 327 | - )); | |
| 328 | - } | |
| 329 | - } | |
| 330 | - conn.execute( | |
| 331 | - "UPDATE discussions SET answer_comment_id = ?2 WHERE id = ?1", | |
| 332 | - (discussion_id.to_string(), comment_id.map(str::to_string)), | |
| 333 | - ) | |
| 334 | - .await | |
| 335 | - .map_err(db_err)?; | |
| 336 | - Ok(()) | |
| 337 | - } | |
| 338 | - | |
| 339 | - pub async fn delete_discussion(&self, discussion_id: &str) -> Result<()> { | |
| 340 | - let conn = self.inner.conn.lock().await; | |
| 341 | - let tx = conn.unchecked_transaction().await.map_err(db_err)?; | |
| 342 | - let outcome: Result<()> = async { | |
| 343 | - discussion_row(&tx, discussion_id).await?; | |
| 344 | - let id = discussion_id.to_string(); | |
| 345 | - for sql in [ | |
| 346 | - "DELETE FROM reactions WHERE target_kind = 'discussion_comment' AND target_id IN \ | |
| 347 | - (SELECT id FROM discussion_comments WHERE discussion_id = ?1)", | |
| 348 | - "DELETE FROM reactions WHERE target_kind = 'discussion' AND target_id = ?1", | |
| 349 | - "DELETE FROM discussion_notifications WHERE discussion_id = ?1", | |
| 350 | - "DELETE FROM discussion_comments WHERE discussion_id = ?1", | |
| 351 | - "DELETE FROM discussions WHERE id = ?1", | |
| 352 | - ] { | |
| 353 | - tx.execute(sql, (id.clone(),)).await.map_err(db_err)?; | |
| 354 | - } | |
| 355 | - Ok(()) | |
| 356 | - } | |
| 357 | - .await; | |
| 358 | - finish(tx, outcome).await | |
| 359 | - } | |
| 360 | - | |
| 361 | - pub async fn add_discussion_comment( | |
| 362 | - &self, | |
| 363 | - discussion_id: &str, | |
| 364 | - author_id: &str, | |
| 365 | - parent_id: Option<&str>, | |
| 366 | - body: &str, | |
| 367 | - triage: bool, | |
| 368 | - ) -> Result<DiscussionComment> { | |
| 369 | - validate_comment(body)?; | |
| 370 | - let conn = self.inner.conn.lock().await; | |
| 371 | - let tx = conn.unchecked_transaction().await.map_err(db_err)?; | |
| 372 | - let outcome: Result<DiscussionComment> = async { | |
| 373 | - let discussion = discussion_row(&tx, discussion_id).await?; | |
| 374 | - if discussion.locked && !triage { | |
| 375 | - return Err(Error::Forbidden("this discussion is locked".into())); | |
| 376 | - } | |
| 377 | - if let Some(parent) = parent_id { | |
| 378 | - let row = fetch_opt( | |
| 379 | - &tx, | |
| 380 | - &format!( | |
| 381 | - "SELECT {COMMENT_COLS} FROM discussion_comments c WHERE c.id = ?1 LIMIT 1" | |
| 382 | - ), | |
| 383 | - (parent.to_string(),), | |
| 384 | - map_comment, | |
| 385 | - ) | |
| 386 | - .await? | |
| 387 | - .ok_or(Error::NotFound)?; | |
| 388 | - if row.discussion_id != discussion_id { | |
| 389 | - return Err(Error::NotFound); | |
| 390 | - } | |
| 391 | - if row.parent_id.is_some() { | |
| 392 | - return Err(Error::Invalid("replies nest one level only".into())); | |
| 393 | - } | |
| 394 | - if row.deleted { | |
| 395 | - return Err(Error::Invalid("this comment was deleted".into())); | |
| 396 | - } | |
| 397 | - } | |
| 398 | - let now = now_stamp(); | |
| 399 | - let comment = DiscussionComment { | |
| 400 | - id: new_id(), | |
| 401 | - discussion_id: discussion_id.to_string(), | |
| 402 | - parent_id: parent_id.map(str::to_string), | |
| 403 | - author_id: author_id.to_string(), | |
| 404 | - body: body.to_string(), | |
| 405 | - created_at: now.clone(), | |
| 406 | - updated_at: now.clone(), | |
| 407 | - deleted: false, | |
| 408 | - }; | |
| 409 | - tx.execute( | |
| 410 | - "INSERT INTO discussion_comments (id, discussion_id, parent_id, author_id, body, \ | |
| 411 | - created_at, updated_at) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?6)", | |
| 412 | - ( | |
| 413 | - comment.id.clone(), | |
| 414 | - comment.discussion_id.clone(), | |
| 415 | - comment.parent_id.clone(), | |
| 416 | - comment.author_id.clone(), | |
| 417 | - comment.body.clone(), | |
| 418 | - now.clone(), | |
| 419 | - ), | |
| 420 | - ) | |
| 421 | - .await | |
| 422 | - .map_err(db_err)?; | |
| 423 | - tx.execute( | |
| 424 | - "UPDATE discussions SET comment_count = comment_count + 1, updated_at = ?2 \ | |
| 425 | - WHERE id = ?1", | |
| 426 | - (discussion_id.to_string(), now.clone()), | |
| 427 | - ) | |
| 428 | - .await | |
| 429 | - .map_err(db_err)?; | |
| 430 | - if discussion.author_id != author_id { | |
| 431 | - upsert_discussion_notification( | |
| 432 | - &tx, | |
| 433 | - &discussion.author_id, | |
| 434 | - &discussion.repo_id, | |
| 435 | - discussion_id, | |
| 436 | - "reply", | |
| 437 | - author_id, | |
| 438 | - &now, | |
| 439 | - ) | |
| 440 | - .await?; | |
| 441 | - } | |
| 442 | - Ok(comment) | |
| 443 | - } | |
| 444 | - .await; | |
| 445 | - finish(tx, outcome).await | |
| 446 | - } | |
| 447 | - | |
| 448 | - pub async fn discussion_comment( | |
| 449 | - &self, | |
| 450 | - discussion_id: &str, | |
| 451 | - comment_id: &str, | |
| 452 | - ) -> Result<Option<DiscussionComment>> { | |
| 453 | - let conn = self.read_conn().await; | |
| 454 | - fetch_opt( | |
| 455 | - &conn, | |
| 456 | - &format!( | |
| 457 | - "SELECT {COMMENT_COLS} FROM discussion_comments c WHERE c.id = ?1 \ | |
| 458 | - AND c.discussion_id = ?2 LIMIT 1" | |
| 459 | - ), | |
| 460 | - (comment_id.to_string(), discussion_id.to_string()), | |
| 461 | - map_comment, | |
| 462 | - ) | |
| 463 | - .await | |
| 464 | - } | |
| 465 | - | |
| 466 | - pub async fn edit_discussion_comment(&self, comment_id: &str, body: &str) -> Result<()> { | |
| 467 | - validate_comment(body)?; | |
| 468 | - let conn = self.inner.conn.lock().await; | |
| 469 | - let changed = conn | |
| 470 | - .execute( | |
| 471 | - "UPDATE discussion_comments SET body = ?2, updated_at = ?3 \ | |
| 472 | - WHERE id = ?1 AND deleted_at IS NULL", | |
| 473 | - (comment_id.to_string(), body.to_string(), now_stamp()), | |
| 474 | - ) | |
| 475 | - .await | |
| 476 | - .map_err(db_err)?; | |
| 477 | - if changed == 0 { | |
| 478 | - return Err(Error::NotFound); | |
| 479 | - } | |
| 480 | - Ok(()) | |
| 481 | - } | |
| 482 | - | |
| 483 | - pub async fn delete_discussion_comment(&self, comment_id: &str) -> Result<()> { | |
| 484 | - let conn = self.inner.conn.lock().await; | |
| 485 | - let tx = conn.unchecked_transaction().await.map_err(db_err)?; | |
| 486 | - let outcome: Result<()> = async { | |
| 487 | - let comment = fetch_opt( | |
| 488 | - &tx, | |
| 489 | - &format!("SELECT {COMMENT_COLS} FROM discussion_comments c WHERE c.id = ?1 LIMIT 1"), | |
| 490 | - (comment_id.to_string(),), | |
| 491 | - map_comment, | |
| 492 | - ) | |
| 493 | - .await? | |
| 494 | - .ok_or(Error::NotFound)?; | |
| 495 | - if comment.deleted { | |
| 496 | - return Ok(()); | |
| 497 | - } | |
| 498 | - let now = now_stamp(); | |
| 499 | - tx.execute( | |
| 500 | - "UPDATE discussion_comments SET body = '', deleted_at = ?2, updated_at = ?2 \ | |
| 501 | - WHERE id = ?1", | |
| 502 | - (comment_id.to_string(), now.clone()), | |
| 503 | - ) | |
| 504 | - .await | |
| 505 | - .map_err(db_err)?; | |
| 506 | - tx.execute( | |
| 507 | - "DELETE FROM reactions WHERE target_kind = 'discussion_comment' AND target_id = ?1", | |
| 508 | - (comment_id.to_string(),), | |
| 509 | - ) | |
| 510 | - .await | |
| 511 | - .map_err(db_err)?; | |
| 512 | - tx.execute( | |
| 513 | - "UPDATE discussions SET comment_count = CASE WHEN comment_count > 0 \ | |
| 514 | - THEN comment_count - 1 ELSE 0 END, updated_at = ?2 WHERE id = ?1", | |
| 515 | - (comment.discussion_id.clone(), now), | |
| 516 | - ) | |
| 517 | - .await | |
| 518 | - .map_err(db_err)?; | |
| 519 | - tx.execute( | |
| 520 | - "UPDATE discussions SET answer_comment_id = NULL WHERE id = ?1 AND answer_comment_id = ?2", | |
| 521 | - (comment.discussion_id, comment_id.to_string()), | |
| 522 | - ) | |
| 523 | - .await | |
| 524 | - .map_err(db_err)?; | |
| 525 | - Ok(()) | |
| 526 | - } | |
| 527 | - .await; | |
| 528 | - finish(tx, outcome).await | |
| 529 | - } | |
| 530 | - | |
| 531 | - pub async fn list_discussion_comments( | |
| 532 | - &self, | |
| 533 | - discussion_id: &str, | |
| 534 | - ) -> Result<Vec<DiscussionComment>> { | |
| 535 | - let conn = self.read_conn().await; | |
| 536 | - fetch_all( | |
| 537 | - &conn, | |
| 538 | - &format!( | |
| 539 | - "SELECT {COMMENT_COLS} FROM discussion_comments c WHERE c.discussion_id = ?1 \ | |
| 540 | - ORDER BY c.created_at, c.id" | |
| 541 | - ), | |
| 542 | - (discussion_id.to_string(),), | |
| 543 | - map_comment, | |
| 544 | - ) | |
| 545 | - .await | |
| 546 | - } | |
| 547 | - | |
| 548 | - pub async fn record_discussion_mentions( | |
| 549 | - &self, | |
| 550 | - repo_id: &str, | |
| 551 | - discussion_id: &str, | |
| 552 | - actor_id: &str, | |
| 553 | - user_ids: &[String], | |
| 554 | - ) -> Result<()> { | |
| 555 | - if user_ids.is_empty() { | |
| 556 | - return Ok(()); | |
| 557 | - } | |
| 558 | - let conn = self.inner.conn.lock().await; | |
| 559 | - let now = now_stamp(); | |
| 560 | - for user_id in user_ids { | |
| 561 | - upsert_discussion_notification( | |
| 562 | - &conn, | |
| 563 | - user_id, | |
| 564 | - repo_id, | |
| 565 | - discussion_id, | |
| 566 | - "mention", | |
| 567 | - actor_id, | |
| 568 | - &now, | |
| 569 | - ) | |
| 570 | - .await?; | |
| 571 | - } | |
| 572 | - Ok(()) | |
| 573 | - } | |
| 574 | - | |
| 575 | - pub async fn unread_discussion_mentions(&self, user_id: &str) -> Result<Vec<(String, String)>> { | |
| 576 | - let conn = self.read_conn().await; | |
| 577 | - fetch_all( | |
| 578 | - &conn, | |
| 579 | - "SELECT discussion_id, repo_id FROM discussion_notifications \ | |
| 580 | - WHERE user_id = ?1 AND unread = 1 ORDER BY updated_at DESC", | |
| 581 | - (user_id.to_string(),), | |
| 582 | - |row| Ok((col_text(row, 0)?, col_text(row, 1)?)), | |
| 583 | - ) | |
| 584 | - .await | |
| 585 | - } | |
| 586 | - | |
| 587 | - pub async fn list_discussion_notifications( | |
| 588 | - &self, | |
| 589 | - user_id: &str, | |
| 590 | - unread_only: bool, | |
| 591 | - before: Option<&str>, | |
| 592 | - limit: u32, | |
| 593 | - ) -> Result<Vec<DiscussionNotification>> { | |
| 594 | - let mut sql = format!("{DISCUSSION_NOTE_SELECT} WHERE n.user_id = ?"); | |
| 595 | - let mut params = vec![Value::Text(user_id.to_string())]; | |
| 596 | - if unread_only { | |
| 597 | - sql.push_str(" AND n.unread = 1"); | |
| 598 | - } | |
| 599 | - if let Some(stamp) = before { | |
| 600 | - sql.push_str(" AND n.updated_at < ?"); | |
| 601 | - params.push(Value::Text(stamp.to_string())); | |
| 602 | - } | |
| 603 | - sql.push_str(" ORDER BY n.updated_at DESC, n.discussion_id DESC LIMIT ?"); | |
| 604 | - params.push(Value::Integer(i64::from(limit.clamp(1, 200)))); | |
| 605 | - let conn = self.read_conn().await; | |
| 606 | - fetch_all(&conn, &sql, params, map_discussion_note).await | |
| 607 | - } | |
| 608 | - | |
| 609 | - pub async fn discussion_notification( | |
| 610 | - &self, | |
| 611 | - user_id: &str, | |
| 612 | - discussion_id: &str, | |
| 613 | - ) -> Result<Option<DiscussionNotification>> { | |
| 614 | - let conn = self.read_conn().await; | |
| 615 | - fetch_opt( | |
| 616 | - &conn, | |
| 617 | - &format!( | |
| 618 | - "{DISCUSSION_NOTE_SELECT} WHERE n.user_id = ?1 AND n.discussion_id = ?2 LIMIT 1" | |
| 619 | - ), | |
| 620 | - (user_id.to_string(), discussion_id.to_string()), | |
| 621 | - map_discussion_note, | |
| 622 | - ) | |
| 623 | - .await | |
| 624 | - } | |
| 625 | - | |
| 626 | - pub async fn mark_discussion_notification_read( | |
| 627 | - &self, | |
| 628 | - user_id: &str, | |
| 629 | - discussion_id: &str, | |
| 630 | - ) -> Result<()> { | |
| 631 | - let conn = self.inner.conn.lock().await; | |
| 632 | - conn.execute( | |
| 633 | - "UPDATE discussion_notifications SET unread = 0 WHERE user_id = ?1 AND discussion_id = ?2", | |
| 634 | - (user_id.to_string(), discussion_id.to_string()), | |
| 635 | - ) | |
| 636 | - .await | |
| 637 | - .map_err(db_err)?; | |
| 638 | - Ok(()) | |
| 639 | - } | |
| 640 | - | |
| 641 | - pub async fn mark_all_discussion_notifications_read( | |
| 642 | - &self, | |
| 643 | - user_id: &str, | |
| 644 | - repo_id: Option<&str>, | |
| 645 | - ) -> Result<()> { | |
| 646 | - let conn = self.inner.conn.lock().await; | |
| 647 | - conn.execute( | |
| 648 | - "UPDATE discussion_notifications SET unread = 0 WHERE user_id = ?1 AND unread = 1 \ | |
| 649 | - AND (?2 IS NULL OR repo_id = ?2)", | |
| 650 | - (user_id.to_string(), repo_id.map(str::to_string)), | |
| 651 | - ) | |
| 652 | - .await | |
| 653 | - .map_err(db_err)?; | |
| 654 | - Ok(()) | |
| 655 | - } | |
| 656 | -} | |
| 657 | - | |
| 658 | -async fn upsert_discussion_notification( | |
| 659 | - conn: &Connection, | |
| 660 | - user_id: &str, | |
| 661 | - repo_id: &str, | |
| 662 | - discussion_id: &str, | |
| 663 | - reason: &str, | |
| 664 | - actor_id: &str, | |
| 665 | - now: &str, | |
| 666 | -) -> Result<()> { | |
| 667 | - conn.execute( | |
| 668 | - "INSERT INTO discussion_notifications (user_id, discussion_id, repo_id, reason, \ | |
| 669 | - last_actor_id, unread, updated_at) VALUES (?1, ?2, ?3, ?4, ?5, 1, ?6) \ | |
| 670 | - ON CONFLICT (user_id, discussion_id) DO UPDATE SET \ | |
| 671 | - reason = CASE WHEN excluded.reason = 'mention' OR discussion_notifications.reason = 'mention' \ | |
| 672 | - THEN 'mention' ELSE 'reply' END, last_actor_id = excluded.last_actor_id, unread = 1, \ | |
| 673 | - updated_at = excluded.updated_at", | |
| 674 | - ( | |
| 675 | - user_id.to_string(), | |
| 676 | - discussion_id.to_string(), | |
| 677 | - repo_id.to_string(), | |
| 678 | - reason.to_string(), | |
| 679 | - actor_id.to_string(), | |
| 680 | - now.to_string(), | |
| 681 | - ), | |
| 682 | - ) | |
| 683 | - .await | |
| 684 | - .map_err(db_err)?; | |
| 685 | - Ok(()) | |
| 686 | -} | |
| 687 | - | |
| 688 | -#[cfg(test)] | |
| 689 | -mod tests { | |
| 690 | - use super::*; | |
| 691 | - use crate::discussions::DiscussionReason; | |
| 692 | - use crate::model::{User, Visibility}; | |
| 693 | - | |
| 694 | - struct Fixture { | |
| 695 | - store: Store, | |
| 696 | - tahinli: User, | |
| 697 | - bob: User, | |
| 698 | - repo_id: String, | |
| 699 | - _dir: tempfile::TempDir, | |
| 700 | - } | |
| 701 | - | |
| 702 | - async fn fixture() -> Fixture { | |
| 703 | - let dir = tempfile::tempdir().unwrap(); | |
| 704 | - let store = Store::open(&dir.path().join("forge.db")).await.unwrap(); | |
| 705 | - let tahinli = store | |
| 706 | - .create_user("Tahinli", None, "hash", false) | |
| 707 | - .await | |
| 708 | - .unwrap(); | |
| 709 | - let bob = store.create_user("Bob", None, "hash", false).await.unwrap(); | |
| 710 | - let repo = store | |
| 711 | - .create_repo(&tahinli.id, "proj", "", Visibility::Public, "main") | |
| 712 | - .await | |
| 713 | - .unwrap(); | |
| 714 | - Fixture { | |
| 715 | - store, | |
| 716 | - tahinli, | |
| 717 | - bob, | |
| 718 | - repo_id: repo.id, | |
| 719 | - _dir: dir, | |
| 720 | - } | |
| 721 | - } | |
| 722 | - | |
| 723 | - fn filter(category: Option<DiscussionCategory>) -> DiscussionFilter { | |
| 724 | - DiscussionFilter { | |
| 725 | - category, | |
| 726 | - page: 1, | |
| 727 | - per_page: 25, | |
| 728 | - } | |
| 729 | - } | |
| 730 | - | |
| 731 | - async fn fresh_repo(store: &Store, owner: &str, name: &str) -> String { | |
| 732 | - store | |
| 733 | - .create_repo(owner, name, "", Visibility::Public, "main") | |
| 734 | - .await | |
| 735 | - .unwrap() | |
| 736 | - .id | |
| 737 | - } | |
| 738 | - | |
| 739 | - #[tokio::test] | |
| 740 | - async fn repo_level_rules_hold_in_each_scenario() { | |
| 741 | - let fx = fixture().await; | |
| 742 | - | |
| 743 | - let repo = fresh_repo(&fx.store, &fx.tahinli.id, "toggle").await; | |
| 744 | - assert!( | |
| 745 | - !fx.store.discussions_enabled(&repo).await.unwrap(), | |
| 746 | - "toggle: off by default" | |
| 747 | - ); | |
| 748 | - fx.store.set_discussions_enabled(&repo, true).await.unwrap(); | |
| 749 | - assert!( | |
| 750 | - fx.store.discussions_enabled(&repo).await.unwrap(), | |
| 751 | - "toggle: on after enabling" | |
| 752 | - ); | |
| 753 | - assert!( | |
| 754 | - matches!( | |
| 755 | - fx.store.set_discussions_enabled("missing", true).await, | |
| 756 | - Err(Error::NotFound) | |
| 757 | - ), | |
| 758 | - "toggle: unknown repo" | |
| 759 | - ); | |
| 760 | - | |
| 761 | - let repo = fresh_repo(&fx.store, &fx.tahinli.id, "numbers").await; | |
| 762 | - let issue = fx | |
| 763 | - .store | |
| 764 | - .create_issue(&repo, &fx.tahinli.id, "first", "") | |
| 765 | - .await | |
| 766 | - .unwrap(); | |
| 767 | - let d1 = fx | |
| 768 | - .store | |
| 769 | - .create_discussion(&repo, &fx.tahinli.id, DiscussionCategory::General, "a", "") | |
| 770 | - .await | |
| 771 | - .unwrap(); | |
| 772 | - let issue2 = fx | |
| 773 | - .store | |
| 774 | - .create_issue(&repo, &fx.tahinli.id, "second", "") | |
| 775 | - .await | |
| 776 | - .unwrap(); | |
| 777 | - assert_eq!(issue.number, 1, "numbers: first issue"); | |
| 778 | - assert_eq!(d1.number, 2, "numbers: discussion takes the next slot"); | |
| 779 | - assert_eq!(issue2.number, 3, "numbers: second issue"); | |
| 780 | - let found = fx.store.discussion_by_number(&repo, 2).await.unwrap(); | |
| 781 | - assert_eq!( | |
| 782 | - found.map(|d| d.title), | |
| 783 | - Some("a".to_string()), | |
| 784 | - "numbers: lookup by number" | |
| 785 | - ); | |
| 786 | - | |
| 787 | - let repo = fresh_repo(&fx.store, &fx.tahinli.id, "categories").await; | |
| 788 | - assert!( | |
| 789 | - matches!( | |
| 790 | - fx.store | |
| 791 | - .create_discussion(&repo, &fx.tahinli.id, DiscussionCategory::Ideas, " ", "") | |
| 792 | - .await, | |
| 793 | - Err(Error::Invalid(_)) | |
| 794 | - ), | |
| 795 | - "categories: blank title refused" | |
| 796 | - ); | |
| 797 | - fx.store | |
| 798 | - .create_discussion(&repo, &fx.tahinli.id, DiscussionCategory::Ideas, "idea", "") | |
| 799 | - .await | |
| 800 | - .unwrap(); | |
| 801 | - fx.store | |
| 802 | - .create_discussion(&repo, &fx.bob.id, DiscussionCategory::Qa, "question", "") | |
| 803 | - .await | |
| 804 | - .unwrap(); | |
| 805 | - let (all, total) = fx | |
| 806 | - .store | |
| 807 | - .list_discussions(&repo, &filter(None)) | |
| 808 | - .await | |
| 809 | - .unwrap(); | |
| 810 | - assert_eq!((all.len(), total), (2, 2), "categories: unfiltered list"); | |
| 811 | - let (qa, total) = fx | |
| 812 | - .store | |
| 813 | - .list_discussions(&repo, &filter(Some(DiscussionCategory::Qa))) | |
| 814 | - .await | |
| 815 | - .unwrap(); | |
| 816 | - assert_eq!(total, 1, "categories: qa total"); | |
| 817 | - assert_eq!(qa[0].discussion.title, "question", "categories: qa title"); | |
| 818 | - assert_eq!(qa[0].author, "Bob", "categories: qa author"); | |
| 819 | - } | |
| 820 | - | |
| 821 | - #[tokio::test] | |
| 822 | - async fn thread_rules_hold_in_each_scenario() { | |
| 823 | - let fx = fixture().await; | |
| 824 | - | |
| 825 | - let d = fx | |
| 826 | - .store | |
| 827 | - .create_discussion( | |
| 828 | - &fx.repo_id, | |
| 829 | - &fx.tahinli.id, | |
| 830 | - DiscussionCategory::General, | |
| 831 | - "t", | |
| 832 | - "", | |
| 833 | - ) | |
| 834 | - .await | |
| 835 | - .unwrap(); | |
| 836 | - let top = fx | |
| 837 | - .store | |
| 838 | - .add_discussion_comment(&d.id, &fx.bob.id, None, "hello", false) | |
| 839 | - .await | |
| 840 | - .unwrap(); | |
| 841 | - let reply = fx | |
| 842 | - .store | |
| 843 | - .add_discussion_comment(&d.id, &fx.tahinli.id, Some(&top.id), "hi back", false) | |
| 844 | - .await | |
| 845 | - .unwrap(); | |
| 846 | - assert_eq!( | |
| 847 | - reply.parent_id.as_deref(), | |
| 848 | - Some(top.id.as_str()), | |
| 849 | - "nesting: reply points at its parent" | |
| 850 | - ); | |
| 851 | - let nested = fx | |
| 852 | - .store | |
| 853 | - .add_discussion_comment(&d.id, &fx.bob.id, Some(&reply.id), "too deep", false) | |
| 854 | - .await; | |
| 855 | - assert!( | |
| 856 | - matches!(nested, Err(Error::Invalid(_))), | |
| 857 | - "nesting: too deep" | |
| 858 | - ); | |
| 859 | - assert!( | |
| 860 | - matches!( | |
| 861 | - fx.store | |
| 862 | - .add_discussion_comment(&d.id, &fx.bob.id, None, " ", false) | |
| 863 | - .await, | |
| 864 | - Err(Error::Invalid(_)) | |
| 865 | - ), | |
| 866 | - "nesting: blank body" | |
| 867 | - ); | |
| 868 | - let stored = fx | |
| 869 | - .store | |
| 870 | - .discussion_by_number(&fx.repo_id, d.number) | |
| 871 | - .await | |
| 872 | - .unwrap(); | |
| 873 | - assert_eq!( | |
| 874 | - stored.map(|d| d.comment_count), | |
| 875 | - Some(2), | |
| 876 | - "nesting: comment count" | |
| 877 | - ); | |
| 878 | - let all = fx.store.list_discussion_comments(&d.id).await.unwrap(); | |
| 879 | - assert_eq!(all.len(), 2, "nesting: listed comments"); | |
| 880 | - | |
| 881 | - let qa = fx | |
| 882 | - .store | |
| 883 | - .create_discussion(&fx.repo_id, &fx.tahinli.id, DiscussionCategory::Qa, "q", "") | |
| 884 | - .await | |
| 885 | - .unwrap(); | |
| 886 | - let general = fx | |
| 887 | - .store | |
| 888 | - .create_discussion( | |
| 889 | - &fx.repo_id, | |
| 890 | - &fx.tahinli.id, | |
| 891 | - DiscussionCategory::General, | |
| 892 | - "g", | |
| 893 | - "", | |
| 894 | - ) | |
| 895 | - .await | |
| 896 | - .unwrap(); | |
| 897 | - let c = fx | |
| 898 | - .store | |
| 899 | - .add_discussion_comment(&qa.id, &fx.bob.id, None, "answer", false) | |
| 900 | - .await | |
| 901 | - .unwrap(); | |
| 902 | - let g = fx | |
| 903 | - .store | |
| 904 | - .add_discussion_comment(&general.id, &fx.bob.id, None, "x", false) | |
| 905 | - .await | |
| 906 | - .unwrap(); | |
| 907 | - assert!( | |
| 908 | - matches!( | |
| 909 | - fx.store | |
| 910 | - .set_discussion_answer(&general.id, Some(&g.id)) | |
| 911 | - .await, | |
| 912 | - Err(Error::Invalid(_)) | |
| 913 | - ), | |
| 914 | - "answer: refused outside Q&A" | |
| 915 | - ); | |
| 916 | - assert!( | |
| 917 | - matches!( | |
| 918 | - fx.store.set_discussion_answer(&qa.id, Some(&g.id)).await, | |
| 919 | - Err(Error::Invalid(_)) | |
| 920 | - ), | |
| 921 | - "answer: refused for a comment of another discussion" | |
| 922 | - ); | |
| 923 | - fx.store | |
| 924 | - .set_discussion_answer(&qa.id, Some(&c.id)) | |
| 925 | - .await | |
| 926 | - .unwrap(); | |
| 927 | - let stored = fx | |
| 928 | - .store | |
| 929 | - .discussion_by_number(&fx.repo_id, qa.number) | |
| 930 | - .await | |
| 931 | - .unwrap(); | |
| 932 | - assert_eq!( | |
| 933 | - stored.and_then(|d| d.answer_comment_id), | |
| 934 | - Some(c.id.clone()), | |
| 935 | - "answer: accepted" | |
| 936 | - ); | |
| 937 | - fx.store.delete_discussion_comment(&c.id).await.unwrap(); | |
| 938 | - let stored = fx | |
| 939 | - .store | |
| 940 | - .discussion_by_number(&fx.repo_id, qa.number) | |
| 941 | - .await | |
| 942 | - .unwrap(); | |
| 943 | - assert_eq!( | |
| 944 | - stored.and_then(|d| d.answer_comment_id), | |
| 945 | - None, | |
| 946 | - "answer: cleared when the comment is deleted" | |
| 947 | - ); | |
| 948 | - | |
| 949 | - let d = fx | |
| 950 | - .store | |
| 951 | - .create_discussion( | |
| 952 | - &fx.repo_id, | |
| 953 | - &fx.tahinli.id, | |
| 954 | - DiscussionCategory::General, | |
| 955 | - "t", | |
| 956 | - "", | |
| 957 | - ) | |
| 958 | - .await | |
| 959 | - .unwrap(); | |
| 960 | - let top = fx | |
| 961 | - .store | |
| 962 | - .add_discussion_comment(&d.id, &fx.bob.id, None, "gone soon", false) | |
| 963 | - .await | |
| 964 | - .unwrap(); | |
| 965 | - fx.store | |
| 966 | - .add_discussion_comment(&d.id, &fx.tahinli.id, Some(&top.id), "reply stays", false) | |
| 967 | - .await | |
| 968 | - .unwrap(); | |
| 969 | - assert!( | |
| 970 | - fx.store.set_discussion_locked(&d.id, true).await.unwrap(), | |
| 971 | - "lock: first change reported" | |
| 972 | - ); | |
| 973 | - assert!( | |
| 974 | - !fx.store.set_discussion_locked(&d.id, true).await.unwrap(), | |
| 975 | - "lock: repeat is no change" | |
| 976 | - ); | |
| 977 | - assert!( | |
| 978 | - matches!( | |
| 979 | - fx.store.set_discussion_locked("missing", true).await, | |
| 980 | - Err(Error::NotFound) | |
| 981 | - ), | |
| 982 | - "lock: unknown discussion" | |
| 983 | - ); | |
| 984 | - fx.store.delete_discussion_comment(&top.id).await.unwrap(); | |
| 985 | - let gone = fx | |
| 986 | - .store | |
| 987 | - .discussion_comment(&d.id, &top.id) | |
| 988 | - .await | |
| 989 | - .unwrap() | |
| 990 | - .unwrap(); | |
| 991 | - assert!(gone.deleted, "lock: parent tombstoned"); | |
| 992 | - assert!(gone.body.is_empty(), "lock: parent body cleared"); | |
| 993 | - let all = fx.store.list_discussion_comments(&d.id).await.unwrap(); | |
| 994 | - assert_eq!(all.len(), 2, "lock: tombstone and reply both listed"); | |
| 995 | - assert!( | |
| 996 | - all.iter().any(|c| c.body == "reply stays" && !c.deleted), | |
| 997 | - "lock: reply survives" | |
| 998 | - ); | |
| 999 | - | |
| 1000 | - let d = fx | |
| 1001 | - .store | |
| 1002 | - .create_discussion( | |
| 1003 | - &fx.repo_id, | |
| 1004 | - &fx.tahinli.id, | |
| 1005 | - DiscussionCategory::Ideas, | |
| 1006 | - "old", | |
| 1007 | - "body", | |
| 1008 | - ) | |
| 1009 | - .await | |
| 1010 | - .unwrap(); | |
| 1011 | - fx.store | |
| 1012 | - .edit_discussion(&d.id, "new", "changed") | |
| 1013 | - .await | |
| 1014 | - .unwrap(); | |
| 1015 | - let edited = fx | |
| 1016 | - .store | |
| 1017 | - .discussion_by_number(&fx.repo_id, d.number) | |
| 1018 | - .await | |
| 1019 | - .unwrap(); | |
| 1020 | - assert_eq!( | |
| 1021 | - edited.map(|d| d.title), | |
| 1022 | - Some("new".to_string()), | |
| 1023 | - "edit: title updated" | |
| 1024 | - ); | |
| 1025 | - fx.store | |
| 1026 | - .add_discussion_comment(&d.id, &fx.bob.id, None, "c", false) | |
| 1027 | - .await | |
| 1028 | - .unwrap(); | |
| 1029 | - fx.store.delete_discussion(&d.id).await.unwrap(); | |
| 1030 | - assert!( | |
| 1031 | - fx.store | |
| 1032 | - .discussion_by_number(&fx.repo_id, d.number) | |
| 1033 | - .await | |
| 1034 | - .unwrap() | |
| 1035 | - .is_none(), | |
| 1036 | - "delete: discussion gone" | |
| 1037 | - ); | |
| 1038 | - assert!( | |
| 1039 | - fx.store | |
| 1040 | - .list_discussion_comments(&d.id) | |
| 1041 | - .await | |
| 1042 | - .unwrap() | |
| 1043 | - .is_empty(), | |
| 1044 | - "delete: comments gone" | |
| 1045 | - ); | |
| 1046 | - assert!( | |
| 1047 | - matches!( | |
| 1048 | - fx.store.delete_discussion(&d.id).await, | |
| 1049 | - Err(Error::NotFound) | |
| 1050 | - ), | |
| 1051 | - "delete: second delete is not found" | |
| 1052 | - ); | |
| 1053 | - | |
| 1054 | - let d = fx | |
| 1055 | - .store | |
| 1056 | - .create_discussion( | |
| 1057 | - &fx.repo_id, | |
| 1058 | - &fx.tahinli.id, | |
| 1059 | - DiscussionCategory::General, | |
| 1060 | - "t", | |
| 1061 | - "", | |
| 1062 | - ) | |
| 1063 | - .await | |
| 1064 | - .unwrap(); | |
| 1065 | - fx.store.set_discussion_locked(&d.id, true).await.unwrap(); | |
| 1066 | - let refused = fx | |
| 1067 | - .store | |
| 1068 | - .add_discussion_comment(&d.id, &fx.bob.id, None, "hi", false) | |
| 1069 | - .await; | |
| 1070 | - assert!( | |
| 1071 | - matches!(refused, Err(Error::Forbidden(_))), | |
| 1072 | - "locked: plain comment refused" | |
| 1073 | - ); | |
| 1074 | - let stored = fx | |
| 1075 | - .store | |
| 1076 | - .discussion_by_number(&fx.repo_id, d.number) | |
| 1077 | - .await | |
| 1078 | - .unwrap() | |
| 1079 | - .unwrap(); | |
| 1080 | - assert_eq!(stored.comment_count, 0, "locked: nothing was stored"); | |
| 1081 | - fx.store | |
| 1082 | - .add_discussion_comment(&d.id, &fx.bob.id, None, "maintainer note", true) | |
| 1083 | - .await | |
| 1084 | - .unwrap(); | |
| 1085 | - fx.store.set_discussion_locked(&d.id, false).await.unwrap(); | |
| 1086 | - fx.store | |
| 1087 | - .add_discussion_comment(&d.id, &fx.bob.id, None, "open again", false) | |
| 1088 | - .await | |
| 1089 | - .unwrap(); | |
| 1090 | - } | |
| 1091 | - | |
| 1092 | - #[tokio::test] | |
| 1093 | - async fn inbox_rules_hold_in_each_scenario() { | |
| 1094 | - let fx = fixture().await; | |
| 1095 | - | |
| 1096 | - let ana = fx | |
| 1097 | - .store | |
| 1098 | - .create_user("Ana", None, "hash", false) | |
| 1099 | - .await | |
| 1100 | - .unwrap(); | |
| 1101 | - let ben = fx | |
| 1102 | - .store | |
| 1103 | - .create_user("Ben", None, "hash", false) | |
| 1104 | - .await | |
| 1105 | - .unwrap(); | |
| 1106 | - let repo = fresh_repo(&fx.store, &ana.id, "mentions").await; | |
| 1107 | - let d = fx | |
| 1108 | - .store | |
| 1109 | - .create_discussion(&repo, &ana.id, DiscussionCategory::General, "t", "") | |
| 1110 | - .await | |
| 1111 | - .unwrap(); | |
| 1112 | - for _ in 0..2 { | |
| 1113 | - fx.store | |
| 1114 | - .record_discussion_mentions(&repo, &d.id, &ana.id, std::slice::from_ref(&ben.id)) | |
| 1115 | - .await | |
| 1116 | - .unwrap(); | |
| 1117 | - } | |
| 1118 | - let rows = fx.store.unread_discussion_mentions(&ben.id).await.unwrap(); | |
| 1119 | - assert_eq!( | |
| 1120 | - rows, | |
| 1121 | - vec![(d.id.clone(), repo.clone())], | |
| 1122 | - "mentions: one row after repeats" | |
| 1123 | - ); | |
| 1124 | - assert!( | |
| 1125 | - fx.store | |
| 1126 | - .unread_discussion_mentions(&ana.id) | |
| 1127 | - .await | |
| 1128 | - .unwrap() | |
| 1129 | - .is_empty(), | |
| 1130 | - "mentions: author is not mentioned" | |
| 1131 | - ); | |
| 1132 | - | |
| 1133 | - let cora = fx | |
| 1134 | - .store | |
| 1135 | - .create_user("Cora", None, "hash", false) | |
| 1136 | - .await | |
| 1137 | - .unwrap(); | |
| 1138 | - let dev = fx | |
| 1139 | - .store | |
| 1140 | - .create_user("Dev", None, "hash", false) | |
| 1141 | - .await | |
| 1142 | - .unwrap(); | |
| 1143 | - let repo = fresh_repo(&fx.store, &cora.id, "replies").await; | |
| 1144 | - let d = fx | |
| 1145 | - .store | |
| 1146 | - .create_discussion(&repo, &cora.id, DiscussionCategory::Qa, "Q", "") | |
| 1147 | - .await | |
| 1148 | - .unwrap(); | |
| 1149 | - fx.store | |
| 1150 | - .add_discussion_comment(&d.id, &dev.id, None, "answer", false) | |
| 1151 | - .await | |
| 1152 | - .unwrap(); | |
| 1153 | - fx.store | |
| 1154 | - .add_discussion_comment(&d.id, &cora.id, None, "thanks", false) | |
| 1155 | - .await | |
| 1156 | - .unwrap(); | |
| 1157 | - let rows = fx | |
| 1158 | - .store | |
| 1159 | - .list_discussion_notifications(&cora.id, true, None, 50) | |
| 1160 | - .await | |
| 1161 | - .unwrap(); | |
| 1162 | - assert_eq!(rows.len(), 1, "replies: one row"); | |
| 1163 | - assert_eq!(rows[0].reason, DiscussionReason::Reply, "replies: reason"); | |
| 1164 | - assert_eq!(rows[0].title, "Q", "replies: title"); | |
| 1165 | - assert_eq!(rows[0].number, d.number, "replies: number"); | |
| 1166 | - assert_eq!(rows[0].repo_owner, "Cora", "replies: owner"); | |
| 1167 | - assert_eq!( | |
| 1168 | - rows[0].last_actor_name.as_deref(), | |
| 1169 | - Some("Dev"), | |
| 1170 | - "replies: last actor" | |
| 1171 | - ); | |
| 1172 | - | |
| 1173 | - fx.store | |
| 1174 | - .record_discussion_mentions(&repo, &d.id, &dev.id, std::slice::from_ref(&cora.id)) | |
| 1175 | - .await | |
| 1176 | - .unwrap(); | |
| 1177 | - fx.store | |
| 1178 | - .add_discussion_comment(&d.id, &dev.id, None, "again", false) | |
| 1179 | - .await | |
| 1180 | - .unwrap(); | |
| 1181 | - let rows = fx | |
| 1182 | - .store | |
| 1183 | - .list_discussion_notifications(&cora.id, true, None, 50) | |
| 1184 | - .await | |
| 1185 | - .unwrap(); | |
| 1186 | - assert_eq!(rows.len(), 1, "upgrade: still one row"); | |
| 1187 | - assert_eq!( | |
| 1188 | - rows[0].reason, | |
| 1189 | - DiscussionReason::Mention, | |
| 1190 | - "upgrade: mention wins" | |
| 1191 | - ); | |
| 1192 | - assert_eq!( | |
| 1193 | - fx.store.unread_count(&cora.id).await.unwrap(), | |
| 1194 | - 1, | |
| 1195 | - "upgrade: unread count" | |
| 1196 | - ); | |
| 1197 | - | |
| 1198 | - fx.store | |
| 1199 | - .mark_discussion_notification_read(&dev.id, &d.id) | |
| 1200 | - .await | |
| 1201 | - .unwrap(); | |
| 1202 | - assert_eq!( | |
| 1203 | - fx.store.unread_count(&cora.id).await.unwrap(), | |
| 1204 | - 1, | |
| 1205 | - "mark-read: other user is ignored" | |
| 1206 | - ); | |
| 1207 | - fx.store | |
| 1208 | - .mark_all_discussion_notifications_read(&cora.id, Some(&repo)) | |
| 1209 | - .await | |
| 1210 | - .unwrap(); | |
| 1211 | - assert_eq!( | |
| 1212 | - fx.store.unread_count(&cora.id).await.unwrap(), | |
| 1213 | - 0, | |
| 1214 | - "mark-read: cleared" | |
| 1215 | - ); | |
| 1216 | - assert!( | |
| 1217 | - fx.store | |
| 1218 | - .list_discussion_notifications(&cora.id, true, None, 50) | |
| 1219 | - .await | |
| 1220 | - .unwrap() | |
| 1221 | - .is_empty(), | |
| 1222 | - "mark-read: no unread rows" | |
| 1223 | - ); | |
| 1224 | - let all = fx | |
| 1225 | - .store | |
| 1226 | - .list_discussion_notifications(&cora.id, false, None, 50) | |
| 1227 | - .await | |
| 1228 | - .unwrap(); | |
| 1229 | - assert_eq!(all.len(), 1, "mark-read: read rows still listed"); | |
| 1230 | - assert!(!all[0].unread, "mark-read: row is read"); | |
| 1231 | - assert!( | |
| 1232 | - fx.store | |
| 1233 | - .discussion_notification(&dev.id, &d.id) | |
| 1234 | - .await | |
| 1235 | - .unwrap() | |
| 1236 | - .is_none(), | |
| 1237 | - "mark-read: no row for the commenter" | |
| 1238 | - ); | |
| 1239 | - } | |
| 1240 | -} |
crates/forge-core/src/store/mod.rsmodified+0 -2
| @@ -6,7 +6,6 @@ pub mod backup_runs; | ||
| 6 | 6 | pub mod ci; |
| 7 | 7 | pub mod commit_status; |
| 8 | 8 | pub mod contributions; |
| 9 | -pub mod discussions; | |
| 10 | 9 | pub mod edit_history_read; |
| 11 | 10 | pub mod exports; |
| 12 | 11 | pub mod health; |
| @@ -1174,7 +1173,6 @@ impl Store { | ||
| 1174 | 1173 | reviews::delete_repo_review_rows(&tx, &id).await?; |
| 1175 | 1174 | pulls::delete_repo_pull_rows(&tx, &id).await?; |
| 1176 | 1175 | issues::delete_repo_issue_rows(&tx, &id).await?; |
| 1177 | - discussions::delete_repo_discussion_rows(&tx, &id).await?; | |
| 1178 | 1176 | releases::delete_repo_release_rows(&tx, &id).await?; |
| 1179 | 1177 | for sql in [ |
| 1180 | 1178 | "DELETE FROM webhook_deliveries WHERE hook_id IN (SELECT id FROM webhooks WHERE repo_id = ?1)", |
crates/forge-core/src/store/notifications.rsmodified+2 -7
| @@ -347,16 +347,11 @@ impl Store { | ||
| 347 | 347 | let readable = readable_repo(); |
| 348 | 348 | let sql = format!( |
| 349 | 349 | "SELECT (SELECT COUNT(*) FROM notifications n JOIN repos r ON r.id = n.repo_id \ |
| 350 | - WHERE n.user_id = ? AND n.unread = 1 AND {readable}) + \ | |
| 351 | - (SELECT COUNT(*) FROM discussion_notifications n JOIN repos r ON r.id = n.repo_id \ | |
| 352 | 350 | WHERE n.user_id = ? AND n.unread = 1 AND {readable}) + \ |
| 353 | 351 | (SELECT COUNT(*) FROM admin_notifications WHERE user_id = ? AND unread = 1)" |
| 354 | 352 | ); |
| 355 | - let mut params = Vec::new(); | |
| 356 | - for _ in 0..2 { | |
| 357 | - params.push(Value::Text(user_id.to_string())); | |
| 358 | - params.extend(readable_params(user_id)); | |
| 359 | - } | |
| 353 | + let mut params = vec![Value::Text(user_id.to_string())]; | |
| 354 | + params.extend(readable_params(user_id)); | |
| 360 | 355 | params.push(Value::Text(user_id.to_string())); |
| 361 | 356 | let conn = self.read_conn().await; |
| 362 | 357 | let n = fetch_opt(&conn, &sql, params, |row| col_int(row, 0)) |
crates/forge-core/src/store/reactions.rsmodified+0 -4
| @@ -21,10 +21,6 @@ impl Store { | ||
| 21 | 21 | let exists_sql = match kind { |
| 22 | 22 | ReactionTarget::Issue => "SELECT 1 FROM issues WHERE id = ?1 LIMIT 1", |
| 23 | 23 | ReactionTarget::Comment => "SELECT 1 FROM comments WHERE id = ?1 LIMIT 1", |
| 24 | - ReactionTarget::Discussion => "SELECT 1 FROM discussions WHERE id = ?1 LIMIT 1", | |
| 25 | - ReactionTarget::DiscussionComment => { | |
| 26 | - "SELECT 1 FROM discussion_comments WHERE id = ?1 AND deleted_at IS NULL LIMIT 1" | |
| 27 | - } | |
| 28 | 24 | }; |
| 29 | 25 | if fetch_opt(&tx, exists_sql, (target_id.to_string(),), |row| { |
| 30 | 26 | col_int(row, 0) |
crates/forge-core/src/store/user_delete.rsmodified+0 -101
| @@ -76,19 +76,6 @@ const REASSIGNED: &[(&str, &str, &str, &str)] = &[ | ||
| 76 | 76 | "last_actor_id", |
| 77 | 77 | " AND user_id <> ?1", |
| 78 | 78 | ), |
| 79 | - ("discussions", "discussions", "author_id", ""), | |
| 80 | - ( | |
| 81 | - "discussion comments", | |
| 82 | - "discussion_comments", | |
| 83 | - "author_id", | |
| 84 | - "", | |
| 85 | - ), | |
| 86 | - ( | |
| 87 | - "discussion notification actors", | |
| 88 | - "discussion_notifications", | |
| 89 | - "last_actor_id", | |
| 90 | - " AND user_id <> ?1", | |
| 91 | - ), | |
| 92 | 79 | ]; |
| 93 | 80 | |
| 94 | 81 | const REMOVED: &[(&str, &str, &str)] = &[ |
| @@ -107,11 +94,6 @@ const REMOVED: &[(&str, &str, &str)] = &[ | ||
| 107 | 94 | ("repo watches", "repo_watches", "user_id"), |
| 108 | 95 | ("issue subscriptions", "issue_subscriptions", "user_id"), |
| 109 | 96 | ("notifications", "notifications", "user_id"), |
| 110 | - ( | |
| 111 | - "discussion notifications", | |
| 112 | - "discussion_notifications", | |
| 113 | - "user_id", | |
| 114 | - ), | |
| 115 | 97 | ("admin notifications", "admin_notifications", "user_id"), |
| 116 | 98 | ("reactions", "reactions", "user_id"), |
| 117 | 99 | ("preferences", "user_prefs", "user_id"), |
| @@ -323,7 +305,6 @@ fn missing() -> Error { | ||
| 323 | 305 | #[cfg(test)] |
| 324 | 306 | mod tests { |
| 325 | 307 | use super::*; |
| 326 | - use crate::discussions::DiscussionCategory; | |
| 327 | 308 | use crate::model::Visibility; |
| 328 | 309 | |
| 329 | 310 | struct Fixture { |
| @@ -567,86 +548,4 @@ mod tests { | ||
| 567 | 548 | 0 |
| 568 | 549 | ); |
| 569 | 550 | } |
| 570 | - | |
| 571 | - #[tokio::test] | |
| 572 | - async fn discussions_and_comments_move_to_ghost() { | |
| 573 | - let fx = fixture().await; | |
| 574 | - let mine = fx | |
| 575 | - .store | |
| 576 | - .create_discussion( | |
| 577 | - &fx.repo_id, | |
| 578 | - &fx.tahinli.id, | |
| 579 | - DiscussionCategory::General, | |
| 580 | - "Mine", | |
| 581 | - "", | |
| 582 | - ) | |
| 583 | - .await | |
| 584 | - .unwrap(); | |
| 585 | - let comment = fx | |
| 586 | - .store | |
| 587 | - .add_discussion_comment(&mine.id, &fx.tahinli.id, None, "a comment", false) | |
| 588 | - .await | |
| 589 | - .unwrap(); | |
| 590 | - fx.store | |
| 591 | - .add_discussion_comment(&mine.id, &fx.bob.id, None, "a reply", false) | |
| 592 | - .await | |
| 593 | - .unwrap(); | |
| 594 | - let theirs = fx | |
| 595 | - .store | |
| 596 | - .create_discussion( | |
| 597 | - &fx.repo_id, | |
| 598 | - &fx.bob.id, | |
| 599 | - DiscussionCategory::General, | |
| 600 | - "Theirs", | |
| 601 | - "", | |
| 602 | - ) | |
| 603 | - .await | |
| 604 | - .unwrap(); | |
| 605 | - fx.store | |
| 606 | - .add_discussion_comment(&theirs.id, &fx.tahinli.id, None, "a reply", false) | |
| 607 | - .await | |
| 608 | - .unwrap(); | |
| 609 | - | |
| 610 | - let report = fx | |
| 611 | - .store | |
| 612 | - .delete_user(&fx.tahinli.id, &fx.ghost.id) | |
| 613 | - .await | |
| 614 | - .unwrap(); | |
| 615 | - assert_eq!(reassigned(&report, "discussions"), Some(1)); | |
| 616 | - assert_eq!(reassigned(&report, "discussion comments"), Some(2)); | |
| 617 | - assert_eq!( | |
| 618 | - reassigned(&report, "discussion notification actors"), | |
| 619 | - Some(1) | |
| 620 | - ); | |
| 621 | - let removed = report | |
| 622 | - .removed | |
| 623 | - .iter() | |
| 624 | - .find(|(l, _)| *l == "discussion notifications") | |
| 625 | - .map(|(_, n)| *n); | |
| 626 | - assert_eq!(removed, Some(1)); | |
| 627 | - | |
| 628 | - assert_eq!( | |
| 629 | - scalar( | |
| 630 | - &fx.store, | |
| 631 | - "SELECT COUNT(*) FROM discussions WHERE author_id = ?1", | |
| 632 | - &fx.ghost.id | |
| 633 | - ) | |
| 634 | - .await, | |
| 635 | - 1 | |
| 636 | - ); | |
| 637 | - let kept = fx.store.list_discussion_comments(&mine.id).await.unwrap(); | |
| 638 | - assert_eq!(kept.len(), 2); | |
| 639 | - assert_eq!(kept[0].id, comment.id); | |
| 640 | - assert_eq!(kept[0].author_id, fx.ghost.id); | |
| 641 | - assert_eq!( | |
| 642 | - scalar( | |
| 643 | - &fx.store, | |
| 644 | - "SELECT COUNT(*) FROM discussion_notifications WHERE last_actor_id = ?1", | |
| 645 | - &fx.ghost.id | |
| 646 | - ) | |
| 647 | - .await, | |
| 648 | - 1 | |
| 649 | - ); | |
| 650 | - assert!(fx.store.user_by_id(&fx.tahinli.id).await.unwrap().is_none()); | |
| 651 | - } | |
| 652 | 551 | } |
crates/forge-e2e/tests/e2e/discussions_e2e.rsdeleted+0 -183
| @@ -1,183 +0,0 @@ | ||
| 1 | -use crate::common::{ | |
| 2 | - BOB_CMD, Http, PW, TAHINLI_CMD, boot_forge, create_repo, csrf_for, login, tool_on_path, | |
| 3 | -}; | |
| 4 | - | |
| 5 | -fn anchored_id(location: Option<&str>) -> String { | |
| 6 | - location | |
| 7 | - .and_then(|l| l.rsplit_once("#comment-")) | |
| 8 | - .map(|(_, id)| id.to_owned()) | |
| 9 | - .expect("redirect anchored on a comment") | |
| 10 | -} | |
| 11 | - | |
| 12 | -#[tokio::test] | |
| 13 | -async fn discussions_create_reply_answer_lock_and_toggle() { | |
| 14 | - if !tool_on_path("git") { | |
| 15 | - eprintln!("SKIP discussions_e2e: `git` was not found on PATH"); | |
| 16 | - return; | |
| 17 | - } | |
| 18 | - | |
| 19 | - let root = tempfile::tempdir().expect("temp dir"); | |
| 20 | - let dir = root.path().to_path_buf(); | |
| 21 | - let (_server, ports) = boot_forge(&dir, "", &[TAHINLI_CMD, BOB_CMD]).await; | |
| 22 | - let http = Http::new(ports.http); | |
| 23 | - let tahinli = login(&http, "tahinli", PW).await; | |
| 24 | - let bob = login(&http, "bob", PW).await; | |
| 25 | - create_repo(&http, &tahinli, "pub", "public").await; | |
| 26 | - | |
| 27 | - let repo_page = http.get("/tahinli/pub", Some(tahinli.as_str())).await; | |
| 28 | - assert_eq!(repo_page.status, 200); | |
| 29 | - assert!( | |
| 30 | - !repo_page.body.contains("href=\"/tahinli/pub/discussions\""), | |
| 31 | - "the Discussions tab shows while discussions are off" | |
| 32 | - ); | |
| 33 | - assert_eq!( | |
| 34 | - http.get("/tahinli/pub/discussions", Some(tahinli.as_str())) | |
| 35 | - .await | |
| 36 | - .status, | |
| 37 | - 404, | |
| 38 | - "list while off" | |
| 39 | - ); | |
| 40 | - | |
| 41 | - let csrf = csrf_for(&http, "/tahinli/pub/settings", &tahinli).await; | |
| 42 | - let res = http | |
| 43 | - .post_form( | |
| 44 | - "/tahinli/pub/settings/discussions", | |
| 45 | - &[("csrf", &csrf), ("enabled", "1")], | |
| 46 | - Some(tahinli.as_str()), | |
| 47 | - ) | |
| 48 | - .await; | |
| 49 | - assert_eq!(res.status, 303, "enable: {}", res.body); | |
| 50 | - let repo_page = http.get("/tahinli/pub", Some(tahinli.as_str())).await; | |
| 51 | - assert!( | |
| 52 | - repo_page.body.contains("href=\"/tahinli/pub/discussions\""), | |
| 53 | - "the Discussions tab is missing after turning it on" | |
| 54 | - ); | |
| 55 | - | |
| 56 | - let csrf = csrf_for(&http, "/tahinli/pub/discussions/new", &tahinli).await; | |
| 57 | - let res = http | |
| 58 | - .post_form( | |
| 59 | - "/tahinli/pub/discussions/new", | |
| 60 | - &[ | |
| 61 | - ("csrf", &csrf), | |
| 62 | - ("category", "qa"), | |
| 63 | - ("title", "How do I rebase?"), | |
| 64 | - ("body", "Any tips?"), | |
| 65 | - ], | |
| 66 | - Some(tahinli.as_str()), | |
| 67 | - ) | |
| 68 | - .await; | |
| 69 | - assert_eq!(res.status, 303, "create: {}", res.body); | |
| 70 | - assert_eq!( | |
| 71 | - res.location().as_deref(), | |
| 72 | - Some("/tahinli/pub/discussions/1") | |
| 73 | - ); | |
| 74 | - let discussion = "/tahinli/pub/discussions/1"; | |
| 75 | - | |
| 76 | - let csrf_bob = csrf_for(&http, discussion, &bob).await; | |
| 77 | - let res = http | |
| 78 | - .post_form( | |
| 79 | - &format!("{discussion}/comments"), | |
| 80 | - &[("csrf", &csrf_bob), ("body", "Try git rebase -i.")], | |
| 81 | - Some(bob.as_str()), | |
| 82 | - ) | |
| 83 | - .await; | |
| 84 | - assert_eq!(res.status, 303, "top comment: {}", res.body); | |
| 85 | - let top = anchored_id(res.location().as_deref()); | |
| 86 | - | |
| 87 | - let res = http | |
| 88 | - .post_form( | |
| 89 | - &format!("{discussion}/comments"), | |
| 90 | - &[ | |
| 91 | - ("csrf", &csrf_bob), | |
| 92 | - ("parent", &top), | |
| 93 | - ("body", "Thanks, that worked."), | |
| 94 | - ], | |
| 95 | - Some(bob.as_str()), | |
| 96 | - ) | |
| 97 | - .await; | |
| 98 | - assert_eq!(res.status, 303, "reply: {}", res.body); | |
| 99 | - let reply = anchored_id(res.location().as_deref()); | |
| 100 | - | |
| 101 | - let res = http | |
| 102 | - .post_form( | |
| 103 | - &format!("{discussion}/comments"), | |
| 104 | - &[ | |
| 105 | - ("csrf", &csrf_bob), | |
| 106 | - ("parent", &reply), | |
| 107 | - ("body", "Too deep"), | |
| 108 | - ], | |
| 109 | - Some(bob.as_str()), | |
| 110 | - ) | |
| 111 | - .await; | |
| 112 | - assert_eq!(res.status, 200, "nested reply shows the refusal page"); | |
| 113 | - assert!( | |
| 114 | - res.body.contains("Could not save") && res.body.contains("one level"), | |
| 115 | - "nested reply was not refused: {}", | |
| 116 | - res.body | |
| 117 | - ); | |
| 118 | - | |
| 119 | - let csrf_tahinli = csrf_for(&http, discussion, &tahinli).await; | |
| 120 | - let res = http | |
| 121 | - .post_form( | |
| 122 | - &format!("{discussion}/answer"), | |
| 123 | - &[ | |
| 124 | - ("csrf", &csrf_tahinli), | |
| 125 | - ("comment_id", &top), | |
| 126 | - ("answer", "1"), | |
| 127 | - ], | |
| 128 | - Some(tahinli.as_str()), | |
| 129 | - ) | |
| 130 | - .await; | |
| 131 | - assert_eq!(res.status, 303, "answer: {}", res.body); | |
| 132 | - let page = http.get(discussion, Some(bob.as_str())).await; | |
| 133 | - assert!( | |
| 134 | - page.body.contains("Answered"), | |
| 135 | - "the answered badge is missing after marking an answer" | |
| 136 | - ); | |
| 137 | - | |
| 138 | - let csrf_tahinli = csrf_for(&http, discussion, &tahinli).await; | |
| 139 | - let res = http | |
| 140 | - .post_form( | |
| 141 | - &format!("{discussion}/lock"), | |
| 142 | - &[("csrf", &csrf_tahinli), ("locked", "1")], | |
| 143 | - Some(tahinli.as_str()), | |
| 144 | - ) | |
| 145 | - .await; | |
| 146 | - assert_eq!(res.status, 303, "lock: {}", res.body); | |
| 147 | - let res = http | |
| 148 | - .post_form( | |
| 149 | - &format!("{discussion}/comments"), | |
| 150 | - &[("csrf", &csrf_bob), ("body", "Still here")], | |
| 151 | - Some(bob.as_str()), | |
| 152 | - ) | |
| 153 | - .await; | |
| 154 | - assert_eq!(res.status, 403, "bob comments on a locked discussion"); | |
| 155 | - let res = http | |
| 156 | - .post_form( | |
| 157 | - &format!("{discussion}/lock"), | |
| 158 | - &[("csrf", &csrf_bob), ("locked", "0")], | |
| 159 | - Some(bob.as_str()), | |
| 160 | - ) | |
| 161 | - .await; | |
| 162 | - assert_eq!(res.status, 403, "bob locks a discussion"); | |
| 163 | - | |
| 164 | - let csrf = csrf_for(&http, "/tahinli/pub/settings", &tahinli).await; | |
| 165 | - let res = http | |
| 166 | - .post_form( | |
| 167 | - "/tahinli/pub/settings/discussions", | |
| 168 | - &[("csrf", &csrf), ("enabled", "0")], | |
| 169 | - Some(tahinli.as_str()), | |
| 170 | - ) | |
| 171 | - .await; | |
| 172 | - assert_eq!(res.status, 303, "disable: {}", res.body); | |
| 173 | - let repo_page = http.get("/tahinli/pub", Some(tahinli.as_str())).await; | |
| 174 | - assert!( | |
| 175 | - !repo_page.body.contains("href=\"/tahinli/pub/discussions\""), | |
| 176 | - "the tab stays after turning discussions off" | |
| 177 | - ); | |
| 178 | - assert_eq!( | |
| 179 | - http.get(discussion, Some(tahinli.as_str())).await.status, | |
| 180 | - 404, | |
| 181 | - "discussion page while off" | |
| 182 | - ); | |
| 183 | -} |
crates/forge-e2e/tests/e2e/main.rsmodified+0 -1
| @@ -5,7 +5,6 @@ mod branch_protection_e2e; | ||
| 5 | 5 | mod browse_e2e; |
| 6 | 6 | mod ci_e2e; |
| 7 | 7 | mod community_i18n_e2e; |
| 8 | -mod discussions_e2e; | |
| 9 | 8 | mod git_e2e; |
| 10 | 9 | mod i18n_e2e; |
| 11 | 10 | mod issue_close_e2e; |
crates/forge-web-account/src/pages/palette.rsmodified+1 -9
| @@ -286,15 +286,7 @@ fn repo_pages(lang: Lang) -> Vec<Value> { | ||
| 286 | 286 | &settings, |
| 287 | 287 | "settings", |
| 288 | 288 | true, |
| 289 | - &[ | |
| 290 | - "Description", | |
| 291 | - "Açıklama", | |
| 292 | - "Features", | |
| 293 | - "Özellikler", | |
| 294 | - "Wiki", | |
| 295 | - "Discussions", | |
| 296 | - "Tartışmalar", | |
| 297 | - ], | |
| 289 | + &["Description", "Açıklama", "Features", "Özellikler", "Wiki"], | |
| 298 | 290 | ), |
| 299 | 291 | repo_page( |
| 300 | 292 | admin(RK::BranchProtection), |
crates/forge-web-app/src/layers.rsmodified+0 -95
| @@ -7,7 +7,6 @@ use topcoat::router::request::{method, uri}; | ||
| 7 | 7 | use crate::live::Topic; |
| 8 | 8 | use crate::state::AppState; |
| 9 | 9 | |
| 10 | -pub use discussion_write::DiscussionWriteLayer; | |
| 11 | 10 | pub use not_found_layer::NotFoundLayer; |
| 12 | 11 | pub use org_write::OrgWriteLayer; |
| 13 | 12 | pub use pull_write::PullWriteLayer; |
| @@ -287,100 +286,6 @@ mod pull_write { | ||
| 287 | 286 | } |
| 288 | 287 | } |
| 289 | 288 | |
| 290 | -mod discussion_write { | |
| 291 | - use topcoat::context::{Cx, context}; | |
| 292 | - use topcoat::router::response::Response; | |
| 293 | - use topcoat::router::{Body, Layer, LayerFuture, Next, Path}; | |
| 294 | - | |
| 295 | - use super::post_segments; | |
| 296 | - use crate::live::Topic; | |
| 297 | - use crate::state::AppState; | |
| 298 | - | |
| 299 | - enum Written { | |
| 300 | - List { | |
| 301 | - owner: String, | |
| 302 | - repo: String, | |
| 303 | - }, | |
| 304 | - Discussion { | |
| 305 | - owner: String, | |
| 306 | - repo: String, | |
| 307 | - number: String, | |
| 308 | - }, | |
| 309 | - } | |
| 310 | - | |
| 311 | - fn written(cx: &Cx) -> Option<Written> { | |
| 312 | - let parts = post_segments(cx)?; | |
| 313 | - let [owner, repo, kind, rest @ ..] = parts.as_slice() else { | |
| 314 | - return None; | |
| 315 | - }; | |
| 316 | - let (owner, repo) = ((*owner).to_owned(), (*repo).to_owned()); | |
| 317 | - match (*kind, rest) { | |
| 318 | - ("discussions", ["new"]) => Some(Written::List { owner, repo }), | |
| 319 | - ("discussions", [number, ..]) => Some(Written::Discussion { | |
| 320 | - owner, | |
| 321 | - repo, | |
| 322 | - number: (*number).to_owned(), | |
| 323 | - }), | |
| 324 | - ("settings", ["discussions"]) => Some(Written::List { owner, repo }), | |
| 325 | - _ => None, | |
| 326 | - } | |
| 327 | - } | |
| 328 | - | |
| 329 | - async fn topics_of(state: &AppState, target: Written) -> Vec<Topic> { | |
| 330 | - let (owner, name) = match &target { | |
| 331 | - Written::List { owner, repo } | Written::Discussion { owner, repo, .. } => { | |
| 332 | - (owner.as_str(), repo.as_str()) | |
| 333 | - } | |
| 334 | - }; | |
| 335 | - let repo = match state.store.repo_by_owner_and_name(owner, name).await { | |
| 336 | - Ok(Some(repo)) => repo, | |
| 337 | - Ok(None) => return Vec::new(), | |
| 338 | - Err(e) => { | |
| 339 | - tracing::error!(error = %e, owner, name, "live: loading the repo to bump failed"); | |
| 340 | - return Vec::new(); | |
| 341 | - } | |
| 342 | - }; | |
| 343 | - let mut topics = vec![Topic::Discussions(repo.id.clone())]; | |
| 344 | - if let Written::Discussion { number, .. } = target | |
| 345 | - && let Ok(number) = number.parse::<i64>() | |
| 346 | - { | |
| 347 | - match state.store.discussion_by_number(&repo.id, number).await { | |
| 348 | - Ok(Some(discussion)) => topics.push(Topic::Discussion(discussion.id)), | |
| 349 | - Ok(None) => {} | |
| 350 | - Err(e) => { | |
| 351 | - tracing::error!(error = %e, number, "live: loading the discussion to bump failed") | |
| 352 | - } | |
| 353 | - } | |
| 354 | - } | |
| 355 | - topics | |
| 356 | - } | |
| 357 | - | |
| 358 | - pub struct DiscussionWriteLayer; | |
| 359 | - | |
| 360 | - impl Layer for DiscussionWriteLayer { | |
| 361 | - fn path(&self) -> Option<&Path> { | |
| 362 | - None | |
| 363 | - } | |
| 364 | - | |
| 365 | - fn handle<'a>(&'a self, cx: &'a Cx, body: Body, next: Next<'a>) -> LayerFuture<'a> { | |
| 366 | - Box::pin(bump_after_write(cx, body, next)) | |
| 367 | - } | |
| 368 | - } | |
| 369 | - | |
| 370 | - async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> topcoat::Result<Response> { | |
| 371 | - let state = context::<AppState>(cx); | |
| 372 | - let topics = match written(cx) { | |
| 373 | - Some(target) => topics_of(state, target).await, | |
| 374 | - None => Vec::new(), | |
| 375 | - }; | |
| 376 | - let result = next.run(cx, body).await; | |
| 377 | - for topic in &topics { | |
| 378 | - state.live.bump(topic); | |
| 379 | - } | |
| 380 | - result | |
| 381 | - } | |
| 382 | -} | |
| 383 | - | |
| 384 | 289 | mod org_write { |
| 385 | 290 | use topcoat::context::{Cx, context}; |
| 386 | 291 | use topcoat::router::response::Response; |
crates/forge-web-app/src/live.rsmodified+0 -2
| @@ -27,8 +27,6 @@ pub enum Topic { | ||
| 27 | 27 | ReviewRequests(String), |
| 28 | 28 | Imports(String), |
| 29 | 29 | Explore, |
| 30 | - Discussions(String), | |
| 31 | - Discussion(String), | |
| 32 | 30 | Wiki(String), |
| 33 | 31 | Snippets, |
| 34 | 32 | Snippet(String), |
crates/forge-web-app/src/test_support/mod.rsmodified+0 -1
| @@ -101,7 +101,6 @@ pub fn app_router(state: AppState) -> Router { | ||
| 101 | 101 | .layer(RepoMovedLayer) |
| 102 | 102 | .layer(crate::layers::RepoSettingsWriteLayer) |
| 103 | 103 | .layer(crate::layers::PullWriteLayer) |
| 104 | - .layer(crate::layers::DiscussionWriteLayer) | |
| 105 | 104 | .layer(crate::layers::OrgWriteLayer) |
| 106 | 105 | .layer(TowerLayer::new(crate::compression::ResponseCompression)) |
| 107 | 106 | .with(Compression::disable()) |
crates/forge-web-app/src/views/mod.rsmodified+3 -11
| @@ -154,8 +154,8 @@ fn step_label(lang: Lang, word: &str) -> String { | ||
| 154 | 154 | |
| 155 | 155 | fn repo_section_label(lang: Lang, kind: &str) -> Option<String> { |
| 156 | 156 | match kind { |
| 157 | - "issues" | "pulls" | "ci" | "commits" | "branches" | "tags" | "releases" | |
| 158 | - | "discussions" | "wiki" | "settings" => Some(tab_title(lang, kind, "")), | |
| 157 | + "issues" | "pulls" | "ci" | "commits" | "branches" | "tags" | "releases" | "wiki" | |
| 158 | + | "settings" => Some(tab_title(lang, kind, "")), | |
| 159 | 159 | "milestones" => Some(s(lang, "Milestones", "Kilometre taşları").to_owned()), |
| 160 | 160 | "labels" => Some(s(lang, "Labels", "Etiketler").to_owned()), |
| 161 | 161 | _ => None, |
| @@ -273,7 +273,7 @@ fn path_segments(lang: Lang, path: &str, title: &str) -> Vec<(String, Option<Str | ||
| 273 | 273 | (Some(label), rest) => { |
| 274 | 274 | segments.push((label, Some(repo_href(owner, repo, section, "")))); |
| 275 | 275 | let item = rest[0].as_str(); |
| 276 | - let numbered = matches!(section, "issues" | "pulls" | "discussions") | |
| 276 | + let numbered = matches!(section, "issues" | "pulls") | |
| 277 | 277 | && item.bytes().all(|b| b.is_ascii_digit()); |
| 278 | 278 | match (section, rest) { |
| 279 | 279 | ("ci", [runs, number]) if runs == "runs" => { |
| @@ -1286,7 +1286,6 @@ pub async fn repo_tabs( | ||
| 1286 | 1286 | lang: Lang, |
| 1287 | 1287 | #[default] open_issues: Option<u64>, |
| 1288 | 1288 | #[default] open_pulls: Option<u64>, |
| 1289 | - #[default] discussions: bool, | |
| 1290 | 1289 | #[default] wiki: bool, |
| 1291 | 1290 | ) -> Result<impl View> { |
| 1292 | 1291 | let home = repo_href(&owner, &repo, "", ""); |
| @@ -1305,7 +1304,6 @@ pub async fn repo_tabs( | ||
| 1305 | 1304 | ); |
| 1306 | 1305 | let code_on = active == "code" || more_on; |
| 1307 | 1306 | let settings = repo_href(&owner, &repo, "settings", ""); |
| 1308 | - let discussions_tab = repo_href(&owner, &repo, "discussions", ""); | |
| 1309 | 1307 | let wiki_tab = repo_href(&owner, &repo, "wiki", ""); |
| 1310 | 1308 | Ok(view! { |
| 1311 | 1309 | <nav class="repo-tabs" aria-label=(g::t(lang, K::RepositoryNav))> |
| @@ -1338,11 +1336,6 @@ pub async fn repo_tabs( | ||
| 1338 | 1336 | <a class=(tab_class(active == "ci")) href=(ci)> |
| 1339 | 1337 | (g::t(lang, K::TabCi)) |
| 1340 | 1338 | </a> |
| 1341 | - if discussions { | |
| 1342 | - <a class=(tab_class(active == "discussions")) href=(discussions_tab)> | |
| 1343 | - (g::t(lang, K::TabDiscussions)) | |
| 1344 | - </a> | |
| 1345 | - } | |
| 1346 | 1339 | if wiki { |
| 1347 | 1340 | <a class=(tab_class(active == "wiki")) href=(wiki_tab)> |
| 1348 | 1341 | (g::t(lang, K::TabWiki)) |
| @@ -1602,7 +1595,6 @@ pub fn tab_title(lang: Lang, active: &str, repo: &str) -> String { | ||
| 1602 | 1595 | "branches" => g::t(lang, K::BranchesTitle).to_owned(), |
| 1603 | 1596 | "tags" => g::t(lang, K::TagsTitle).to_owned(), |
| 1604 | 1597 | "releases" => g::t(lang, K::TabReleases).to_owned(), |
| 1605 | - "discussions" => g::t(lang, K::TabDiscussions).to_owned(), | |
| 1606 | 1598 | "wiki" => g::t(lang, K::TabWiki).to_owned(), |
| 1607 | 1599 | "settings" => g::t(lang, K::TabSettings).to_owned(), |
| 1608 | 1600 | _ => repo.to_owned(), |
crates/forge-web-base/src/i18n/audit_names.rsmodified+0 -35
| @@ -114,28 +114,6 @@ pub fn action_name(lang: Lang, action: &str) -> Option<&'static str> { | ||
| 114 | 114 | ("ci_registration_token_created", Lang::Tr) => Some("CI kayıt belirteci oluşturuldu"), |
| 115 | 115 | ("ui_prefs_changed", Lang::En) => Some("Display preferences changed"), |
| 116 | 116 | ("ui_prefs_changed", Lang::Tr) => Some("Görünüm tercihleri değiştirildi"), |
| 117 | - ("discussions_enabled", Lang::En) => Some("Discussions turned on"), | |
| 118 | - ("discussions_enabled", Lang::Tr) => Some("Tartışmalar açıldı"), | |
| 119 | - ("discussions_disabled", Lang::En) => Some("Discussions turned off"), | |
| 120 | - ("discussions_disabled", Lang::Tr) => Some("Tartışmalar kapatıldı"), | |
| 121 | - ("discussion_created", Lang::En) => Some("Discussion created"), | |
| 122 | - ("discussion_created", Lang::Tr) => Some("Tartışma oluşturuldu"), | |
| 123 | - ("discussion_edited", Lang::En) => Some("Discussion edited"), | |
| 124 | - ("discussion_edited", Lang::Tr) => Some("Tartışma düzenlendi"), | |
| 125 | - ("discussion_deleted", Lang::En) => Some("Discussion deleted"), | |
| 126 | - ("discussion_deleted", Lang::Tr) => Some("Tartışma silindi"), | |
| 127 | - ("discussion_locked", Lang::En) => Some("Discussion locked"), | |
| 128 | - ("discussion_locked", Lang::Tr) => Some("Tartışma kilitlendi"), | |
| 129 | - ("discussion_unlocked", Lang::En) => Some("Discussion unlocked"), | |
| 130 | - ("discussion_unlocked", Lang::Tr) => Some("Tartışmanın kilidi açıldı"), | |
| 131 | - ("discussion_answered", Lang::En) => Some("Discussion answered"), | |
| 132 | - ("discussion_answered", Lang::Tr) => Some("Tartışma yanıtlandı"), | |
| 133 | - ("discussion_comment_created", Lang::En) => Some("Discussion comment posted"), | |
| 134 | - ("discussion_comment_created", Lang::Tr) => Some("Tartışmaya yorum eklendi"), | |
| 135 | - ("discussion_comment_edited", Lang::En) => Some("Discussion comment edited"), | |
| 136 | - ("discussion_comment_edited", Lang::Tr) => Some("Tartışma yorumu düzenlendi"), | |
| 137 | - ("discussion_comment_deleted", Lang::En) => Some("Discussion comment deleted"), | |
| 138 | - ("discussion_comment_deleted", Lang::Tr) => Some("Tartışma yorumu silindi"), | |
| 139 | 117 | ("mail_settings_updated", Lang::En) => Some("Mail settings updated"), |
| 140 | 118 | ("mail_settings_updated", Lang::Tr) => Some("E-posta ayarları güncellendi"), |
| 141 | 119 | ("mail_test_queued", Lang::En) => Some("Test email queued"), |
| @@ -234,8 +212,6 @@ pub fn target_kind_name(lang: Lang, kind: &str) -> Option<&'static str> { | ||
| 234 | 212 | ("ci_runner_token", Lang::Tr) => Some("CI çalıştırıcı belirteci"), |
| 235 | 213 | ("comment", Lang::En) => Some("comment"), |
| 236 | 214 | ("comment", Lang::Tr) => Some("yorum"), |
| 237 | - ("discussion", Lang::En) => Some("discussion"), | |
| 238 | - ("discussion", Lang::Tr) => Some("tartışma"), | |
| 239 | 215 | ("fsck", Lang::En) => Some("integrity check"), |
| 240 | 216 | ("fsck", Lang::Tr) => Some("bütünlük denetimi"), |
| 241 | 217 | ("gpg_key", Lang::En) => Some("GPG key"), |
| @@ -454,17 +430,6 @@ mod tests { | ||
| 454 | 430 | "ci_runner_config_changed", |
| 455 | 431 | "ci_registration_token_created", |
| 456 | 432 | "ui_prefs_changed", |
| 457 | - "discussions_enabled", | |
| 458 | - "discussions_disabled", | |
| 459 | - "discussion_created", | |
| 460 | - "discussion_edited", | |
| 461 | - "discussion_deleted", | |
| 462 | - "discussion_locked", | |
| 463 | - "discussion_unlocked", | |
| 464 | - "discussion_answered", | |
| 465 | - "discussion_comment_created", | |
| 466 | - "discussion_comment_edited", | |
| 467 | - "discussion_comment_deleted", | |
| 468 | 433 | "mail_settings_updated", |
| 469 | 434 | "mail_test_queued", |
| 470 | 435 | "server_settings_updated", |
crates/forge-web-base/src/i18n/code.rsmodified+0 -1
| @@ -107,7 +107,6 @@ strings! { | ||
| 107 | 107 | TabCommits => "Commits", "Commitler"; |
| 108 | 108 | TabReleases => "Releases", "Sürümler"; |
| 109 | 109 | TabCi => "CI", "CI"; |
| 110 | - TabDiscussions => "Discussions", "Tartışmalar"; | |
| 111 | 110 | TabWiki => "Wiki", "Wiki"; |
| 112 | 111 | TabSettings => "Settings", "Ayarlar"; |
| 113 | 112 | } |
crates/forge-web-base/src/i18n/community.rsmodified+2 -48
| @@ -1,44 +1,14 @@ | ||
| 1 | -use forge_core::discussions::DiscussionCategory; | |
| 2 | - | |
| 3 | 1 | use super::Lang; |
| 4 | 2 | |
| 5 | 3 | strings! { |
| 6 | 4 | K; |
| 7 | - AllCategories => "All", "Tümü"; | |
| 8 | - CategoriesNav => "Discussion categories", "Tartışma kategorileri"; | |
| 9 | - NewDiscussion => "New discussion", "Yeni tartışma"; | |
| 10 | - NoDiscussionsYet => "No discussions here yet.", "Henüz tartışma yok."; | |
| 11 | - Discussions => "Discussions", "Tartışmalar"; | |
| 12 | - Category => "Category", "Kategori"; | |
| 13 | 5 | Title => "Title", "Başlık"; |
| 14 | 6 | Description => "Description", "Açıklama"; |
| 15 | - StartDiscussion => "Start discussion", "Tartışma başlat"; | |
| 16 | 7 | Save => "Save", "Kaydet"; |
| 17 | 8 | Delete => "Delete", "Sil"; |
| 18 | 9 | Edit => "Edit", "Düzenle"; |
| 19 | - EditComment => "Edit comment", "Yorumu düzenle"; | |
| 20 | 10 | CouldNotSave => "Could not save", "Kaydedilemedi"; |
| 21 | - CommentDeleted => "Comment deleted", "Yorum silindi"; | |
| 22 | - Answer => "Answer", "Cevap"; | |
| 23 | - MarkAsAnswer => "Mark as answer", "Cevap olarak işaretle"; | |
| 24 | - UnmarkAnswer => "Unmark answer", "Cevap işaretini kaldır"; | |
| 25 | 11 | Reply => "Reply", "Yanıtla"; |
| 26 | - DeleteDiscussion => "Delete discussion", "Tartışmayı sil"; | |
| 27 | - Conversation => "Conversation", "Konuşma"; | |
| 28 | - LockConversation => "Lock conversation", "Konuşmayı kilitle"; | |
| 29 | - UnlockConversation => "Unlock conversation", "Konuşmanın kilidini aç"; | |
| 30 | - Answered => "Answered", "Cevaplandı"; | |
| 31 | - Locked => "Locked", "Kilitli"; | |
| 32 | - NoDescription => "_No description provided._", "_Açıklama eklenmedi._"; | |
| 33 | - LockedNotice => "This conversation is locked. Only people with Triage access can comment.", "Bu konuşma kilitli. Yorum yalnızca Triage erişimi olanlar tarafından yapılabilir."; | |
| 34 | - AddComment => "Add a comment", "Yorum ekle"; | |
| 35 | - CommentButton => "Comment", "Yorum yap"; | |
| 36 | - ToCommentSuffix => " to comment.", "."; | |
| 37 | - ArchivedDiscussions => "This repository is archived, so its discussions are read-only.", "Bu depo arşivlendiği için tartışmalar salt okunur."; | |
| 38 | - CategoryGeneral => "General", "Genel"; | |
| 39 | - CategoryIdeas => "Ideas", "Fikirler"; | |
| 40 | - CategoryQa => "Q&A", "Soru-cevap"; | |
| 41 | - CategoryAnnouncements => "Announcements", "Duyurular"; | |
| 42 | 12 | |
| 43 | 13 | Wiki => "Wiki", "Wiki"; |
| 44 | 14 | Home => "Home", "Ana sayfa"; |
| @@ -90,22 +60,6 @@ strings! { | ||
| 90 | 60 | ChooseVisibility => "Choose a visibility.", "Bir görünürlük seçin."; |
| 91 | 61 | } |
| 92 | 62 | |
| 93 | -pub fn category_label(lang: Lang, category: DiscussionCategory) -> &'static str { | |
| 94 | - match category { | |
| 95 | - DiscussionCategory::General => t(lang, K::CategoryGeneral), | |
| 96 | - DiscussionCategory::Ideas => t(lang, K::CategoryIdeas), | |
| 97 | - DiscussionCategory::Qa => t(lang, K::CategoryQa), | |
| 98 | - DiscussionCategory::Announcements => t(lang, K::CategoryAnnouncements), | |
| 99 | - } | |
| 100 | -} | |
| 101 | - | |
| 102 | -pub fn byline(lang: Lang) -> (&'static str, &'static str, &'static str) { | |
| 103 | - match lang { | |
| 104 | - Lang::En => (" by ", " ", ""), | |
| 105 | - Lang::Tr => ("", " tarafından ", " açıldı"), | |
| 106 | - } | |
| 107 | -} | |
| 108 | - | |
| 109 | 63 | pub fn comments_count(lang: Lang, count: i64) -> String { |
| 110 | 64 | match lang { |
| 111 | 65 | Lang::En => format!("{count} comment{}", if count == 1 { "" } else { "s" }), |
| @@ -181,8 +135,8 @@ mod tests { | ||
| 181 | 135 | .filter(|key| t(Lang::En, **key) != t(Lang::Tr, **key)) |
| 182 | 136 | .count(); |
| 183 | 137 | assert!(differing >= 3, "only {differing} keys differ"); |
| 184 | - assert_eq!(t(Lang::Tr, K::NewDiscussion), "Yeni tartışma"); | |
| 185 | - assert_eq!(t(Lang::En, K::NewDiscussion), "New discussion"); | |
| 138 | + assert_eq!(t(Lang::Tr, K::NewSnippet), "Yeni parçacık"); | |
| 139 | + assert_eq!(t(Lang::En, K::NewSnippet), "New snippet"); | |
| 186 | 140 | } |
| 187 | 141 | |
| 188 | 142 | #[test] |
crates/forge-web-base/src/i18n/misc.rsmodified+0 -3
| @@ -36,7 +36,6 @@ strings! { | ||
| 36 | 36 | KindClosedIssue => "Closed issue", "Kapalı sorun"; |
| 37 | 37 | KindOpenPull => "Open pull request", "Açık çekme isteği"; |
| 38 | 38 | KindClosedPull => "Closed pull request", "Kapalı çekme isteği"; |
| 39 | - KindDiscussion => "Discussion", "Tartışma"; | |
| 40 | 39 | KindAdminAlert => "Admin alert", "Yönetici uyarısı"; |
| 41 | 40 | ReasonMentioned => "mentioned", "bahsedildi"; |
| 42 | 41 | ReasonAssigned => "assigned", "atandı"; |
| @@ -46,7 +45,6 @@ strings! { | ||
| 46 | 45 | ReasonStateChange => "state change", "durum değişikliği"; |
| 47 | 46 | ReasonSubscribed => "subscribed", "abone"; |
| 48 | 47 | ReasonWatching => "watching", "izleniyor"; |
| 49 | - ReasonReplied => "replied", "yanıtladı"; | |
| 50 | 48 | ReasonAdmin => "admin", "yönetici"; |
| 51 | 49 | VerbOpened => "opened", "açıldı"; |
| 52 | 50 | VerbCommented => "commented", "yorumlandı"; |
| @@ -59,7 +57,6 @@ strings! { | ||
| 59 | 57 | VerbMentionedYou => "mentioned you", "sizden bahsedildi"; |
| 60 | 58 | VerbPushedTo => "pushed to", "gönderim yapıldı"; |
| 61 | 59 | VerbUpdated => "updated", "güncellendi"; |
| 62 | - VerbDiscussionReply => "commented on your discussion", "tartışmanıza yorum yapıldı"; | |
| 63 | 60 | MarkAllAsRead => "Mark all as read", "Tümünü okundu olarak işaretle"; |
| 64 | 61 | MarkAllRead => "Mark all read", "Tümünü okundu işaretle"; |
| 65 | 62 | MarkRead => "Mark read", "Okundu işaretle"; |
crates/forge-web-pages/src/pages/code_live.rsmodified+1 -2
| @@ -71,7 +71,6 @@ async fn header_fingerprint( | ||
| 71 | 71 | let forks = fork_count(state, repo_id).await?; |
| 72 | 72 | let (open_issues, _) = state.store.issue_counts(repo_id).await?; |
| 73 | 73 | let (open_pulls, _) = state.store.pull_counts(repo_id).await?; |
| 74 | - let discussions = state.store.discussions_enabled(repo_id).await?; | |
| 75 | 74 | let wiki = state.store.wiki_enabled(repo_id).await?; |
| 76 | 75 | let watch = match viewer_id { |
| 77 | 76 | Some(viewer) => format!("{:?}", state.store.watch_level(viewer, repo_id).await?), |
| @@ -89,7 +88,7 @@ async fn header_fingerprint( | ||
| 89 | 88 | Ok(header_text( |
| 90 | 89 | &repo, |
| 91 | 90 | [stars, watchers, forks, open_issues, open_pulls], |
| 92 | - &format!("{discussions} {wiki} {watch}\n{mirror}"), | |
| 91 | + &format!("{wiki} {watch}\n{mirror}"), | |
| 93 | 92 | )) |
| 94 | 93 | } |
| 95 | 94 |
crates/forge-web-pages/src/pages/discussion_settings.rsdeleted+0 -88
| @@ -1,88 +0,0 @@ | ||
| 1 | -use forge_core::AuditAction; | |
| 2 | -use serde::Deserialize; | |
| 3 | -use topcoat::Result; | |
| 4 | -use topcoat::context::{Cx, context}; | |
| 5 | -use topcoat::router::content::Form; | |
| 6 | -use topcoat::router::error::{SeeOther, forbidden, see_other}; | |
| 7 | -use topcoat::router::{path_param, route}; | |
| 8 | -use topcoat::view::{View, component, view}; | |
| 9 | - | |
| 10 | -use crate::audit::{self, Actor, Target}; | |
| 11 | -use crate::auth::require_csrf; | |
| 12 | -use crate::i18n::Lang; | |
| 13 | -use crate::live::Topic; | |
| 14 | -use crate::pages::repo_ctx::load_repo; | |
| 15 | -use crate::state::AppState; | |
| 16 | -use crate::views::repo_href; | |
| 17 | - | |
| 18 | -path_param!(owner); | |
| 19 | -path_param!(repo); | |
| 20 | - | |
| 21 | -#[component] | |
| 22 | -pub async fn discussions_switch( | |
| 23 | - cx: &Cx, | |
| 24 | - lang: Lang, | |
| 25 | - action: String, | |
| 26 | - csrf: String, | |
| 27 | - enabled: bool, | |
| 28 | -) -> Result<impl View> { | |
| 29 | - let switch_label = crate::i18n::s(lang, "Discussions", "Tartışmalar"); | |
| 30 | - Ok(view! { | |
| 31 | - <form method="post" action=(action.as_str()) id="discussions"> | |
| 32 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 33 | - <label class="switch"> | |
| 34 | - <input type="checkbox" name="enabled" value="1" checked=(enabled) data-autosubmit="true"> | |
| 35 | - <span>(switch_label)</span> | |
| 36 | - </label> | |
| 37 | - </form> | |
| 38 | - }) | |
| 39 | -} | |
| 40 | - | |
| 41 | -#[derive(Deserialize, Default)] | |
| 42 | -struct ToggleForm { | |
| 43 | - #[serde(default)] | |
| 44 | - csrf: String, | |
| 45 | - #[serde(default)] | |
| 46 | - enabled: String, | |
| 47 | -} | |
| 48 | - | |
| 49 | -#[route(POST "/{owner}/{repo}/settings/discussions")] | |
| 50 | -async fn settings_discussions_save(cx: &Cx, Form(form): Form<ToggleForm>) -> Result<SeeOther> { | |
| 51 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 52 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 53 | - if !ctx.can_admin() { | |
| 54 | - return Err(forbidden().into()); | |
| 55 | - } | |
| 56 | - let enabled = form.enabled == "1"; | |
| 57 | - let state = context::<AppState>(cx); | |
| 58 | - state | |
| 59 | - .store | |
| 60 | - .set_discussions_enabled(&ctx.repo.id, enabled) | |
| 61 | - .await?; | |
| 62 | - state.live.bump(&Topic::Repo(ctx.repo.id.clone())); | |
| 63 | - let name = ctx.title(); | |
| 64 | - let action = if enabled { | |
| 65 | - AuditAction::DiscussionsEnabled | |
| 66 | - } else { | |
| 67 | - AuditAction::DiscussionsDisabled | |
| 68 | - }; | |
| 69 | - audit::record( | |
| 70 | - &state.store, | |
| 71 | - Some(cx), | |
| 72 | - Actor::User(&user), | |
| 73 | - action, | |
| 74 | - Target { | |
| 75 | - kind: "repo", | |
| 76 | - id: &ctx.repo.id, | |
| 77 | - name: &name, | |
| 78 | - }, | |
| 79 | - serde_json::Value::Null, | |
| 80 | - ) | |
| 81 | - .await; | |
| 82 | - Ok(see_other(repo_href( | |
| 83 | - &ctx.repo.owner_name, | |
| 84 | - &ctx.repo.name, | |
| 85 | - "settings", | |
| 86 | - "", | |
| 87 | - ))) | |
| 88 | -} |
crates/forge-web-pages/src/pages/mod.rsmodified+0 -1
| @@ -10,7 +10,6 @@ pub mod ci_fail; | ||
| 10 | 10 | pub mod ci_job; |
| 11 | 11 | pub mod ci_runs; |
| 12 | 12 | pub mod code_live; |
| 13 | -pub mod discussion_settings; | |
| 14 | 13 | pub mod edit_history; |
| 15 | 14 | pub mod finder; |
| 16 | 15 | pub mod issue_meta; |
crates/forge-web-pages/src/pages/notifications.rsmodified+1 -109
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | use std::collections::HashMap; |
| 2 | 2 | |
| 3 | 3 | use forge_core::authz::{Action, authorize}; |
| 4 | -use forge_core::discussions::{DiscussionNotification, DiscussionReason}; | |
| 5 | 4 | use forge_core::store::admin_alerts::AdminNotice; |
| 6 | 5 | use forge_core::store::transfers::PendingTransfer; |
| 7 | 6 | use forge_core::{IssueState, Notification, Reason, Role, SubState, User, WatchLevel}; |
| @@ -38,7 +37,6 @@ path_param!(owner); | ||
| 38 | 37 | path_param!(repo); |
| 39 | 38 | path_param!(number); |
| 40 | 39 | path_param!(note); |
| 41 | -path_param!(discussion_id); | |
| 42 | 40 | path_param!(admin_note); |
| 43 | 41 | |
| 44 | 42 | const ADMIN_GROUP: &str = "admin"; |
| @@ -94,7 +92,6 @@ pub struct RepoGroup { | ||
| 94 | 92 | |
| 95 | 93 | enum Entry { |
| 96 | 94 | Issue(Notification), |
| 97 | - Discussion(DiscussionNotification), | |
| 98 | 95 | Admin(AdminNotice), |
| 99 | 96 | } |
| 100 | 97 | |
| @@ -102,7 +99,6 @@ impl Entry { | ||
| 102 | 99 | fn repo_id(&self) -> &str { |
| 103 | 100 | match self { |
| 104 | 101 | Entry::Issue(note) => ¬e.repo_id, |
| 105 | - Entry::Discussion(note) => ¬e.repo_id, | |
| 106 | 102 | Entry::Admin(_) => ADMIN_GROUP, |
| 107 | 103 | } |
| 108 | 104 | } |
| @@ -110,7 +106,6 @@ impl Entry { | ||
| 110 | 106 | fn repo_owner(&self) -> &str { |
| 111 | 107 | match self { |
| 112 | 108 | Entry::Issue(note) => ¬e.repo_owner, |
| 113 | - Entry::Discussion(note) => ¬e.repo_owner, | |
| 114 | 109 | Entry::Admin(_) => "", |
| 115 | 110 | } |
| 116 | 111 | } |
| @@ -118,7 +113,6 @@ impl Entry { | ||
| 118 | 113 | fn repo_name(&self) -> &str { |
| 119 | 114 | match self { |
| 120 | 115 | Entry::Issue(note) => ¬e.repo_name, |
| 121 | - Entry::Discussion(note) => ¬e.repo_name, | |
| 122 | 116 | Entry::Admin(_) => "", |
| 123 | 117 | } |
| 124 | 118 | } |
| @@ -126,7 +120,6 @@ impl Entry { | ||
| 126 | 120 | fn updated_at(&self) -> &str { |
| 127 | 121 | match self { |
| 128 | 122 | Entry::Issue(note) => ¬e.updated_at, |
| 129 | - Entry::Discussion(note) => ¬e.updated_at, | |
| 130 | 123 | Entry::Admin(note) => ¬e.updated_at, |
| 131 | 124 | } |
| 132 | 125 | } |
| @@ -180,41 +173,6 @@ fn issue_row(lang: Lang, note: &Notification, tz: &str, now: i64) -> RowView { | ||
| 180 | 173 | } |
| 181 | 174 | } |
| 182 | 175 | |
| 183 | -fn discussion_row(lang: Lang, note: &DiscussionNotification, tz: &str, now: i64) -> RowView { | |
| 184 | - let (reason, activity) = match note.reason { | |
| 185 | - DiscussionReason::Mention => (g::t(lang, K::ReasonMentioned), K::VerbMentionedYou), | |
| 186 | - DiscussionReason::Reply => (g::t(lang, K::ReasonReplied), K::VerbDiscussionReply), | |
| 187 | - }; | |
| 188 | - let actor = note | |
| 189 | - .last_actor_name | |
| 190 | - .as_deref() | |
| 191 | - .map(|name| display_name(lang, name)); | |
| 192 | - let (iso, absolute, relative) = times(lang, ¬e.updated_at, tz, now); | |
| 193 | - RowView { | |
| 194 | - item_class: item_class(note.unread), | |
| 195 | - icon_class: "notif-icon discussion", | |
| 196 | - kind_label: g::t(lang, K::KindDiscussion), | |
| 197 | - open_href: format!( | |
| 198 | - "/notifications/discussions/{}/open", | |
| 199 | - percent_encode(¬e.discussion_id) | |
| 200 | - ), | |
| 201 | - read_action: format!( | |
| 202 | - "/notifications/discussions/{}/read", | |
| 203 | - percent_encode(¬e.discussion_id) | |
| 204 | - ), | |
| 205 | - title_line: format!( | |
| 206 | - "{}/{} #{} {}", | |
| 207 | - note.repo_owner, note.repo_name, note.number, note.title | |
| 208 | - ), | |
| 209 | - reason, | |
| 210 | - activity: g::activity_line(lang, activity, actor.as_deref()), | |
| 211 | - iso, | |
| 212 | - absolute, | |
| 213 | - relative, | |
| 214 | - unread: note.unread, | |
| 215 | - } | |
| 216 | -} | |
| 217 | - | |
| 218 | 176 | fn admin_row(lang: Lang, note: &AdminNotice, tz: &str, now: i64) -> RowView { |
| 219 | 177 | let (iso, absolute, relative) = times(lang, ¬e.updated_at, tz, now); |
| 220 | 178 | RowView { |
| @@ -289,10 +247,6 @@ async fn inbox(cx: &Cx) -> Result<impl View> { | ||
| 289 | 247 | .store |
| 290 | 248 | .list_notifications(&user.id, !all, before.as_deref(), PAGE_SIZE) |
| 291 | 249 | .await?; |
| 292 | - let discussion_rows = state | |
| 293 | - .store | |
| 294 | - .list_discussion_notifications(&user.id, !all, before.as_deref(), PAGE_SIZE) | |
| 295 | - .await?; | |
| 296 | 250 | let admin_rows = if user.is_admin { |
| 297 | 251 | state |
| 298 | 252 | .store |
| @@ -301,13 +255,10 @@ async fn inbox(cx: &Cx) -> Result<impl View> { | ||
| 301 | 255 | } else { |
| 302 | 256 | Vec::new() |
| 303 | 257 | }; |
| 304 | - let lists_full = rows.len() == PAGE_SIZE as usize | |
| 305 | - || discussion_rows.len() == PAGE_SIZE as usize | |
| 306 | - || admin_rows.len() == PAGE_SIZE as usize; | |
| 258 | + let lists_full = rows.len() == PAGE_SIZE as usize || admin_rows.len() == PAGE_SIZE as usize; | |
| 307 | 259 | let mut merged: Vec<Entry> = rows |
| 308 | 260 | .into_iter() |
| 309 | 261 | .map(Entry::Issue) |
| 310 | - .chain(discussion_rows.into_iter().map(Entry::Discussion)) | |
| 311 | 262 | .chain(admin_rows.into_iter().map(Entry::Admin)) |
| 312 | 263 | .collect(); |
| 313 | 264 | merged.sort_by(|a, b| b.updated_at().cmp(a.updated_at())); |
| @@ -359,7 +310,6 @@ async fn inbox(cx: &Cx) -> Result<impl View> { | ||
| 359 | 310 | }); |
| 360 | 311 | let row = match entry { |
| 361 | 312 | Entry::Issue(note) => issue_row(lang, ¬e, &tz, now), |
| 362 | - Entry::Discussion(note) => discussion_row(lang, ¬e, &tz, now), | |
| 363 | 313 | Entry::Admin(note) => admin_row(lang, ¬e, &tz, now), |
| 364 | 314 | }; |
| 365 | 315 | groups[slot].rows.push(row); |
| @@ -367,12 +317,6 @@ async fn inbox(cx: &Cx) -> Result<impl View> { | ||
| 367 | 317 | for entry in &hidden { |
| 368 | 318 | match entry { |
| 369 | 319 | Entry::Issue(note) => state.store.mark_read(&user.id, ¬e.id).await?, |
| 370 | - Entry::Discussion(note) => { | |
| 371 | - state | |
| 372 | - .store | |
| 373 | - .mark_discussion_notification_read(&user.id, ¬e.discussion_id) | |
| 374 | - .await?; | |
| 375 | - } | |
| 376 | 320 | Entry::Admin(note) => { |
| 377 | 321 | state |
| 378 | 322 | .store |
| @@ -422,16 +366,6 @@ async fn inbox_fingerprint(state: &AppState, user: &User, all: bool) -> Result<S | ||
| 422 | 366 | note.issue_state.as_str() |
| 423 | 367 | )); |
| 424 | 368 | } |
| 425 | - for note in state | |
| 426 | - .store | |
| 427 | - .list_discussion_notifications(&user.id, unread_only, before, PAGE_SIZE) | |
| 428 | - .await? | |
| 429 | - { | |
| 430 | - lines.push(format!( | |
| 431 | - "discussion {} {} {} {}", | |
| 432 | - note.discussion_id, note.unread, note.updated_at, note.title | |
| 433 | - )); | |
| 434 | - } | |
| 435 | 369 | if user.is_admin { |
| 436 | 370 | for note in state |
| 437 | 371 | .store |
| @@ -488,44 +422,6 @@ async fn open_notification(cx: &Cx) -> Result<SeeOther> { | ||
| 488 | 422 | Ok(see_other(href)) |
| 489 | 423 | } |
| 490 | 424 | |
| 491 | -#[route(GET "/notifications/discussions/{discussion_id}/open")] | |
| 492 | -async fn open_discussion_notification(cx: &Cx) -> Result<SeeOther> { | |
| 493 | - let (user, _) = require_user(cx).await?; | |
| 494 | - let state = context::<AppState>(cx); | |
| 495 | - let id = discussion_id(cx); | |
| 496 | - let Some(note) = state.store.discussion_notification(&user.id, id).await? else { | |
| 497 | - return Err(not_found().into()); | |
| 498 | - }; | |
| 499 | - state | |
| 500 | - .store | |
| 501 | - .mark_discussion_notification_read(&user.id, id) | |
| 502 | - .await?; | |
| 503 | - publish_unread(state, &user.id).await; | |
| 504 | - if !repo_allows(state, &user, ¬e.repo_id, Action::Read).await? { | |
| 505 | - return Err(not_found().into()); | |
| 506 | - } | |
| 507 | - let href = repo_href( | |
| 508 | - ¬e.repo_owner, | |
| 509 | - ¬e.repo_name, | |
| 510 | - "discussions", | |
| 511 | - ¬e.number.to_string(), | |
| 512 | - ); | |
| 513 | - Ok(see_other(href)) | |
| 514 | -} | |
| 515 | - | |
| 516 | -#[route(POST "/notifications/discussions/{discussion_id}/read")] | |
| 517 | -async fn read_discussion_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { | |
| 518 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 519 | - let state = context::<AppState>(cx); | |
| 520 | - let id = discussion_id(cx); | |
| 521 | - state | |
| 522 | - .store | |
| 523 | - .mark_discussion_notification_read(&user.id, id) | |
| 524 | - .await?; | |
| 525 | - publish_unread(state, &user.id).await; | |
| 526 | - Ok(see_other(back(cx))) | |
| 527 | -} | |
| 528 | - | |
| 529 | 425 | #[route(GET "/notifications/admin/{admin_note}/open")] |
| 530 | 426 | async fn open_admin_notification(cx: &Cx) -> Result<SeeOther> { |
| 531 | 427 | let (user, _) = require_user(cx).await?; |
| @@ -574,10 +470,6 @@ async fn mark_all_read(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> | ||
| 574 | 470 | state.store.mark_all_admin_notices_read(&user.id).await?; |
| 575 | 471 | } |
| 576 | 472 | state.store.mark_all_read(&user.id, repo_id).await?; |
| 577 | - state | |
| 578 | - .store | |
| 579 | - .mark_all_discussion_notifications_read(&user.id, repo_id) | |
| 580 | - .await?; | |
| 581 | 473 | publish_unread(state, &user.id).await; |
| 582 | 474 | Ok(see_other(back(cx))) |
| 583 | 475 | } |
crates/forge-web-pages/src/pages/repo.rsmodified+1 -2
| @@ -64,7 +64,6 @@ pub async fn repo_head( | ||
| 64 | 64 | forks, |
| 65 | 65 | live, |
| 66 | 66 | mirror, |
| 67 | - discussions, | |
| 68 | 67 | wiki, |
| 69 | 68 | lang, |
| 70 | 69 | clone, |
| @@ -162,7 +161,7 @@ pub async fn repo_head( | ||
| 162 | 161 | (child) |
| 163 | 162 | </div> |
| 164 | 163 | head_sub(parts: parts, pips: pips, keep: true) |
| 165 | - repo_tabs(owner: owner.clone(), repo: name.clone(), default_branch: default_branch.clone(), active: active.clone(), can_admin: can_admin, lang: lang, open_issues: Some(open_issues), open_pulls: Some(open_pulls), discussions: discussions, wiki: wiki) | |
| 164 | + repo_tabs(owner: owner.clone(), repo: name.clone(), default_branch: default_branch.clone(), active: active.clone(), can_admin: can_admin, lang: lang, open_issues: Some(open_issues), open_pulls: Some(open_pulls), wiki: wiki) | |
| 166 | 165 | </section> |
| 167 | 166 | if archived { |
| 168 | 167 | <p class="state" role="status">(g::t(lang, K::ArchivedNotice))</p> |
crates/forge-web-pages/src/pages/repo_ctx.rsmodified+0 -3
| @@ -53,7 +53,6 @@ pub struct RepoHead { | ||
| 53 | 53 | pub forks: u64, |
| 54 | 54 | pub live: String, |
| 55 | 55 | pub mirror: Option<MirrorSource>, |
| 56 | - pub discussions: bool, | |
| 57 | 56 | pub wiki: bool, |
| 58 | 57 | pub clone: CloneLinks, |
| 59 | 58 | } |
| @@ -165,7 +164,6 @@ impl RepoCtx { | ||
| 165 | 164 | None => None, |
| 166 | 165 | }; |
| 167 | 166 | let forks = fork_count(state, &self.repo.id).await?; |
| 168 | - let discussions = state.store.discussions_enabled(&self.repo.id).await?; | |
| 169 | 167 | let wiki = state.store.wiki_enabled(&self.repo.id).await?; |
| 170 | 168 | let mirror = state |
| 171 | 169 | .store |
| @@ -215,7 +213,6 @@ impl RepoCtx { | ||
| 215 | 213 | ), |
| 216 | 214 | )), |
| 217 | 215 | }, |
| 218 | - discussions, | |
| 219 | 216 | wiki, |
| 220 | 217 | }) |
| 221 | 218 | } |
crates/forge-web-pages/src/pages/repo_settings.rsmodified+1 -5
| @@ -26,7 +26,6 @@ use crate::auth::{require_csrf, require_user}; | ||
| 26 | 26 | use crate::i18n::merge_queue as mq; |
| 27 | 27 | use crate::i18n::repo_admin::{self as g, K}; |
| 28 | 28 | use crate::i18n::{self, Lang}; |
| 29 | -use crate::pages::discussion_settings::discussions_switch; | |
| 30 | 29 | use crate::pages::refs::load_refs; |
| 31 | 30 | use crate::pages::repo::repo_head; |
| 32 | 31 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; |
| @@ -491,7 +490,6 @@ async fn general_section( | ||
| 491 | 490 | description: String, |
| 492 | 491 | default_branch: String, |
| 493 | 492 | branches: Vec<String>, |
| 494 | - discussions_on: bool, | |
| 495 | 493 | wiki_on: bool, |
| 496 | 494 | ) -> Result<impl View> { |
| 497 | 495 | let general_action = format!("/{title}/settings/general"); |
| @@ -528,7 +526,6 @@ async fn general_section( | ||
| 528 | 526 | |
| 529 | 527 | <section class="sec"> |
| 530 | 528 | <h2>(g::t(lang, K::Features))</h2> |
| 531 | - discussions_switch(lang: lang, action: format!("/{title}/settings/discussions"), csrf: csrf.clone(), enabled: discussions_on) | |
| 532 | 529 | wiki_switch(action: format!("/{title}/settings/wiki"), csrf: csrf.clone(), enabled: wiki_on) |
| 533 | 530 | </section> |
| 534 | 531 | }) |
| @@ -969,7 +966,6 @@ async fn settings_body( | ||
| 969 | 966 | } |
| 970 | 967 | } |
| 971 | 968 | let (description, visibility) = (head.description.clone(), head.visibility); |
| 972 | - let discussions_on = head.discussions; | |
| 973 | 969 | let notice = notice.map(|(key, is_error)| (g::t(lang, key), is_error)); |
| 974 | 970 | let section_name = match section { |
| 975 | 971 | "branches" => g::t(lang, K::BranchProtection), |
| @@ -985,7 +981,7 @@ async fn settings_body( | ||
| 985 | 981 | if section == "general" { |
| 986 | 982 | general_section(lang: lang, title: title.clone(), csrf: csrf.clone(), description: description, |
| 987 | 983 | default_branch: default_branch.clone(), branches: branches, |
| 988 | - discussions_on: discussions_on, wiki_on: wiki_on) | |
| 984 | + wiki_on: wiki_on) | |
| 989 | 985 | } |
| 990 | 986 | if section == "branches" { |
| 991 | 987 | <section class="sec"> |
crates/forge-web-repo/Cargo.tomlmodified+1 -1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | [package] |
| 2 | 2 | name = "forge-web-repo" |
| 3 | -description = "forge code, pull request, discussion and issue view pages" | |
| 3 | +description = "forge code, pull request and issue view pages" | |
| 4 | 4 | version.workspace = true |
| 5 | 5 | edition.workspace = true |
| 6 | 6 | license.workspace = true |
crates/forge-web-repo/src/pages/discussion_actions.rsdeleted+0 -371
| @@ -1,371 +0,0 @@ | ||
| 1 | -use forge_core::{AuditAction, Reaction, ReactionTarget}; | |
| 2 | -use serde::Deserialize; | |
| 3 | -use topcoat::Result; | |
| 4 | -use topcoat::context::{Cx, context}; | |
| 5 | -use topcoat::router::content::Form; | |
| 6 | -use topcoat::router::error::{SeeOther, bad_request, forbidden, not_found, see_other}; | |
| 7 | -use topcoat::router::{page, path_param, route}; | |
| 8 | -use topcoat::view::{View, view}; | |
| 9 | - | |
| 10 | -use crate::auth::require_csrf; | |
| 11 | -use crate::i18n; | |
| 12 | -use crate::i18n::community::{self as g, K}; | |
| 13 | -use crate::pages::discussions::{ | |
| 14 | - audit_discussion, discussion_by_number, discussions_href, ensure_enabled, is_author, | |
| 15 | - may_converse, notify_mentions, | |
| 16 | -}; | |
| 17 | -use crate::pages::issue_meta::{action_error_at, can_triage, refusal_message}; | |
| 18 | -use crate::pages::repo_ctx::{RepoCtx, load_repo}; | |
| 19 | -use crate::state::AppState; | |
| 20 | -use crate::views::shell; | |
| 21 | - | |
| 22 | -path_param!(owner); | |
| 23 | -path_param!(repo); | |
| 24 | -path_param!(number); | |
| 25 | -path_param!(comment_id); | |
| 26 | - | |
| 27 | -#[derive(Deserialize, Default)] | |
| 28 | -struct ActionForm { | |
| 29 | - #[serde(default)] | |
| 30 | - csrf: String, | |
| 31 | - #[serde(default)] | |
| 32 | - title: String, | |
| 33 | - #[serde(default)] | |
| 34 | - body: String, | |
| 35 | - #[serde(default)] | |
| 36 | - parent: String, | |
| 37 | - #[serde(default)] | |
| 38 | - locked: String, | |
| 39 | - #[serde(default)] | |
| 40 | - comment_id: String, | |
| 41 | - #[serde(default)] | |
| 42 | - answer: String, | |
| 43 | - #[serde(default)] | |
| 44 | - target_kind: String, | |
| 45 | - #[serde(default)] | |
| 46 | - target_id: String, | |
| 47 | - #[serde(default)] | |
| 48 | - reaction: String, | |
| 49 | -} | |
| 50 | - | |
| 51 | -fn base_of(ctx: &RepoCtx, number: i64) -> String { | |
| 52 | - discussions_href(&ctx.repo.owner_name, &ctx.repo.name, &number.to_string()) | |
| 53 | -} | |
| 54 | - | |
| 55 | -async fn own_comment( | |
| 56 | - state: &AppState, | |
| 57 | - ctx: &RepoCtx, | |
| 58 | - discussion_id: &str, | |
| 59 | - comment_id: &str, | |
| 60 | -) -> Result<forge_core::discussions::DiscussionComment> { | |
| 61 | - let comment = match state | |
| 62 | - .store | |
| 63 | - .discussion_comment(discussion_id, comment_id) | |
| 64 | - .await? | |
| 65 | - { | |
| 66 | - Some(comment) if !comment.deleted => comment, | |
| 67 | - _ => return Err(not_found().into()), | |
| 68 | - }; | |
| 69 | - if ctx.repo.archived || !is_author(ctx, &comment.author_id) { | |
| 70 | - return Err(forbidden().into()); | |
| 71 | - } | |
| 72 | - Ok(comment) | |
| 73 | -} | |
| 74 | - | |
| 75 | -#[page(POST "/{owner}/{repo}/discussions/{number}/comments")] | |
| 76 | -async fn discussion_comment(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> { | |
| 77 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 78 | - let state = context::<AppState>(cx); | |
| 79 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 80 | - let lang = i18n::lang(cx, Some(&user)); | |
| 81 | - ensure_enabled(state, &ctx).await?; | |
| 82 | - let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 83 | - if !may_converse(&ctx, discussion.locked) { | |
| 84 | - return Err(forbidden().into()); | |
| 85 | - } | |
| 86 | - let parent = Some(form.parent.as_str()).filter(|p| !p.is_empty()); | |
| 87 | - let base = base_of(&ctx, discussion.number); | |
| 88 | - let comment = match state | |
| 89 | - .store | |
| 90 | - .add_discussion_comment( | |
| 91 | - &discussion.id, | |
| 92 | - &user.id, | |
| 93 | - parent, | |
| 94 | - &form.body, | |
| 95 | - can_triage(&ctx), | |
| 96 | - ) | |
| 97 | - .await | |
| 98 | - { | |
| 99 | - Ok(comment) => comment, | |
| 100 | - Err(e) => { | |
| 101 | - let message = refusal_message(e)?; | |
| 102 | - return Ok(view! { | |
| 103 | - shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), | |
| 104 | - action_error_at(lang: lang, message: message, back: base)) | |
| 105 | - }); | |
| 106 | - } | |
| 107 | - }; | |
| 108 | - audit_discussion( | |
| 109 | - cx, | |
| 110 | - state, | |
| 111 | - &user, | |
| 112 | - &ctx, | |
| 113 | - AuditAction::DiscussionCommentCreated, | |
| 114 | - &discussion.id, | |
| 115 | - ) | |
| 116 | - .await; | |
| 117 | - notify_mentions(state, &ctx, &discussion.id, &user.id, &form.body, None).await; | |
| 118 | - Err(see_other(format!("{base}#comment-{}", comment.id)).into()) | |
| 119 | -} | |
| 120 | - | |
| 121 | -#[page(POST "/{owner}/{repo}/discussions/{number}/edit")] | |
| 122 | -async fn discussion_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> { | |
| 123 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 124 | - let state = context::<AppState>(cx); | |
| 125 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 126 | - let lang = i18n::lang(cx, Some(&user)); | |
| 127 | - ensure_enabled(state, &ctx).await?; | |
| 128 | - let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 129 | - if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) { | |
| 130 | - return Err(forbidden().into()); | |
| 131 | - } | |
| 132 | - let base = base_of(&ctx, discussion.number); | |
| 133 | - if let Err(e) = state | |
| 134 | - .store | |
| 135 | - .edit_discussion(&discussion.id, &form.title, &form.body) | |
| 136 | - .await | |
| 137 | - { | |
| 138 | - let message = refusal_message(e)?; | |
| 139 | - return Ok(view! { | |
| 140 | - shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), | |
| 141 | - action_error_at(lang: lang, message: message, back: base)) | |
| 142 | - }); | |
| 143 | - } | |
| 144 | - audit_discussion( | |
| 145 | - cx, | |
| 146 | - state, | |
| 147 | - &user, | |
| 148 | - &ctx, | |
| 149 | - AuditAction::DiscussionEdited, | |
| 150 | - &discussion.id, | |
| 151 | - ) | |
| 152 | - .await; | |
| 153 | - notify_mentions( | |
| 154 | - state, | |
| 155 | - &ctx, | |
| 156 | - &discussion.id, | |
| 157 | - &user.id, | |
| 158 | - &form.body, | |
| 159 | - Some(&discussion.body), | |
| 160 | - ) | |
| 161 | - .await; | |
| 162 | - Err(see_other(base).into()) | |
| 163 | -} | |
| 164 | - | |
| 165 | -#[route(POST "/{owner}/{repo}/discussions/{number}/delete")] | |
| 166 | -async fn discussion_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> { | |
| 167 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 168 | - let state = context::<AppState>(cx); | |
| 169 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 170 | - ensure_enabled(state, &ctx).await?; | |
| 171 | - let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 172 | - if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) { | |
| 173 | - return Err(forbidden().into()); | |
| 174 | - } | |
| 175 | - state.store.delete_discussion(&discussion.id).await?; | |
| 176 | - audit_discussion( | |
| 177 | - cx, | |
| 178 | - state, | |
| 179 | - &user, | |
| 180 | - &ctx, | |
| 181 | - AuditAction::DiscussionDeleted, | |
| 182 | - &discussion.id, | |
| 183 | - ) | |
| 184 | - .await; | |
| 185 | - Ok(see_other(discussions_href( | |
| 186 | - &ctx.repo.owner_name, | |
| 187 | - &ctx.repo.name, | |
| 188 | - "", | |
| 189 | - ))) | |
| 190 | -} | |
| 191 | - | |
| 192 | -#[route(POST "/{owner}/{repo}/discussions/{number}/lock")] | |
| 193 | -async fn discussion_lock(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> { | |
| 194 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 195 | - let state = context::<AppState>(cx); | |
| 196 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 197 | - ensure_enabled(state, &ctx).await?; | |
| 198 | - let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 199 | - if !can_triage(&ctx) { | |
| 200 | - return Err(forbidden().into()); | |
| 201 | - } | |
| 202 | - let locked = form.locked == "1"; | |
| 203 | - let changed = state | |
| 204 | - .store | |
| 205 | - .set_discussion_locked(&discussion.id, locked) | |
| 206 | - .await?; | |
| 207 | - if changed { | |
| 208 | - let action = if locked { | |
| 209 | - AuditAction::DiscussionLocked | |
| 210 | - } else { | |
| 211 | - AuditAction::DiscussionUnlocked | |
| 212 | - }; | |
| 213 | - audit_discussion(cx, state, &user, &ctx, action, &discussion.id).await; | |
| 214 | - } | |
| 215 | - Ok(see_other(base_of(&ctx, discussion.number))) | |
| 216 | -} | |
| 217 | - | |
| 218 | -#[page(POST "/{owner}/{repo}/discussions/{number}/answer")] | |
| 219 | -async fn discussion_answer(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> { | |
| 220 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 221 | - let state = context::<AppState>(cx); | |
| 222 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 223 | - let lang = i18n::lang(cx, Some(&user)); | |
| 224 | - ensure_enabled(state, &ctx).await?; | |
| 225 | - let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 226 | - if ctx.repo.archived || !(can_triage(&ctx) || is_author(&ctx, &discussion.author_id)) { | |
| 227 | - return Err(forbidden().into()); | |
| 228 | - } | |
| 229 | - let base = base_of(&ctx, discussion.number); | |
| 230 | - let answer = form.answer == "1"; | |
| 231 | - let chosen = answer | |
| 232 | - .then_some(form.comment_id.as_str()) | |
| 233 | - .filter(|c| !c.is_empty()); | |
| 234 | - if answer && chosen.is_none() { | |
| 235 | - return Err(bad_request("missing comment").into()); | |
| 236 | - } | |
| 237 | - if let Err(e) = state | |
| 238 | - .store | |
| 239 | - .set_discussion_answer(&discussion.id, chosen) | |
| 240 | - .await | |
| 241 | - { | |
| 242 | - let message = refusal_message(e)?; | |
| 243 | - return Ok(view! { | |
| 244 | - shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), | |
| 245 | - action_error_at(lang: lang, message: message, back: base)) | |
| 246 | - }); | |
| 247 | - } | |
| 248 | - audit_discussion( | |
| 249 | - cx, | |
| 250 | - state, | |
| 251 | - &user, | |
| 252 | - &ctx, | |
| 253 | - AuditAction::DiscussionAnswered, | |
| 254 | - &discussion.id, | |
| 255 | - ) | |
| 256 | - .await; | |
| 257 | - match chosen { | |
| 258 | - Some(id) => Err(see_other(format!("{base}#comment-{id}")).into()), | |
| 259 | - None => Err(see_other(base).into()), | |
| 260 | - } | |
| 261 | -} | |
| 262 | - | |
| 263 | -#[page(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/edit")] | |
| 264 | -async fn discussion_comment_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> { | |
| 265 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 266 | - let state = context::<AppState>(cx); | |
| 267 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 268 | - ensure_enabled(state, &ctx).await?; | |
| 269 | - let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 270 | - let lang = i18n::lang(cx, Some(&user)); | |
| 271 | - let comment = own_comment(state, &ctx, &discussion.id, comment_id(cx)).await?; | |
| 272 | - let base = base_of(&ctx, discussion.number); | |
| 273 | - if let Err(e) = state | |
| 274 | - .store | |
| 275 | - .edit_discussion_comment(&comment.id, &form.body) | |
| 276 | - .await | |
| 277 | - { | |
| 278 | - let message = refusal_message(e)?; | |
| 279 | - return Ok(view! { | |
| 280 | - shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), | |
| 281 | - action_error_at(lang: lang, message: message, back: base)) | |
| 282 | - }); | |
| 283 | - } | |
| 284 | - audit_discussion( | |
| 285 | - cx, | |
| 286 | - state, | |
| 287 | - &user, | |
| 288 | - &ctx, | |
| 289 | - AuditAction::DiscussionCommentEdited, | |
| 290 | - &discussion.id, | |
| 291 | - ) | |
| 292 | - .await; | |
| 293 | - notify_mentions( | |
| 294 | - state, | |
| 295 | - &ctx, | |
| 296 | - &discussion.id, | |
| 297 | - &user.id, | |
| 298 | - &form.body, | |
| 299 | - Some(&comment.body), | |
| 300 | - ) | |
| 301 | - .await; | |
| 302 | - Err(see_other(format!("{base}#comment-{}", comment.id)).into()) | |
| 303 | -} | |
| 304 | - | |
| 305 | -#[route(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/delete")] | |
| 306 | -async fn discussion_comment_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> { | |
| 307 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 308 | - let state = context::<AppState>(cx); | |
| 309 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 310 | - ensure_enabled(state, &ctx).await?; | |
| 311 | - let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 312 | - let comment = own_comment(state, &ctx, &discussion.id, comment_id(cx)).await?; | |
| 313 | - state.store.delete_discussion_comment(&comment.id).await?; | |
| 314 | - audit_discussion( | |
| 315 | - cx, | |
| 316 | - state, | |
| 317 | - &user, | |
| 318 | - &ctx, | |
| 319 | - AuditAction::DiscussionCommentDeleted, | |
| 320 | - &discussion.id, | |
| 321 | - ) | |
| 322 | - .await; | |
| 323 | - Ok(see_other(base_of(&ctx, discussion.number))) | |
| 324 | -} | |
| 325 | - | |
| 326 | -#[route(POST "/{owner}/{repo}/discussions/{number}/reactions")] | |
| 327 | -async fn discussion_reaction(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> { | |
| 328 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 329 | - let state = context::<AppState>(cx); | |
| 330 | - let (user, _) = require_csrf(cx, &form.csrf).await?; | |
| 331 | - ensure_enabled(state, &ctx).await?; | |
| 332 | - let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 333 | - if !may_converse(&ctx, discussion.locked) { | |
| 334 | - return Err(forbidden().into()); | |
| 335 | - } | |
| 336 | - let Ok(reaction) = form.reaction.parse::<Reaction>() else { | |
| 337 | - return Err(bad_request("unknown reaction").into()); | |
| 338 | - }; | |
| 339 | - let target_id = form.target_id.clone(); | |
| 340 | - let (kind, anchor) = match form.target_kind.as_str() { | |
| 341 | - "discussion" => { | |
| 342 | - if target_id != discussion.id { | |
| 343 | - return Err(not_found().into()); | |
| 344 | - } | |
| 345 | - (ReactionTarget::Discussion, "discussion-body".to_owned()) | |
| 346 | - } | |
| 347 | - "discussion_comment" => { | |
| 348 | - match state | |
| 349 | - .store | |
| 350 | - .discussion_comment(&discussion.id, &target_id) | |
| 351 | - .await? | |
| 352 | - { | |
| 353 | - Some(comment) if !comment.deleted => {} | |
| 354 | - _ => return Err(not_found().into()), | |
| 355 | - } | |
| 356 | - ( | |
| 357 | - ReactionTarget::DiscussionComment, | |
| 358 | - format!("comment-{target_id}"), | |
| 359 | - ) | |
| 360 | - } | |
| 361 | - _ => return Err(bad_request("unknown reaction target").into()), | |
| 362 | - }; | |
| 363 | - state | |
| 364 | - .store | |
| 365 | - .toggle_reaction(kind, &target_id, &user.id, reaction) | |
| 366 | - .await?; | |
| 367 | - Ok(see_other(format!( | |
| 368 | - "{}#{anchor}", | |
| 369 | - base_of(&ctx, discussion.number) | |
| 370 | - ))) | |
| 371 | -} |
crates/forge-web-repo/src/pages/discussion_live.rsdeleted+0 -38
| @@ -1,38 +0,0 @@ | ||
| 1 | -use topcoat::Result; | |
| 2 | -use topcoat::context::{Cx, context}; | |
| 3 | -use topcoat::router::response::Response; | |
| 4 | -use topcoat::router::{path_param, route}; | |
| 5 | - | |
| 6 | -use crate::live::{Topic, stream_wakes}; | |
| 7 | -use crate::pages::discussions::{discussion_by_number, ensure_enabled}; | |
| 8 | -use crate::pages::repo_ctx::load_repo; | |
| 9 | -use crate::state::AppState; | |
| 10 | - | |
| 11 | -path_param!(owner); | |
| 12 | -path_param!(repo); | |
| 13 | -path_param!(number); | |
| 14 | - | |
| 15 | -pub fn list_live_url(owner: &str, repo: &str) -> String { | |
| 16 | - format!("/{owner}/{repo}/discussions/live") | |
| 17 | -} | |
| 18 | - | |
| 19 | -pub fn item_live_url(owner: &str, repo: &str, number: i64) -> String { | |
| 20 | - format!("/{owner}/{repo}/discussions/{number}/live") | |
| 21 | -} | |
| 22 | - | |
| 23 | -#[route(GET "/{owner}/{repo}/discussions/live")] | |
| 24 | -async fn discussions_live(cx: &Cx) -> Result<Response> { | |
| 25 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 26 | - let state = context::<AppState>(cx); | |
| 27 | - ensure_enabled(state, &ctx).await?; | |
| 28 | - stream_wakes(cx, &state.live, &[Topic::Discussions(ctx.repo.id.clone())]) | |
| 29 | -} | |
| 30 | - | |
| 31 | -#[route(GET "/{owner}/{repo}/discussions/{number}/live")] | |
| 32 | -async fn discussion_live(cx: &Cx) -> Result<Response> { | |
| 33 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 34 | - let state = context::<AppState>(cx); | |
| 35 | - ensure_enabled(state, &ctx).await?; | |
| 36 | - let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 37 | - stream_wakes(cx, &state.live, &[Topic::Discussion(discussion.id.clone())]) | |
| 38 | -} |
crates/forge-web-repo/src/pages/discussion_live_tests.rsdeleted+0 -223
| @@ -1,223 +0,0 @@ | ||
| 1 | -use std::sync::Arc; | |
| 2 | - | |
| 3 | -use forge_core::discussions::DiscussionCategory; | |
| 4 | -use forge_core::{Store, Visibility}; | |
| 5 | -use topcoat::router::request::Request; | |
| 6 | -use topcoat::router::{Body, Router}; | |
| 7 | - | |
| 8 | -use crate::auth::SESSION_COOKIE; | |
| 9 | -use crate::live::{LiveHub, Topic}; | |
| 10 | -use crate::test_support::fixture::send; | |
| 11 | - | |
| 12 | -const CSRF: &str = "discussion-live-csrf"; | |
| 13 | - | |
| 14 | -struct Site { | |
| 15 | - router: Router, | |
| 16 | - store: Store, | |
| 17 | - live: Arc<LiveHub>, | |
| 18 | - _dir: tempfile::TempDir, | |
| 19 | -} | |
| 20 | - | |
| 21 | -async fn site() -> Site { | |
| 22 | - let dir = tempfile::tempdir().expect("tempdir"); | |
| 23 | - let state = crate::test_support::test_state(dir.path()).await; | |
| 24 | - let store = state.store.clone(); | |
| 25 | - let live = state.live.clone(); | |
| 26 | - let router = crate::test_support::app_router(state); | |
| 27 | - Site { | |
| 28 | - router, | |
| 29 | - store, | |
| 30 | - live, | |
| 31 | - _dir: dir, | |
| 32 | - } | |
| 33 | -} | |
| 34 | - | |
| 35 | -async fn sign_in(store: &Store, user_id: &str, token: &str) -> String { | |
| 36 | - crate::test_support::create_session(store, user_id, token, CSRF).await; | |
| 37 | - format!("__Host-{SESSION_COOKIE}={token}") | |
| 38 | -} | |
| 39 | - | |
| 40 | -async fn post(site: &Site, uri: &str, cookie: &str, fields: &[(&str, &str)]) -> u16 { | |
| 41 | - send(&site.router, "POST", uri, Some(cookie), Some(fields)) | |
| 42 | - .await | |
| 43 | - .status | |
| 44 | -} | |
| 45 | - | |
| 46 | -async fn stream_status(site: &Site, uri: &str, cookie: Option<&str>) -> u16 { | |
| 47 | - let mut builder = Request::builder().method("GET").uri(uri); | |
| 48 | - if let Some(cookie) = cookie { | |
| 49 | - builder = builder.header("cookie", cookie); | |
| 50 | - } | |
| 51 | - let res = site | |
| 52 | - .router | |
| 53 | - .handle(builder.body(Body::empty()).expect("request")) | |
| 54 | - .await; | |
| 55 | - res.status().as_u16() | |
| 56 | -} | |
| 57 | - | |
| 58 | -struct Seed { | |
| 59 | - site: Site, | |
| 60 | - owner_cookie: String, | |
| 61 | - bob_cookie: String, | |
| 62 | - repo_id: String, | |
| 63 | - discussion_id: String, | |
| 64 | -} | |
| 65 | - | |
| 66 | -async fn seeded(visibility: Visibility) -> Seed { | |
| 67 | - let site = site().await; | |
| 68 | - let store = site.store.clone(); | |
| 69 | - let tahinli = store | |
| 70 | - .create_user("tahinli", None, "unused", false) | |
| 71 | - .await | |
| 72 | - .expect("tahinli"); | |
| 73 | - let bob = store | |
| 74 | - .create_user("bob", None, "unused", false) | |
| 75 | - .await | |
| 76 | - .expect("bob"); | |
| 77 | - let repo = store | |
| 78 | - .create_repo(&tahinli.id, "forge", "", visibility, "main") | |
| 79 | - .await | |
| 80 | - .expect("repo"); | |
| 81 | - store | |
| 82 | - .set_discussions_enabled(&repo.id, true) | |
| 83 | - .await | |
| 84 | - .expect("enable"); | |
| 85 | - let discussion = store | |
| 86 | - .create_discussion( | |
| 87 | - &repo.id, | |
| 88 | - &tahinli.id, | |
| 89 | - DiscussionCategory::General, | |
| 90 | - "Hello", | |
| 91 | - "Body", | |
| 92 | - ) | |
| 93 | - .await | |
| 94 | - .expect("discussion"); | |
| 95 | - let owner_cookie = sign_in(&store, &tahinli.id, "owner-token").await; | |
| 96 | - let bob_cookie = sign_in(&store, &bob.id, "bob-token").await; | |
| 97 | - Seed { | |
| 98 | - site, | |
| 99 | - owner_cookie, | |
| 100 | - bob_cookie, | |
| 101 | - repo_id: repo.id, | |
| 102 | - discussion_id: discussion.id, | |
| 103 | - } | |
| 104 | -} | |
| 105 | - | |
| 106 | -#[tokio::test] | |
| 107 | -async fn writes_bump_the_topics_they_reach() { | |
| 108 | - let seed = seeded(Visibility::Public).await; | |
| 109 | - let site = &seed.site; | |
| 110 | - | |
| 111 | - let list = site | |
| 112 | - .live | |
| 113 | - .subscribe(&Topic::Discussions(seed.repo_id.clone())); | |
| 114 | - let item = site | |
| 115 | - .live | |
| 116 | - .subscribe(&Topic::Discussion(seed.discussion_id.clone())); | |
| 117 | - let other = site.live.subscribe(&Topic::Discussion("other".to_owned())); | |
| 118 | - let status = post( | |
| 119 | - site, | |
| 120 | - "/tahinli/forge/discussions/1/comments", | |
| 121 | - &seed.owner_cookie, | |
| 122 | - &[("csrf", CSRF), ("body", "A reply")], | |
| 123 | - ) | |
| 124 | - .await; | |
| 125 | - assert_ne!(status, 404, "comment: the comment was refused"); | |
| 126 | - let comments = site | |
| 127 | - .store | |
| 128 | - .list_discussion_comments(&seed.discussion_id) | |
| 129 | - .await | |
| 130 | - .expect("comments"); | |
| 131 | - assert_eq!(comments.len(), 1, "comment: the comment was stored"); | |
| 132 | - assert!( | |
| 133 | - list.has_changed().expect("open"), | |
| 134 | - "comment: the list was bumped" | |
| 135 | - ); | |
| 136 | - assert!( | |
| 137 | - item.has_changed().expect("open"), | |
| 138 | - "comment: the discussion was bumped" | |
| 139 | - ); | |
| 140 | - assert!( | |
| 141 | - !other.has_changed().expect("open"), | |
| 142 | - "comment: an unrelated discussion was not bumped" | |
| 143 | - ); | |
| 144 | - | |
| 145 | - let list = site | |
| 146 | - .live | |
| 147 | - .subscribe(&Topic::Discussions(seed.repo_id.clone())); | |
| 148 | - let category = DiscussionCategory::General.as_str(); | |
| 149 | - let status = post( | |
| 150 | - site, | |
| 151 | - "/tahinli/forge/discussions/new", | |
| 152 | - &seed.owner_cookie, | |
| 153 | - &[ | |
| 154 | - ("csrf", CSRF), | |
| 155 | - ("category", category), | |
| 156 | - ("title", "Another"), | |
| 157 | - ("body", "Text"), | |
| 158 | - ], | |
| 159 | - ) | |
| 160 | - .await; | |
| 161 | - assert_ne!(status, 404, "new discussion: the discussion was refused"); | |
| 162 | - assert!( | |
| 163 | - list.has_changed().expect("open"), | |
| 164 | - "new discussion: the list was bumped" | |
| 165 | - ); | |
| 166 | - | |
| 167 | - let item = site | |
| 168 | - .live | |
| 169 | - .subscribe(&Topic::Discussion(seed.discussion_id.clone())); | |
| 170 | - let status = post( | |
| 171 | - site, | |
| 172 | - "/tahinli/forge/discussions/1/comments", | |
| 173 | - &seed.bob_cookie, | |
| 174 | - &[("csrf", CSRF), ("body", "")], | |
| 175 | - ) | |
| 176 | - .await; | |
| 177 | - assert_ne!(status, 404, "refused write: the discussion page answered"); | |
| 178 | - assert!( | |
| 179 | - item.has_changed().expect("open"), | |
| 180 | - "refused write: the discussion was bumped" | |
| 181 | - ); | |
| 182 | -} | |
| 183 | - | |
| 184 | -#[tokio::test] | |
| 185 | -async fn streams_follow_the_page_read_check() { | |
| 186 | - let seed = seeded(Visibility::Private).await; | |
| 187 | - let site = &seed.site; | |
| 188 | - let list = "/tahinli/forge/discussions/live"; | |
| 189 | - let item = "/tahinli/forge/discussions/1/live"; | |
| 190 | - | |
| 191 | - assert_eq!(stream_status(site, list, None).await, 404, "anonymous list"); | |
| 192 | - assert_eq!(stream_status(site, item, None).await, 404, "anonymous item"); | |
| 193 | - assert_eq!( | |
| 194 | - stream_status(site, list, Some(&seed.bob_cookie)).await, | |
| 195 | - 404, | |
| 196 | - "bob, no access, list" | |
| 197 | - ); | |
| 198 | - assert_eq!( | |
| 199 | - stream_status(site, item, Some(&seed.bob_cookie)).await, | |
| 200 | - 404, | |
| 201 | - "bob, no access, item" | |
| 202 | - ); | |
| 203 | - assert_eq!( | |
| 204 | - stream_status(site, list, Some(&seed.owner_cookie)).await, | |
| 205 | - 200, | |
| 206 | - "owner, list" | |
| 207 | - ); | |
| 208 | - assert_eq!( | |
| 209 | - stream_status(site, item, Some(&seed.owner_cookie)).await, | |
| 210 | - 200, | |
| 211 | - "owner, item" | |
| 212 | - ); | |
| 213 | - assert_eq!( | |
| 214 | - stream_status( | |
| 215 | - site, | |
| 216 | - "/tahinli/forge/discussions/9/live", | |
| 217 | - Some(&seed.owner_cookie) | |
| 218 | - ) | |
| 219 | - .await, | |
| 220 | - 404, | |
| 221 | - "a discussion that is not there" | |
| 222 | - ); | |
| 223 | -} |
crates/forge-web-repo/src/pages/discussion_view.rsdeleted+0 -471
| @@ -1,471 +0,0 @@ | ||
| 1 | -use std::collections::HashMap; | |
| 2 | - | |
| 3 | -use forge_core::discussions::{Discussion, DiscussionCategory, DiscussionComment}; | |
| 4 | -use forge_core::{ReactionMap, ReactionTarget}; | |
| 5 | -use topcoat::Result; | |
| 6 | -use topcoat::context::{Cx, context}; | |
| 7 | -use topcoat::router::{page, path_param}; | |
| 8 | -use topcoat::view::{Unescaped, View, component, view}; | |
| 9 | - | |
| 10 | -use crate::i18n::community::{self as g, K}; | |
| 11 | -use crate::i18n::{self, Lang}; | |
| 12 | -use crate::pages::discussion_live::item_live_url; | |
| 13 | -use crate::pages::discussions::{ | |
| 14 | - discussion_by_number, discussions_href, ensure_enabled, is_author, may_converse, | |
| 15 | -}; | |
| 16 | -use crate::pages::issue_meta::can_triage; | |
| 17 | -use crate::pages::issue_parts::{ReactionBar, csrf_of, reaction_bar_for, reaction_row}; | |
| 18 | -use crate::pages::repo::repo_head; | |
| 19 | -use crate::pages::repo_ctx::{RepoCtx, load_repo}; | |
| 20 | -use crate::pages::tree::link_context; | |
| 21 | -use crate::render::markdown::{LinkContext, render_markdown}; | |
| 22 | -use crate::state::AppState; | |
| 23 | -use crate::views::When; | |
| 24 | -use crate::views::parts::{SubPart, confirm_act, post_act, reveal}; | |
| 25 | -use crate::views::{avatar_url, display_name, now_unix, shell, user_href, user_link}; | |
| 26 | - | |
| 27 | -path_param!(owner); | |
| 28 | -path_param!(repo); | |
| 29 | -path_param!(number); | |
| 30 | - | |
| 31 | -pub(crate) struct CommentView { | |
| 32 | - lang: Lang, | |
| 33 | - anchor: String, | |
| 34 | - author: String, | |
| 35 | - login: String, | |
| 36 | - avatar: String, | |
| 37 | - when: When, | |
| 38 | - html: String, | |
| 39 | - raw: String, | |
| 40 | - deleted: bool, | |
| 41 | - accepted: bool, | |
| 42 | - id: String, | |
| 43 | - edit_action: Option<String>, | |
| 44 | - delete_action: Option<String>, | |
| 45 | - reply_action: Option<String>, | |
| 46 | - answer_action: Option<String>, | |
| 47 | - answer_value: &'static str, | |
| 48 | - answer_label: &'static str, | |
| 49 | - csrf: String, | |
| 50 | - reactions: Option<ReactionBar>, | |
| 51 | -} | |
| 52 | - | |
| 53 | -pub(crate) struct Thread { | |
| 54 | - root: CommentView, | |
| 55 | - replies: Vec<CommentView>, | |
| 56 | -} | |
| 57 | - | |
| 58 | -struct Frame { | |
| 59 | - lang: Lang, | |
| 60 | - base: String, | |
| 61 | - csrf: String, | |
| 62 | - tz: String, | |
| 63 | - now: i64, | |
| 64 | - names: HashMap<String, (String, Option<String>)>, | |
| 65 | - reactions: ReactionMap, | |
| 66 | - reaction_action: String, | |
| 67 | - can_react: bool, | |
| 68 | - can_comment: bool, | |
| 69 | - can_mark: bool, | |
| 70 | - qa: bool, | |
| 71 | - answer_id: Option<String>, | |
| 72 | - viewer_id: Option<String>, | |
| 73 | -} | |
| 74 | - | |
| 75 | -fn comment_view( | |
| 76 | - frame: &Frame, | |
| 77 | - link: &LinkContext, | |
| 78 | - c: &DiscussionComment, | |
| 79 | - top_level: bool, | |
| 80 | -) -> CommentView { | |
| 81 | - let (username, hash) = frame | |
| 82 | - .names | |
| 83 | - .get(&c.author_id) | |
| 84 | - .cloned() | |
| 85 | - .unwrap_or_else(|| ("ghost".to_owned(), None)); | |
| 86 | - let mine = frame.viewer_id.as_deref() == Some(c.author_id.as_str()); | |
| 87 | - let live = !c.deleted; | |
| 88 | - let accepted = frame.answer_id.as_deref() == Some(c.id.as_str()); | |
| 89 | - let reactions = if live { | |
| 90 | - reaction_bar_for( | |
| 91 | - frame.lang, | |
| 92 | - frame.reactions.get(&c.id), | |
| 93 | - frame.can_react, | |
| 94 | - &frame.reaction_action, | |
| 95 | - &frame.csrf, | |
| 96 | - ReactionTarget::DiscussionComment, | |
| 97 | - &c.id, | |
| 98 | - ) | |
| 99 | - } else { | |
| 100 | - None | |
| 101 | - }; | |
| 102 | - CommentView { | |
| 103 | - lang: frame.lang, | |
| 104 | - anchor: format!("comment-{}", c.id), | |
| 105 | - author: display_name(frame.lang, &username), | |
| 106 | - login: username.clone(), | |
| 107 | - avatar: avatar_url(&username, hash.as_deref()), | |
| 108 | - when: When::new(frame.lang, &c.created_at, &frame.tz, frame.now), | |
| 109 | - html: if live { | |
| 110 | - render_markdown(&c.body, Some(link)) | |
| 111 | - } else { | |
| 112 | - String::new() | |
| 113 | - }, | |
| 114 | - raw: c.body.clone(), | |
| 115 | - deleted: c.deleted, | |
| 116 | - accepted, | |
| 117 | - id: c.id.clone(), | |
| 118 | - edit_action: (mine && live).then(|| format!("{}/comments/{}/edit", frame.base, c.id)), | |
| 119 | - delete_action: (mine && live).then(|| format!("{}/comments/{}/delete", frame.base, c.id)), | |
| 120 | - reply_action: (top_level && live && frame.can_comment) | |
| 121 | - .then(|| format!("{}/comments", frame.base)), | |
| 122 | - answer_action: (frame.qa && live && frame.can_mark) | |
| 123 | - .then(|| format!("{}/answer", frame.base)), | |
| 124 | - answer_value: if accepted { "0" } else { "1" }, | |
| 125 | - answer_label: if accepted { | |
| 126 | - g::t(frame.lang, K::UnmarkAnswer) | |
| 127 | - } else { | |
| 128 | - g::t(frame.lang, K::MarkAsAnswer) | |
| 129 | - }, | |
| 130 | - csrf: frame.csrf.clone(), | |
| 131 | - reactions, | |
| 132 | - } | |
| 133 | -} | |
| 134 | - | |
| 135 | -#[component] | |
| 136 | -async fn comment_article(cx: &Cx, item: CommentView) -> Result<impl View> { | |
| 137 | - let CommentView { | |
| 138 | - lang, | |
| 139 | - anchor, | |
| 140 | - author, | |
| 141 | - login, | |
| 142 | - avatar, | |
| 143 | - when, | |
| 144 | - html, | |
| 145 | - raw, | |
| 146 | - deleted, | |
| 147 | - accepted, | |
| 148 | - id, | |
| 149 | - edit_action, | |
| 150 | - delete_action, | |
| 151 | - reply_action, | |
| 152 | - answer_action, | |
| 153 | - answer_value, | |
| 154 | - answer_label, | |
| 155 | - csrf, | |
| 156 | - reactions, | |
| 157 | - } = item; | |
| 158 | - let profile = user_href(&login); | |
| 159 | - let class = if accepted { | |
| 160 | - "sec thread-entry discussion-accepted" | |
| 161 | - } else { | |
| 162 | - "sec thread-entry" | |
| 163 | - }; | |
| 164 | - let answer_fields = vec![ | |
| 165 | - ("comment_id".to_owned(), id.clone()), | |
| 166 | - ("answer".to_owned(), answer_value.to_owned()), | |
| 167 | - ]; | |
| 168 | - let reply_id = format!("reply-{id}"); | |
| 169 | - let reply_open = format!("reply-open-{id}"); | |
| 170 | - let edit_id = format!("edit-{id}"); | |
| 171 | - let edit_open = format!("edit-open-{id}"); | |
| 172 | - Ok(view! { | |
| 173 | - <article class=(class) id=(anchor.as_str())> | |
| 174 | - <header class="thread-head"> | |
| 175 | - if deleted { | |
| 176 | - (g::t(lang, K::CommentDeleted)) | |
| 177 | - } else { | |
| 178 | - <a href=(profile.as_str()) aria-label=(login.as_str())><img class="avatar avatar-sm" src=(avatar.as_str()) alt="" width="24" height="24"></a> | |
| 179 | - <strong>user_link(shown: author.as_str(), login: login.as_str())</strong> | |
| 180 | - <time data-rel="true" datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time> | |
| 181 | - } | |
| 182 | - if accepted { | |
| 183 | - " · " (g::t(lang, K::Answer)) | |
| 184 | - } | |
| 185 | - </header> | |
| 186 | - if !deleted { | |
| 187 | - <div class="markdown-body">(Unescaped::new_unchecked(html))</div> | |
| 188 | - if let Some(bar) = reactions { | |
| 189 | - reaction_row(lang: lang, bar: bar) | |
| 190 | - } | |
| 191 | - <div class="acts"> | |
| 192 | - if let Some(action) = answer_action { | |
| 193 | - post_act(label: answer_label, action: action.as_str(), csrf: csrf.as_str(), fields: answer_fields) | |
| 194 | - } | |
| 195 | - if let Some(action) = reply_action { | |
| 196 | - reveal(label: g::t(lang, K::Reply), id: Some(reply_open.as_str()), | |
| 197 | - <form method="post" action=(action.as_str()) class="fields"> | |
| 198 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 199 | - <input type="hidden" name="parent" value=(id.as_str())> | |
| 200 | - <div class="field"> | |
| 201 | - <label for=(reply_id.as_str())>(g::t(lang, K::Reply))</label> | |
| 202 | - <textarea id=(reply_id.as_str()) name="body" rows="4"></textarea> | |
| 203 | - </div> | |
| 204 | - <button type="submit" class="primary">(g::t(lang, K::Reply))</button> | |
| 205 | - </form> | |
| 206 | - ) | |
| 207 | - } | |
| 208 | - if let Some(action) = edit_action { | |
| 209 | - reveal(label: g::t(lang, K::Edit), id: Some(edit_open.as_str()), | |
| 210 | - <form method="post" action=(action.as_str()) class="fields"> | |
| 211 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 212 | - <div class="field"> | |
| 213 | - <label for=(edit_id.as_str())>(g::t(lang, K::EditComment))</label> | |
| 214 | - <textarea id=(edit_id.as_str()) name="body" rows="6">(raw.as_str())</textarea> | |
| 215 | - </div> | |
| 216 | - <button type="submit" class="primary">(g::t(lang, K::Save))</button> | |
| 217 | - </form> | |
| 218 | - ) | |
| 219 | - } | |
| 220 | - if let Some(action) = delete_action { | |
| 221 | - confirm_act(lang: lang, label: g::t(lang, K::Delete), action: action.as_str(), csrf: csrf.as_str()) | |
| 222 | - } | |
| 223 | - </div> | |
| 224 | - } | |
| 225 | - </article> | |
| 226 | - }) | |
| 227 | -} | |
| 228 | - | |
| 229 | -#[component] | |
| 230 | -async fn comment_thread( | |
| 231 | - cx: &Cx, | |
| 232 | - root: CommentView, | |
| 233 | - replies: Vec<CommentView>, | |
| 234 | -) -> Result<impl View> { | |
| 235 | - Ok(view! { | |
| 236 | - <div class="discussion-thread"> | |
| 237 | - comment_article(item: root) | |
| 238 | - if !replies.is_empty() { | |
| 239 | - <div class="discussion-replies"> | |
| 240 | - for reply in replies.into_iter() { | |
| 241 | - comment_article(item: reply) | |
| 242 | - } | |
| 243 | - </div> | |
| 244 | - } | |
| 245 | - </div> | |
| 246 | - }) | |
| 247 | -} | |
| 248 | - | |
| 249 | -#[page("/{owner}/{repo}/discussions/{number}")] | |
| 250 | -async fn discussion_show(cx: &Cx) -> Result<impl View> { | |
| 251 | - let number = number(cx); | |
| 252 | - let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 253 | - let state = context::<AppState>(cx); | |
| 254 | - ensure_enabled(state, &ctx).await?; | |
| 255 | - let discussion = discussion_by_number(state, &ctx, number).await?; | |
| 256 | - discussion_page(cx, state, ctx, discussion).await | |
| 257 | -} | |
| 258 | - | |
| 259 | -async fn discussion_page( | |
| 260 | - cx: &Cx, | |
| 261 | - state: &AppState, | |
| 262 | - ctx: RepoCtx, | |
| 263 | - discussion: Discussion, | |
| 264 | -) -> Result<impl View> { | |
| 265 | - let lang = i18n::lang(cx, ctx.viewer_user()); | |
| 266 | - let owner = ctx.repo.owner_name.clone(); | |
| 267 | - let name = ctx.repo.name.clone(); | |
| 268 | - let number = discussion.number; | |
| 269 | - let base = discussions_href(&owner, &name, &number.to_string()); | |
| 270 | - let viewer_id = ctx.viewer.as_ref().map(|(user, _)| user.id.clone()); | |
| 271 | - let tz = ctx.viewer_tz().to_owned(); | |
| 272 | - let now = now_unix(); | |
| 273 | - let csrf = csrf_of(&ctx); | |
| 274 | - let triage = can_triage(&ctx); | |
| 275 | - let archived = ctx.repo.archived; | |
| 276 | - let signed_in = ctx.viewer.is_some(); | |
| 277 | - let can_converse = may_converse(&ctx, discussion.locked); | |
| 278 | - let qa = discussion.category == DiscussionCategory::Qa; | |
| 279 | - | |
| 280 | - let comments = state.store.list_discussion_comments(&discussion.id).await?; | |
| 281 | - let mut author_ids: Vec<String> = comments.iter().map(|c| c.author_id.clone()).collect(); | |
| 282 | - author_ids.push(discussion.author_id.clone()); | |
| 283 | - let names = state.store.usernames_by_ids(&author_ids).await?; | |
| 284 | - let comment_ids: Vec<String> = comments.iter().map(|c| c.id.clone()).collect(); | |
| 285 | - let reactions = state | |
| 286 | - .store | |
| 287 | - .reactions_for( | |
| 288 | - ReactionTarget::DiscussionComment, | |
| 289 | - &comment_ids, | |
| 290 | - viewer_id.as_deref(), | |
| 291 | - ) | |
| 292 | - .await?; | |
| 293 | - let body_reactions = state | |
| 294 | - .store | |
| 295 | - .reactions_for( | |
| 296 | - ReactionTarget::Discussion, | |
| 297 | - std::slice::from_ref(&discussion.id), | |
| 298 | - viewer_id.as_deref(), | |
| 299 | - ) | |
| 300 | - .await?; | |
| 301 | - | |
| 302 | - let reaction_action = discussions_href(&owner, &name, &format!("{number}/reactions")); | |
| 303 | - let link = link_context(state, &ctx.repo, &ctx.repo.default_branch, ""); | |
| 304 | - let frame = Frame { | |
| 305 | - lang, | |
| 306 | - base: base.clone(), | |
| 307 | - csrf: csrf.clone(), | |
| 308 | - tz: tz.clone(), | |
| 309 | - now, | |
| 310 | - names: names.clone(), | |
| 311 | - reactions, | |
| 312 | - reaction_action: reaction_action.clone(), | |
| 313 | - can_react: can_converse, | |
| 314 | - can_comment: can_converse, | |
| 315 | - can_mark: !archived && (triage || is_author(&ctx, &discussion.author_id)), | |
| 316 | - qa, | |
| 317 | - answer_id: discussion.answer_comment_id.clone(), | |
| 318 | - viewer_id: viewer_id.clone(), | |
| 319 | - }; | |
| 320 | - | |
| 321 | - let mut replies: HashMap<String, Vec<&DiscussionComment>> = HashMap::new(); | |
| 322 | - for c in comments.iter().filter(|c| c.parent_id.is_some()) { | |
| 323 | - if let Some(parent) = &c.parent_id { | |
| 324 | - replies.entry(parent.clone()).or_default().push(c); | |
| 325 | - } | |
| 326 | - } | |
| 327 | - let threads: Vec<Thread> = comments | |
| 328 | - .iter() | |
| 329 | - .filter(|c| c.parent_id.is_none()) | |
| 330 | - .map(|c| Thread { | |
| 331 | - root: comment_view(&frame, &link, c, true), | |
| 332 | - replies: replies | |
| 333 | - .get(&c.id) | |
| 334 | - .map(|list| { | |
| 335 | - list.iter() | |
| 336 | - .map(|r| comment_view(&frame, &link, r, false)) | |
| 337 | - .collect() | |
| 338 | - }) | |
| 339 | - .unwrap_or_default(), | |
| 340 | - }) | |
| 341 | - .collect(); | |
| 342 | - | |
| 343 | - let (author_name, author_hash) = names | |
| 344 | - .get(&discussion.author_id) | |
| 345 | - .cloned() | |
| 346 | - .unwrap_or_else(|| ("ghost".to_owned(), None)); | |
| 347 | - let author = display_name(lang, &author_name); | |
| 348 | - let author_avatar = avatar_url(&author_name, author_hash.as_deref()); | |
| 349 | - let author_profile = user_href(&author_name); | |
| 350 | - let author_login = author_name.clone(); | |
| 351 | - let opened = When::new(lang, &discussion.created_at, &tz, now); | |
| 352 | - let body_source = if discussion.body.trim().is_empty() { | |
| 353 | - g::t(lang, K::NoDescription) | |
| 354 | - } else { | |
| 355 | - discussion.body.as_str() | |
| 356 | - }; | |
| 357 | - let body_html = render_markdown(body_source, Some(&link)); | |
| 358 | - let mine = is_author(&ctx, &discussion.author_id); | |
| 359 | - let edit_action = format!("{base}/edit"); | |
| 360 | - let delete_action = format!("{base}/delete"); | |
| 361 | - let lock_action = format!("{base}/lock"); | |
| 362 | - let comment_action = format!("{base}/comments"); | |
| 363 | - let body_bar = reaction_bar_for( | |
| 364 | - lang, | |
| 365 | - body_reactions.get(&discussion.id), | |
| 366 | - can_converse, | |
| 367 | - &reaction_action, | |
| 368 | - &csrf, | |
| 369 | - ReactionTarget::Discussion, | |
| 370 | - &discussion.id, | |
| 371 | - ); | |
| 372 | - let body_mine_actions = !archived && mine; | |
| 373 | - let locked = discussion.locked; | |
| 374 | - let lock_value = if locked { "0" } else { "1" }; | |
| 375 | - let lock_label = if locked { | |
| 376 | - g::t(lang, K::UnlockConversation) | |
| 377 | - } else { | |
| 378 | - g::t(lang, K::LockConversation) | |
| 379 | - }; | |
| 380 | - let category = g::category_label(lang, discussion.category); | |
| 381 | - let answered = qa && discussion.answer_comment_id.is_some(); | |
| 382 | - let number_label = format!("#{number}"); | |
| 383 | - let page_title = format!("{} {number_label} \u{b7} {owner}/{name}", discussion.title); | |
| 384 | - let login_href = "/login".to_owned(); | |
| 385 | - let lock_notice = g::t(lang, K::LockedNotice); | |
| 386 | - let live_href = item_live_url(&owner, &name, number); | |
| 387 | - let header = ctx.head(state, "discussions").await?; | |
| 388 | - | |
| 389 | - let comments_label = g::comments_count(lang, discussion.comment_count); | |
| 390 | - let mut sub = vec![SubPart::text(category)]; | |
| 391 | - if answered { | |
| 392 | - sub.push(SubPart::text(g::t(lang, K::Answered))); | |
| 393 | - } | |
| 394 | - if locked { | |
| 395 | - sub.push(SubPart::text(g::t(lang, K::Locked))); | |
| 396 | - } | |
| 397 | - sub.push(SubPart::link(author.clone(), author_profile.clone())); | |
| 398 | - sub.push(SubPart::text(opened.relative.clone())); | |
| 399 | - sub.push(SubPart::text(comments_label)); | |
| 400 | - Ok(view! { | |
| 401 | - shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), | |
| 402 | - repo_head(head: header, title: Some(discussion.title.clone()), sub: sub, | |
| 403 | - <span class="num">(number_label.as_str())</span> | |
| 404 | - ) | |
| 405 | - <div class="work" data-live=(live_href.as_str()) data-live-now=""> | |
| 406 | - <div class="sheet"> | |
| 407 | - <article class="sec thread-entry" id="discussion-body"> | |
| 408 | - <header class="thread-head"> | |
| 409 | - <a href=(author_profile.as_str()) aria-label=(author.as_str())><img class="avatar avatar-sm" src=(author_avatar.as_str()) alt="" width="24" height="24"></a> | |
| 410 | - <strong>user_link(shown: author.as_str(), login: author_login.as_str())</strong> | |
| 411 | - <time data-rel="true" datetime=(opened.iso.as_str()) title=(opened.absolute.as_str())>(opened.relative.as_str())</time> | |
| 412 | - </header> | |
| 413 | - <div class="markdown-body">(Unescaped::new_unchecked(body_html))</div> | |
| 414 | - if let Some(bar) = body_bar { | |
| 415 | - reaction_row(lang: lang, bar: bar) | |
| 416 | - } | |
| 417 | - if body_mine_actions { | |
| 418 | - <div class="acts"> | |
| 419 | - reveal(label: g::t(lang, K::Edit), id: Some("edit-open"), | |
| 420 | - <form method="post" action=(edit_action.as_str()) class="fields"> | |
| 421 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 422 | - <div class="field"> | |
| 423 | - <label for="edit-title">(g::t(lang, K::Title))</label> | |
| 424 | - <input id="edit-title" type="text" name="title" value=(discussion.title.as_str()) required=(true) autocomplete="off"> | |
| 425 | - </div> | |
| 426 | - <div class="field"> | |
| 427 | - <label for="edit-body">(g::t(lang, K::Description))</label> | |
| 428 | - <textarea id="edit-body" name="body" rows="8">(discussion.body.as_str())</textarea> | |
| 429 | - </div> | |
| 430 | - <button type="submit" class="primary">(g::t(lang, K::Save))</button> | |
| 431 | - </form> | |
| 432 | - ) | |
| 433 | - confirm_act(lang: lang, label: g::t(lang, K::DeleteDiscussion), action: delete_action.as_str(), csrf: csrf.as_str()) | |
| 434 | - </div> | |
| 435 | - } | |
| 436 | - </article> | |
| 437 | - for thread in threads.into_iter() { | |
| 438 | - comment_thread(root: thread.root, replies: thread.replies) | |
| 439 | - } | |
| 440 | - if can_converse { | |
| 441 | - <section class="sec"> | |
| 442 | - <form method="post" action=(comment_action.as_str()) class="fields"> | |
| 443 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | |
| 444 | - <div class="field"> | |
| 445 | - <label for="new-comment">(g::t(lang, K::AddComment))</label> | |
| 446 | - <textarea id="new-comment" name="body" rows="6"></textarea> | |
| 447 | - </div> | |
| 448 | - <button type="submit" class="primary">(g::t(lang, K::CommentButton))</button> | |
| 449 | - </form> | |
| 450 | - </section> | |
| 451 | - } else if locked && signed_in && !archived { | |
| 452 | - <p class="state">(lock_notice)</p> | |
| 453 | - } else if !signed_in { | |
| 454 | - <p class="state">(g::comment_login_lead(lang))<a href=(login_href.as_str())>(crate::i18n::t(lang, crate::i18n::Key::LogInLink))</a>(g::t(lang, K::ToCommentSuffix))</p> | |
| 455 | - } | |
| 456 | - if archived { | |
| 457 | - <p class="state">(g::t(lang, K::ArchivedDiscussions))</p> | |
| 458 | - } | |
| 459 | - if triage && !archived { | |
| 460 | - <section class="sec meta"> | |
| 461 | - <h2>(g::t(lang, K::Conversation))</h2> | |
| 462 | - <div class="acts"> | |
| 463 | - post_act(label: lock_label, action: lock_action.as_str(), csrf: csrf.as_str(), fields: vec![("locked".to_owned(), lock_value.to_owned())]) | |
| 464 | - </div> | |
| 465 | - </section> | |
| 466 | - } | |
| 467 | - </div> | |
| 468 | - </div> | |
| 469 | - ) | |
| 470 | - }) | |
| 471 | -} |
crates/forge-web-repo/src/pages/discussions.rsdeleted+0 -511
| @@ -1,511 +0,0 @@ | ||
| 1 | -use forge_core::discussions::{ | |
| 2 | - DISCUSSION_CATEGORIES, Discussion, DiscussionCategory, DiscussionFilter, | |
| 3 | -}; | |
| 4 | -use forge_core::{Action, AuditAction, Role, User, authorize}; | |
| 5 | -use topcoat::Result; | |
| 6 | -use topcoat::context::{Cx, context}; | |
| 7 | -use topcoat::router::content::RawForm; | |
| 8 | -use topcoat::router::error::{bad_request, forbidden, not_found, see_other}; | |
| 9 | -use topcoat::router::{StatusCode, page, path_param, query_params}; | |
| 10 | -use topcoat::view::{View, component, view}; | |
| 11 | - | |
| 12 | -use crate::audit::{self, Actor, Target}; | |
| 13 | -use crate::auth::{require_csrf, require_user}; | |
| 14 | -use crate::i18n::community::{self as g, K}; | |
| 15 | -use crate::i18n::{self, Lang}; | |
| 16 | -use crate::pages::discussion_live::list_live_url; | |
| 17 | -use crate::pages::issue_meta::{can_triage, form_field, form_pairs, refusal_message}; | |
| 18 | -use crate::pages::issues_list::list_href; | |
| 19 | -use crate::pages::repo::repo_head; | |
| 20 | -use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; | |
| 21 | -use crate::render::markdown::mentioned_usernames; | |
| 22 | -use crate::state::AppState; | |
| 23 | -use crate::views::When; | |
| 24 | -use crate::views::paging::page_count; | |
| 25 | -use crate::views::parts::{RailItem, SubPart, rail}; | |
| 26 | -use crate::views::{alert, csrf_field, now_unix, repo_href, shell, user_link}; | |
| 27 | - | |
| 28 | -path_param!(owner); | |
| 29 | -path_param!(repo); | |
| 30 | - | |
| 31 | -pub(crate) const PER_PAGE: u32 = 25; | |
| 32 | -const MAX_PAGE: u32 = 1000; | |
| 33 | - | |
| 34 | -pub(crate) fn discussions_href(owner: &str, repo: &str, rest: &str) -> String { | |
| 35 | - repo_href(owner, repo, "discussions", rest) | |
| 36 | -} | |
| 37 | - | |
| 38 | -pub(crate) async fn ensure_enabled(state: &AppState, ctx: &RepoCtx) -> Result<()> { | |
| 39 | - if state.store.discussions_enabled(&ctx.repo.id).await? { | |
| 40 | - Ok(()) | |
| 41 | - } else { | |
| 42 | - Err(not_found().into()) | |
| 43 | - } | |
| 44 | -} | |
| 45 | - | |
| 46 | -pub(crate) fn maintains(ctx: &RepoCtx) -> bool { | |
| 47 | - let actor = ctx.viewer_user(); | |
| 48 | - authorize(actor, &ctx.repo, ctx.role, ctx.org_role, Action::Admin).is_ok() | |
| 49 | - || (ctx.viewer.is_some() && matches!(ctx.role, Some(Role::Maintain))) | |
| 50 | -} | |
| 51 | - | |
| 52 | -pub(crate) fn may_converse(ctx: &RepoCtx, locked: bool) -> bool { | |
| 53 | - ctx.viewer.is_some() && !ctx.repo.archived && (!locked || can_triage(ctx)) | |
| 54 | -} | |
| 55 | - | |
| 56 | -pub(crate) fn is_author(ctx: &RepoCtx, author_id: &str) -> bool { | |
| 57 | - ctx.viewer | |
| 58 | - .as_ref() | |
| 59 | - .is_some_and(|(user, _)| user.id == author_id) | |
| 60 | -} | |
| 61 | - | |
| 62 | -pub(crate) async fn audit_discussion( | |
| 63 | - cx: &Cx, | |
| 64 | - state: &AppState, | |
| 65 | - user: &User, | |
| 66 | - ctx: &RepoCtx, | |
| 67 | - action: AuditAction, | |
| 68 | - target_id: &str, | |
| 69 | -) { | |
| 70 | - let name = ctx.title(); | |
| 71 | - audit::record( | |
| 72 | - &state.store, | |
| 73 | - Some(cx), | |
| 74 | - Actor::User(user), | |
| 75 | - action, | |
| 76 | - Target { | |
| 77 | - kind: "discussion", | |
| 78 | - id: target_id, | |
| 79 | - name: &name, | |
| 80 | - }, | |
| 81 | - serde_json::Value::Null, | |
| 82 | - ) | |
| 83 | - .await; | |
| 84 | -} | |
| 85 | - | |
| 86 | -pub(crate) async fn notify_mentions( | |
| 87 | - state: &AppState, | |
| 88 | - ctx: &RepoCtx, | |
| 89 | - discussion_id: &str, | |
| 90 | - actor_id: &str, | |
| 91 | - text: &str, | |
| 92 | - old: Option<&str>, | |
| 93 | -) { | |
| 94 | - let mut names = mentioned_usernames(text); | |
| 95 | - if let Some(old) = old { | |
| 96 | - let before = mentioned_usernames(old); | |
| 97 | - names.retain(|name| !before.contains(name)); | |
| 98 | - } | |
| 99 | - let mut ids: Vec<String> = Vec::new(); | |
| 100 | - for name in names { | |
| 101 | - let user = match state.store.user_by_username(&name).await { | |
| 102 | - Ok(Some(user)) => user, | |
| 103 | - Ok(None) => continue, | |
| 104 | - Err(e) => { | |
| 105 | - tracing::error!(error = %e, name, "discussions: mention lookup failed"); | |
| 106 | - continue; | |
| 107 | - } | |
| 108 | - }; | |
| 109 | - if user.id == actor_id { | |
| 110 | - continue; | |
| 111 | - } | |
| 112 | - let role = match state.store.collaborator_role(&ctx.repo.id, &user.id).await { | |
| 113 | - Ok(role) => role, | |
| 114 | - Err(e) => { | |
| 115 | - tracing::error!(error = %e, "discussions: role lookup failed"); | |
| 116 | - continue; | |
| 117 | - } | |
| 118 | - }; | |
| 119 | - let org_role = match state | |
| 120 | - .store | |
| 121 | - .org_repo_role(&ctx.repo.owner_id, &user.id, &ctx.repo.id) | |
| 122 | - .await | |
| 123 | - { | |
| 124 | - Ok(role) => role, | |
| 125 | - Err(e) => { | |
| 126 | - tracing::error!(error = %e, "discussions: org role lookup failed"); | |
| 127 | - continue; | |
| 128 | - } | |
| 129 | - }; | |
| 130 | - if authorize(Some(&user), &ctx.repo, role, org_role, Action::Read).is_ok() { | |
| 131 | - ids.push(user.id); | |
| 132 | - } | |
| 133 | - } | |
| 134 | - if let Err(e) = state | |
| 135 | - .store | |
| 136 | - .record_discussion_mentions(&ctx.repo.id, discussion_id, actor_id, &ids) | |
| 137 | - .await | |
| 138 | - { | |
| 139 | - tracing::error!(error = %e, discussion_id, "discussions: mention rows failed"); | |
| 140 | - } | |
| 141 | -} | |
| 142 | - | |
| 143 | -pub(crate) struct CategoryOption { | |
| 144 | - pub(crate) value: &'static str, | |
| 145 | - pub(crate) label: &'static str, | |
| 146 | - pub(crate) selected: bool, | |
| 147 | -} | |
| 148 | - | |
| 149 | -pub(crate) fn category_options( | |
| 150 | - lang: Lang, | |
| 151 | - selected: Option<DiscussionCategory>, | |
| 152 | - maintainer: bool, | |
| 153 | -) -> Vec<CategoryOption> { | |
| 154 | - DISCUSSION_CATEGORIES | |
| 155 | - .iter() | |
| 156 | - .filter(|c| maintainer || **c != DiscussionCategory::Announcements) | |
| 157 | - .map(|c| CategoryOption { | |
| 158 | - value: c.as_str(), | |
| 159 | - label: g::category_label(lang, *c), | |
| 160 | - selected: Some(*c) == selected, | |
| 161 | - }) | |
| 162 | - .collect() | |
| 163 | -} | |
| 164 | - | |
| 165 | -#[query_params(error = bad_request)] | |
| 166 | -pub(crate) struct ListQuery { | |
| 167 | - category: Option<String>, | |
| 168 | - page: Option<String>, | |
| 169 | -} | |
| 170 | - | |
| 171 | -struct RowView { | |
| 172 | - href: String, | |
| 173 | - title: String, | |
| 174 | - category: &'static str, | |
| 175 | - author: String, | |
| 176 | - relative: String, | |
| 177 | - absolute: String, | |
| 178 | - iso: String, | |
| 179 | - comments_text: String, | |
| 180 | -} | |
| 181 | - | |
| 182 | -fn row_view( | |
| 183 | - lang: Lang, | |
| 184 | - owner: &str, | |
| 185 | - repo: &str, | |
| 186 | - item: &forge_core::discussions::DiscussionListItem, | |
| 187 | - tz: &str, | |
| 188 | - now: i64, | |
| 189 | -) -> RowView { | |
| 190 | - let d = &item.discussion; | |
| 191 | - let when = When::new(lang, &d.created_at, tz, now); | |
| 192 | - let comments = d.comment_count.max(0); | |
| 193 | - RowView { | |
| 194 | - href: discussions_href(owner, repo, &d.number.to_string()), | |
| 195 | - title: d.title.clone(), | |
| 196 | - category: g::category_label(lang, d.category), | |
| 197 | - author: item.author.clone(), | |
| 198 | - relative: when.relative, | |
| 199 | - absolute: when.absolute, | |
| 200 | - iso: when.iso, | |
| 201 | - comments_text: g::comments_count(lang, comments), | |
| 202 | - } | |
| 203 | -} | |
| 204 | - | |
| 205 | -#[page("/{owner}/{repo}/discussions")] | |
| 206 | -async fn discussions_list_page(cx: &Cx) -> Result<impl View> { | |
| 207 | - let owner = owner(cx); | |
| 208 | - let name = repo(cx); | |
| 209 | - let query = query_params::<ListQuery>(cx)?; | |
| 210 | - let ctx = load_repo(cx, owner, name).await?; | |
| 211 | - let state = context::<AppState>(cx); | |
| 212 | - ensure_enabled(state, &ctx).await?; | |
| 213 | - let lang = i18n::lang(cx, ctx.viewer_user()); | |
| 214 | - | |
| 215 | - let category = query | |
| 216 | - .category | |
| 217 | - .as_deref() | |
| 218 | - .and_then(|name| name.parse::<DiscussionCategory>().ok()); | |
| 219 | - let page = query | |
| 220 | - .page | |
| 221 | - .as_deref() | |
| 222 | - .and_then(|p| p.trim().parse::<u32>().ok()) | |
| 223 | - .filter(|p| (1..=MAX_PAGE).contains(p)) | |
| 224 | - .unwrap_or(1); | |
| 225 | - let filter = DiscussionFilter { | |
| 226 | - category, | |
| 227 | - page, | |
| 228 | - per_page: PER_PAGE, | |
| 229 | - }; | |
| 230 | - let (items, total) = state.store.list_discussions(&ctx.repo.id, &filter).await?; | |
| 231 | - | |
| 232 | - let owner_name = ctx.repo.owner_name.clone(); | |
| 233 | - let repo_name = ctx.repo.name.clone(); | |
| 234 | - let now = now_unix(); | |
| 235 | - let tz = ctx.viewer_tz().to_owned(); | |
| 236 | - let rows: Vec<RowView> = items | |
| 237 | - .iter() | |
| 238 | - .map(|item| row_view(lang, &owner_name, &repo_name, item, &tz, now)) | |
| 239 | - .collect(); | |
| 240 | - | |
| 241 | - let base = discussions_href(&owner_name, &repo_name, ""); | |
| 242 | - let selected = category.map_or("", |c| c.as_str()); | |
| 243 | - let all_on = category.is_none(); | |
| 244 | - let all_href = list_href(&base, &[]); | |
| 245 | - let nav_label = g::t(lang, K::CategoriesNav); | |
| 246 | - let list_title = match category { | |
| 247 | - Some(c) => g::category_label(lang, c), | |
| 248 | - None => g::t(lang, K::AllCategories), | |
| 249 | - }; | |
| 250 | - let mut rail_items: Vec<RailItem> = vec![RailItem { | |
| 251 | - name: g::t(lang, K::AllCategories).to_owned(), | |
| 252 | - val: String::new(), | |
| 253 | - href: all_href, | |
| 254 | - current: all_on, | |
| 255 | - }]; | |
| 256 | - rail_items.extend(DISCUSSION_CATEGORIES.iter().map(|c| RailItem { | |
| 257 | - name: g::category_label(lang, *c).to_owned(), | |
| 258 | - val: String::new(), | |
| 259 | - href: list_href(&base, &[("category", c.as_str())]), | |
| 260 | - current: category == Some(*c), | |
| 261 | - })); | |
| 262 | - let sub = vec![SubPart::text(match lang { | |
| 263 | - Lang::En if total == 1 => "1 discussion".to_owned(), | |
| 264 | - Lang::En => format!("{total} discussions"), | |
| 265 | - Lang::Tr => format!("{total} tartışma"), | |
| 266 | - })]; | |
| 267 | - | |
| 268 | - let last_page = page_count(total, u64::from(PER_PAGE)); | |
| 269 | - let has_newer = page > 1; | |
| 270 | - let has_older = u64::from(page) < last_page; | |
| 271 | - let page_param = |p: u32| { | |
| 272 | - let text = if p > 1 { p.to_string() } else { String::new() }; | |
| 273 | - list_href(&base, &[("category", selected), ("page", text.as_str())]) | |
| 274 | - }; | |
| 275 | - let newer_href = page_param(page.saturating_sub(1)); | |
| 276 | - let older_href = page_param(page + 1); | |
| 277 | - let page_label = i18n::page_label(lang, page); | |
| 278 | - | |
| 279 | - let can_start = ctx.viewer.is_some() && !ctx.repo.archived; | |
| 280 | - let live_href = list_live_url(&owner_name, &repo_name); | |
| 281 | - let new_href = discussions_href(&owner_name, &repo_name, "new"); | |
| 282 | - let title = format!( | |
| 283 | - "{owner_name}/{repo_name} \u{b7} {}", | |
| 284 | - g::t(lang, K::Discussions) | |
| 285 | - ); | |
| 286 | - let empty_text = g::t(lang, K::NoDiscussionsYet); | |
| 287 | - let new_label = g::t(lang, K::NewDiscussion); | |
| 288 | - let (by_before, by_middle, by_after) = g::byline(lang); | |
| 289 | - let newer_label = crate::i18n::t(lang, crate::i18n::Key::Newer); | |
| 290 | - let older_label = crate::i18n::t(lang, crate::i18n::Key::Older); | |
| 291 | - | |
| 292 | - let header = ctx.head(state, "discussions").await?; | |
| 293 | - Ok(view! { | |
| 294 | - shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), | |
| 295 | - repo_head(head: header, sub: sub, | |
| 296 | - if can_start { | |
| 297 | - <a class="button primary" href=(new_href.as_str())>(new_label)</a> | |
| 298 | - } | |
| 299 | - ) | |
| 300 | - <div class="work" data-live=(live_href.as_str()) data-live-now=""> | |
| 301 | - rail(label: nav_label, items: rail_items) | |
| 302 | - <div class="sheet"> | |
| 303 | - <div class="sheet-tools"> | |
| 304 | - <strong>(list_title)</strong> | |
| 305 | - </div> | |
| 306 | - if rows.is_empty() { | |
| 307 | - <p class="state">(empty_text)</p> | |
| 308 | - if can_start { | |
| 309 | - <div class="acts"> | |
| 310 | - <a class="act" href=(new_href.as_str())>(new_label)</a> | |
| 311 | - </div> | |
| 312 | - } | |
| 313 | - } else { | |
| 314 | - for row in rows.iter() { | |
| 315 | - <div class="line" data-kb-row=""> | |
| 316 | - <a class="name" href=(row.href.as_str())>(row.title.as_str())</a> | |
| 317 | - <span class="tag">(row.category)</span> | |
| 318 | - <span class="val"> | |
| 319 | - (by_before) user_link(shown: row.author.as_str(), login: row.author.as_str()) (by_middle) | |
| 320 | - <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time> | |
| 321 | - (by_after) | |
| 322 | - " · " | |
| 323 | - <a href=(row.href.as_str())>(row.comments_text.as_str())</a> | |
| 324 | - </span> | |
| 325 | - </div> | |
| 326 | - } | |
| 327 | - } | |
| 328 | - if has_newer || has_older { | |
| 329 | - <nav class="pager"> | |
| 330 | - if has_newer { | |
| 331 | - <a href=(newer_href.as_str())>(newer_label)</a> | |
| 332 | - } | |
| 333 | - <span>(page_label.as_str())</span> | |
| 334 | - if has_older { | |
| 335 | - <a href=(older_href.as_str())>(older_label)</a> | |
| 336 | - } | |
| 337 | - </nav> | |
| 338 | - } | |
| 339 | - </div> | |
| 340 | - </div> | |
| 341 | - ) | |
| 342 | - }) | |
| 343 | -} | |
| 344 | - | |
| 345 | -#[derive(Default)] | |
| 346 | -struct DraftDiscussion { | |
| 347 | - title: String, | |
| 348 | - body: String, | |
| 349 | - error: Option<String>, | |
| 350 | -} | |
| 351 | - | |
| 352 | -#[component] | |
| 353 | -async fn new_discussion_body( | |
| 354 | - cx: &Cx, | |
| 355 | - lang: Lang, | |
| 356 | - head: RepoHead, | |
| 357 | - csrf: String, | |
| 358 | - draft: DraftDiscussion, | |
| 359 | - options: Vec<CategoryOption>, | |
| 360 | -) -> Result<impl View> { | |
| 361 | - let action = discussions_href(&head.owner, &head.name, "new"); | |
| 362 | - let cancel = discussions_href(&head.owner, &head.name, ""); | |
| 363 | - Ok(view! { | |
| 364 | - repo_head(head: head, title: Some(g::t(lang, K::NewDiscussion).to_owned())) | |
| 365 | - <div class="sheet fit"> | |
| 366 | - if let Some(message) = draft.error { | |
| 367 | - alert(message: message.as_str()) | |
| 368 | - } | |
| 369 | - <form method="post" action=(action.as_str()) class="fields"> | |
| 370 | - csrf_field(token: csrf.as_str()) | |
| 371 | - <div class="field"> | |
| 372 | - <label for="discussion-category">(g::t(lang, K::Category))</label> | |
| 373 | - <select id="discussion-category" name="category"> | |
| 374 | - for option in options.iter() { | |
| 375 | - <option value=(option.value) selected=(option.selected)>(option.label)</option> | |
| 376 | - } | |
| 377 | - </select> | |
| 378 | - </div> | |
| 379 | - <div class="field"> | |
| 380 | - <label for="discussion-title">(g::t(lang, K::Title))</label> | |
| 381 | - <input id="discussion-title" type="text" name="title" value=(draft.title.as_str()) required=(true) autocomplete="off"> | |
| 382 | - </div> | |
| 383 | - <div class="field"> | |
| 384 | - <label for="discussion-body">(g::t(lang, K::Description))</label> | |
| 385 | - <textarea id="discussion-body" name="body" rows="12">(draft.body.as_str())</textarea> | |
| 386 | - </div> | |
| 387 | - <div class="acts"> | |
| 388 | - <button type="submit" class="primary">(g::t(lang, K::StartDiscussion))</button> | |
| 389 | - <a class="act quiet" href=(cancel.as_str())>(crate::i18n::t(lang, crate::i18n::Key::Cancel))</a> | |
| 390 | - </div> | |
| 391 | - </form> | |
| 392 | - </div> | |
| 393 | - }) | |
| 394 | -} | |
| 395 | - | |
| 396 | -#[page("/{owner}/{repo}/discussions/new")] | |
| 397 | -async fn discussion_new_page(cx: &Cx) -> Result<impl View> { | |
| 398 | - let owner = owner(cx); | |
| 399 | - let name = repo(cx); | |
| 400 | - let ctx = load_repo(cx, owner, name).await?; | |
| 401 | - let state = context::<AppState>(cx); | |
| 402 | - ensure_enabled(state, &ctx).await?; | |
| 403 | - let viewer = require_user(cx).await?; | |
| 404 | - let lang = i18n::lang(cx, Some(&viewer.0)); | |
| 405 | - if ctx.repo.archived { | |
| 406 | - return Err(forbidden().into()); | |
| 407 | - } | |
| 408 | - let header = ctx.head(state, "discussions").await?; | |
| 409 | - let title = format!( | |
| 410 | - "{}/{} \u{b7} {}", | |
| 411 | - ctx.repo.owner_name, | |
| 412 | - ctx.repo.name, | |
| 413 | - g::t(lang, K::NewDiscussion) | |
| 414 | - ); | |
| 415 | - let csrf = viewer.1.csrf_token.clone(); | |
| 416 | - let options = category_options(lang, Some(DiscussionCategory::General), maintains(&ctx)); | |
| 417 | - Ok(view! { | |
| 418 | - shell(title: title.as_str(), viewer: Some(&viewer), | |
| 419 | - new_discussion_body(lang: lang, head: header, csrf: csrf, draft: DraftDiscussion::default(), options: options)) | |
| 420 | - }) | |
| 421 | -} | |
| 422 | - | |
| 423 | -#[page(POST "/{owner}/{repo}/discussions/new")] | |
| 424 | -async fn discussion_create(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> { | |
| 425 | - let owner = owner(cx); | |
| 426 | - let name = repo(cx); | |
| 427 | - let ctx = load_repo(cx, owner, name).await?; | |
| 428 | - let state = context::<AppState>(cx); | |
| 429 | - ensure_enabled(state, &ctx).await?; | |
| 430 | - let fields = form_pairs(&raw[..]); | |
| 431 | - let viewer = require_csrf(cx, &form_field(&fields, "csrf")).await?; | |
| 432 | - let lang = i18n::lang(cx, Some(&viewer.0)); | |
| 433 | - if ctx.repo.archived { | |
| 434 | - return Err(forbidden().into()); | |
| 435 | - } | |
| 436 | - let category = match form_field(&fields, "category").parse::<DiscussionCategory>() { | |
| 437 | - Ok(category) => category, | |
| 438 | - Err(_) => return Err(bad_request("unknown category").into()), | |
| 439 | - }; | |
| 440 | - if category == DiscussionCategory::Announcements && !maintains(&ctx) { | |
| 441 | - return Err(forbidden().into()); | |
| 442 | - } | |
| 443 | - let typed_title = form_field(&fields, "title"); | |
| 444 | - let typed_body = form_field(&fields, "body"); | |
| 445 | - match state | |
| 446 | - .store | |
| 447 | - .create_discussion( | |
| 448 | - &ctx.repo.id, | |
| 449 | - &viewer.0.id, | |
| 450 | - category, | |
| 451 | - &typed_title, | |
| 452 | - &typed_body, | |
| 453 | - ) | |
| 454 | - .await | |
| 455 | - { | |
| 456 | - Ok(discussion) => { | |
| 457 | - audit_discussion( | |
| 458 | - cx, | |
| 459 | - state, | |
| 460 | - &viewer.0, | |
| 461 | - &ctx, | |
| 462 | - AuditAction::DiscussionCreated, | |
| 463 | - &discussion.id, | |
| 464 | - ) | |
| 465 | - .await; | |
| 466 | - notify_mentions(state, &ctx, &discussion.id, &viewer.0.id, &typed_body, None).await; | |
| 467 | - let location = discussions_href( | |
| 468 | - &ctx.repo.owner_name, | |
| 469 | - &ctx.repo.name, | |
| 470 | - &discussion.number.to_string(), | |
| 471 | - ); | |
| 472 | - Err(see_other(location).into()) | |
| 473 | - } | |
| 474 | - Err(e) => { | |
| 475 | - let message = refusal_message(e)?; | |
| 476 | - let header = ctx.head(state, "discussions").await?; | |
| 477 | - let title = format!( | |
| 478 | - "{}/{} \u{b7} {}", | |
| 479 | - ctx.repo.owner_name, | |
| 480 | - ctx.repo.name, | |
| 481 | - g::t(lang, K::NewDiscussion) | |
| 482 | - ); | |
| 483 | - let csrf = viewer.1.csrf_token.clone(); | |
| 484 | - let draft = DraftDiscussion { | |
| 485 | - title: typed_title, | |
| 486 | - body: typed_body, | |
| 487 | - error: Some(message), | |
| 488 | - }; | |
| 489 | - let options = category_options(lang, Some(category), maintains(&ctx)); | |
| 490 | - Ok(view! { | |
| 491 | - (StatusCode::UNPROCESSABLE_ENTITY) | |
| 492 | - shell(title: title.as_str(), viewer: Some(&viewer), | |
| 493 | - new_discussion_body(lang: lang, head: header, csrf: csrf, draft: draft, options: options)) | |
| 494 | - }) | |
| 495 | - } | |
| 496 | - } | |
| 497 | -} | |
| 498 | - | |
| 499 | -pub(crate) async fn discussion_by_number( | |
| 500 | - state: &AppState, | |
| 501 | - ctx: &RepoCtx, | |
| 502 | - number: &str, | |
| 503 | -) -> Result<Discussion> { | |
| 504 | - let Some(n) = number.parse::<i64>().ok() else { | |
| 505 | - return Err(not_found().into()); | |
| 506 | - }; | |
| 507 | - match state.store.discussion_by_number(&ctx.repo.id, n).await? { | |
| 508 | - Some(discussion) => Ok(discussion), | |
| 509 | - None => Err(not_found().into()), | |
| 510 | - } | |
| 511 | -} |
crates/forge-web-repo/src/pages/mod.rsmodified+0 -5
| @@ -16,12 +16,7 @@ pub mod code_search; | ||
| 16 | 16 | pub mod commit; |
| 17 | 17 | pub mod commits; |
| 18 | 18 | pub mod compare; |
| 19 | -pub mod discussion_actions; | |
| 20 | -pub mod discussion_live; | |
| 21 | 19 | #[cfg(test)] |
| 22 | -mod discussion_live_tests; | |
| 23 | -pub mod discussion_view; | |
| 24 | -pub mod discussions; | |
| 25 | 20 | pub mod fork; |
| 26 | 21 | #[cfg(test)] |
| 27 | 22 | mod issue_meta_tests; |
crates/forge-web/assets/nav.jsmodified+2 -2
| @@ -3455,7 +3455,7 @@ | ||
| 3455 | 3455 | |
| 3456 | 3456 | // List memory: a list page keeps its filters (per path, in sessionStorage) and its scroll position |
| 3457 | 3457 | // when the reader leaves and comes back. Paging parameters are not filters. |
| 3458 | - var LIST_PAGE = /^\/[^\/]+\/[^\/]+\/(issues|pulls|ci|commits\/.*|releases|tags|branches|discussions|labels|milestones|merge-queue|search)$|^\/(explore|notifications|review-requests|admin\/users|admin\/runners|admin\/audit|settings\/security\/log|org\/[^\/]+\/members)$/; | |
| 3458 | + var LIST_PAGE = /^\/[^\/]+\/[^\/]+\/(issues|pulls|ci|commits\/.*|releases|tags|branches|labels|milestones|merge-queue|search)$|^\/(explore|notifications|review-requests|admin\/users|admin\/runners|admin\/audit|settings\/security\/log|org\/[^\/]+\/members)$/; | |
| 3459 | 3459 | var LIST_PAGING = ['page', 'before', 'after', 'cursor']; |
| 3460 | 3460 | var LIST_Y_TTL = 30 * 60 * 1000; // ms a remembered scroll position is still used |
| 3461 | 3461 | |
| @@ -5273,7 +5273,7 @@ | ||
| 5273 | 5273 | : { attach: 'Attach', title: 'Attach an image or file (you can also paste or drop it)', up: 'Uploading', fail: 'Upload failed', taskFail: 'Could not save the task' }; |
| 5274 | 5274 | |
| 5275 | 5275 | // Repo pages whose textareas take markdown. `/owner/repo/section/...` |
| 5276 | - var REPO_PATH = /^\/([^\/]+)\/([^\/]+)\/(issues|pulls|discussions|wiki|compare|releases)(\/|$)/; | |
| 5276 | + var REPO_PATH = /^\/([^\/]+)\/([^\/]+)\/(issues|pulls|wiki|compare|releases)(\/|$)/; | |
| 5277 | 5277 | var NAMES = { body: 1, content: 1, message: 1 }; |
| 5278 | 5278 | |
| 5279 | 5279 | function repoBase() { |
crates/forge-web/src/boot.rsmodified+0 -1
| @@ -158,7 +158,6 @@ pub async fn serve( | ||
| 158 | 158 | .layer(CookieLayer::new()) |
| 159 | 159 | .layer(forge_web_app::layers::RepoMovedLayer) |
| 160 | 160 | .layer(forge_web_app::layers::PullWriteLayer) |
| 161 | - .layer(forge_web_app::layers::DiscussionWriteLayer) | |
| 162 | 161 | .layer(forge_web_app::layers::OrgWriteLayer) |
| 163 | 162 | .layer(forge_web_app::layers::RepoSettingsWriteLayer) |
| 164 | 163 | .layer(forge_web_app::layers::NotFoundLayer) |
crates/forge-web/src/page_route_tests/notifications.rsmodified+0 -71
| @@ -372,74 +372,3 @@ async fn row_for_a_repo_the_viewer_lost_access_to_is_hidden() { | ||
| 372 | 372 | assert!(!page.body.contains("tahinli/demo #1 First")); |
| 373 | 373 | assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 0); |
| 374 | 374 | } |
| 375 | - | |
| 376 | -#[tokio::test] | |
| 377 | -async fn discussion_replies_show_in_the_inbox_and_clear_by_open_or_mark_all() { | |
| 378 | - let site = site().await; | |
| 379 | - let w = world(&site, Visibility::Public).await; | |
| 380 | - let discussion = site | |
| 381 | - .store | |
| 382 | - .create_discussion( | |
| 383 | - &w.repo.id, | |
| 384 | - &w.tahinli.id, | |
| 385 | - forge_core::discussions::DiscussionCategory::General, | |
| 386 | - "Ideas", | |
| 387 | - "", | |
| 388 | - ) | |
| 389 | - .await | |
| 390 | - .expect("discussion"); | |
| 391 | - site.store | |
| 392 | - .add_discussion_comment(&discussion.id, &w.bob.id, None, "+1", false) | |
| 393 | - .await | |
| 394 | - .expect("reply"); | |
| 395 | - let tahinli = sign_in(&site.store, &w.tahinli.id, "tahinli-token").await; | |
| 396 | - let bob = sign_in(&site.store, &w.bob.id, "bob-token").await; | |
| 397 | - let open = format!("/notifications/discussions/{}/open", discussion.id); | |
| 398 | - | |
| 399 | - let page = get(&site, "/notifications", Some(&tahinli)).await; | |
| 400 | - assert_eq!(page.status, 200); | |
| 401 | - assert!(page.body.contains("Ideas")); | |
| 402 | - assert!(page.body.contains(&open)); | |
| 403 | - assert_eq!( | |
| 404 | - site.store.unread_count(&w.tahinli.id).await.expect("count"), | |
| 405 | - 1 | |
| 406 | - ); | |
| 407 | - | |
| 408 | - let other = get(&site, &open, Some(&bob)).await; | |
| 409 | - assert_eq!(other.status, 404); | |
| 410 | - | |
| 411 | - let res = get(&site, &open, Some(&tahinli)).await; | |
| 412 | - assert_eq!(res.status, 303); | |
| 413 | - assert_eq!(res.location.as_deref(), Some("/tahinli/demo/discussions/2")); | |
| 414 | - assert_eq!( | |
| 415 | - site.store.unread_count(&w.tahinli.id).await.expect("count"), | |
| 416 | - 0 | |
| 417 | - ); | |
| 418 | - | |
| 419 | - let discussion = site | |
| 420 | - .store | |
| 421 | - .create_discussion( | |
| 422 | - &w.repo.id, | |
| 423 | - &w.tahinli.id, | |
| 424 | - forge_core::discussions::DiscussionCategory::General, | |
| 425 | - "Ideas", | |
| 426 | - "", | |
| 427 | - ) | |
| 428 | - .await | |
| 429 | - .expect("discussion"); | |
| 430 | - site.store | |
| 431 | - .add_discussion_comment(&discussion.id, &w.bob.id, None, "+1", false) | |
| 432 | - .await | |
| 433 | - .expect("reply"); | |
| 434 | - assert_eq!( | |
| 435 | - site.store.unread_count(&w.tahinli.id).await.expect("count"), | |
| 436 | - 1 | |
| 437 | - ); | |
| 438 | - | |
| 439 | - let res = post(&site, "/notifications/mark_all_read", &tahinli, "").await; | |
| 440 | - assert_eq!(res.status, 303); | |
| 441 | - assert_eq!( | |
| 442 | - site.store.unread_count(&w.tahinli.id).await.expect("count"), | |
| 443 | - 0 | |
| 444 | - ); | |
| 445 | -} |
crates/forge-web/src/routes.snapmodified+0 -17
| @@ -95,14 +95,6 @@ page /{owner}/{repo}/commit/{oid} Only([GET]) | ||
| 95 | 95 | page /{owner}/{repo}/commits/{*rest} Only([GET]) |
| 96 | 96 | page /{owner}/{repo}/compare Only([GET]) |
| 97 | 97 | page /{owner}/{repo}/compare/{*spec} Only([GET]) |
| 98 | -page /{owner}/{repo}/discussions Only([GET]) | |
| 99 | -page /{owner}/{repo}/discussions/new Only([GET]) | |
| 100 | -page /{owner}/{repo}/discussions/new Only([POST]) | |
| 101 | -page /{owner}/{repo}/discussions/{number} Only([GET]) | |
| 102 | -page /{owner}/{repo}/discussions/{number}/answer Only([POST]) | |
| 103 | -page /{owner}/{repo}/discussions/{number}/comments Only([POST]) | |
| 104 | -page /{owner}/{repo}/discussions/{number}/comments/{comment_id}/edit Only([POST]) | |
| 105 | -page /{owner}/{repo}/discussions/{number}/edit Only([POST]) | |
| 106 | 98 | page /{owner}/{repo}/issues Only([GET]) |
| 107 | 99 | page /{owner}/{repo}/issues/new Only([GET]) |
| 108 | 100 | page /{owner}/{repo}/issues/new Only([POST]) |
| @@ -292,8 +284,6 @@ route /needs-you/events Only([GET]) | ||
| 292 | 284 | route /needs-you/runs/dismiss Only([POST]) |
| 293 | 285 | route /notifications/admin/{admin_note}/open Only([GET]) |
| 294 | 286 | route /notifications/admin/{admin_note}/read Only([POST]) |
| 295 | -route /notifications/discussions/{discussion_id}/open Only([GET]) | |
| 296 | -route /notifications/discussions/{discussion_id}/read Only([POST]) | |
| 297 | 287 | route /notifications/events Only([GET]) |
| 298 | 288 | route /notifications/mark_all_read Only([POST]) |
| 299 | 289 | route /notifications/stream Only([GET]) |
| @@ -367,12 +357,6 @@ route /{owner}/{repo}/ci/runs/{run_number}/events Only([GET]) | ||
| 367 | 357 | route /{owner}/{repo}/ci/runs/{run_number}/rerun Only([POST]) |
| 368 | 358 | route /{owner}/{repo}/ci/runs/{run_number}/rerun-failed Only([POST]) |
| 369 | 359 | route /{owner}/{repo}/commit/{oid} Any |
| 370 | -route /{owner}/{repo}/discussions/live Only([GET]) | |
| 371 | -route /{owner}/{repo}/discussions/{number}/comments/{comment_id}/delete Only([POST]) | |
| 372 | -route /{owner}/{repo}/discussions/{number}/delete Only([POST]) | |
| 373 | -route /{owner}/{repo}/discussions/{number}/live Only([GET]) | |
| 374 | -route /{owner}/{repo}/discussions/{number}/lock Only([POST]) | |
| 375 | -route /{owner}/{repo}/discussions/{number}/reactions Only([POST]) | |
| 376 | 360 | route /{owner}/{repo}/events Only([GET]) |
| 377 | 361 | route /{owner}/{repo}/fork Only([POST]) |
| 378 | 362 | route /{owner}/{repo}/git-receive-pack Only([POST]) |
| @@ -429,7 +413,6 @@ route /{owner}/{repo}/settings/branches/delete Only([POST]) | ||
| 429 | 413 | route /{owner}/{repo}/settings/collaborators/add Only([POST]) |
| 430 | 414 | route /{owner}/{repo}/settings/collaborators/remove Only([POST]) |
| 431 | 415 | route /{owner}/{repo}/settings/collaborators/role Only([POST]) |
| 432 | -route /{owner}/{repo}/settings/discussions Only([POST]) | |
| 433 | 416 | route /{owner}/{repo}/settings/general Only([POST]) |
| 434 | 417 | route /{owner}/{repo}/settings/hooks/{hook_id}/delete Only([POST]) |
| 435 | 418 | route /{owner}/{repo}/settings/hooks/{hook_id}/deliveries/{delivery_id}/redeliver Only([POST]) |
docs/api.mdmodified+1 -1
| @@ -434,4 +434,4 @@ Git over HTTP accepts the same token as the Basic password, with your user name, | ||
| 434 | 434 | |
| 435 | 435 | Not carried over: topics, wiki and LFS objects (the clone brings the code only), user emails and |
| 436 | 436 | avatars (people arrive as plain user names, so the target creates placeholders you can re-map), |
| 437 | -team reviews, discussions, snippets, CI runs and secrets. | |
| 437 | +team reviews, snippets, CI runs and secrets. |
docs/architecture.mdmodified+1 -2
| @@ -51,7 +51,7 @@ project_git/ | ||
| 51 | 51 | forge-web-app/ everything below the pages: state, auth, live, views, CI, mail, backup, replication, git smart-HTTP, LFS, the HTTP APIs, test_support; its build.rs compiles the stylesheet |
| 52 | 52 | forge-web-pages/ pages the others build on: repo, tree, issues, pulls core, CI runs, wiki, releases, repo settings |
| 53 | 53 | forge-web-account/ account, admin, org and profile pages (on forge-web-pages) |
| 54 | - forge-web-repo/ code, commits, pull views, discussions, issue view pages (on forge-web-pages) | |
| 54 | + forge-web-repo/ code, commits, pull views, issue view pages (on forge-web-pages) | |
| 55 | 55 | forge-e2e/ end-to-end tests. They run `FORGE_BIN` when it is set, so CI tests the binary it ships, and otherwise build `forge` |
| 56 | 56 | ``` |
| 57 | 57 | |
| @@ -548,7 +548,6 @@ Known gaps: | ||
| 548 | 548 | - Merge strategies: merge commit (`commit-tree` from merge-tree output), squash, rebase, fast-forward only. |
| 549 | 549 | - `range-diff` for "what changed since the last review." AGit (`refs/for/<branch>`) is considered later. |
| 550 | 550 | - Live pages: the pull list and every pull tab (conversation, commits, files) update while open. Each has an event stream (`/{o}/{r}/pulls/events`, `/{o}/{r}/pulls/{n}/events`) that sends `changed` when a write changes what the page shows. A POST under the pulls paths, a push, a commit status for the head, and a mergeability or auto-merge run each wake it. The page re-reads in place and keeps typed text, focus and open inline forms; the Files tab keeps the file in view at the same offset. Streams are in-process, event driven, and never poll. Topics live in `live.rs`; the bump helpers are in `pages/pull_live.rs`. |
| 551 | -- Live discussions: the discussion list and each discussion page update while open. Each has an event stream (`/{o}/{r}/discussions/live`, `/{o}/{r}/discussions/{n}/live`) that sends `changed` when a comment, reply, reaction, answer, edit, lock, category change or new discussion changes what the page shows. A POST under the discussions paths and the discussions toggle in the repo settings wake them. Topics are `Discussions` (per repo) and `Discussion` (per discussion); the write layer is in `pages/discussion_live.rs`. The reply box keeps its typed text across an update. | |
| 552 | 551 | |
| 553 | 552 | ### Webhooks, push mirrors, replication, backups, export |
| 554 | 553 |
docs/backlog.mdmodified+0 -1
| @@ -87,7 +87,6 @@ Status: `[ ]` todo, `[~]` in progress, `[x]` done. | ||
| 87 | 87 | - [x] M2 mail flows (password reset, email verification, invites; notification emails move to M3) |
| 88 | 88 | - [x] M3 notification emails (per-user opt-out on `/settings/notifications`, threaded by Message-ID) |
| 89 | 89 | - [x] W1 wiki (git-backed, web editing, clone/push, backups/replication) |
| 90 | -- [x] D1 discussions | |
| 91 | 90 | - [x] S1 snippets |
| 92 | 91 | - [x] T1 theme and language preferences (dark mode toggle) |
| 93 | 92 | - [x] I18 i18n infrastructure (En/Tr) and the shell, auth and settings pages |
scripts/audit/seed.pymodified+0 -15
| @@ -456,21 +456,6 @@ def _(): | ||
| 456 | 456 | admin.post(f"{R}/settings/collaborators/add", {"username": OTHER, "role": "write"}) |
| 457 | 457 | |
| 458 | 458 | |
| 459 | -@step("discussion") | |
| 460 | -def _(): | |
| 461 | - r = admin.get(f"{R}/discussions/new") | |
| 462 | - if r.status >= 400: | |
| 463 | - admin.post(f"{R}/settings/discussions", {"enabled": "1"}) | |
| 464 | - r = admin.get(f"{R}/discussions/new") | |
| 465 | - cats = re.findall(r'<option value="([^"]+)"', r.text) | |
| 466 | - ok(admin.post(f"{R}/discussions/new", {"category": cats[0] if cats else "general", | |
| 467 | - "title": "Roadmap for 0.3", "body": "What should land next?"}), "discussion") | |
| 468 | - # Discussions share the issue/PR number counter, so find the real number. | |
| 469 | - nums = re.findall(rf'{re.escape(R)}/discussions/(\d+)', admin.get(f"{R}/discussions").text) | |
| 470 | - seed["discussion_number"] = int(nums[0]) if nums else 1 | |
| 471 | - other.post(f"{R}/discussions/{seed['discussion_number']}/comments", {"body": "Mobile layout fixes please!"}) | |
| 472 | - | |
| 473 | - | |
| 474 | 459 | @step("ci runner registration") |
| 475 | 460 | def _(): |
| 476 | 461 | r = ok(admin.post("/admin/runners/tokens", {}), "runner token") |
scripts/audit/shoot.pymodified+1 -3
| @@ -413,8 +413,6 @@ def concrete(pat): | ||
| 413 | 413 | fill["{comment_id}"] = s.get("pull_comment_id") |
| 414 | 414 | if "/review_comments/" in pat: |
| 415 | 415 | fill["{comment_id}"] = s.get("review_comment_id") |
| 416 | - elif "/discussions/{number}" in pat: | |
| 417 | - fill["{number}"] = s.get("discussion_number", 1) | |
| 418 | 416 | else: |
| 419 | 417 | fill["{number}"] = 1 |
| 420 | 418 | fill["{comment_id}"] = s.get("issue_comment_id") |
| @@ -496,7 +494,7 @@ def area_of(pat): | ||
| 496 | 494 | return "profile-orgs" |
| 497 | 495 | if "/actions" in p or "/ci" in p or "/runs" in p or "/runners" in p or "/artifacts" in p: |
| 498 | 496 | return "ci" |
| 499 | - if "/issues" in p or "/pulls" in p or "/discussions" in p or "/milestones" in p or "/labels" in p: | |
| 497 | + if "/issues" in p or "/pulls" in p or "/milestones" in p or "/labels" in p: | |
| 500 | 498 | return "issues-prs" |
| 501 | 499 | if p.startswith("/{owner}/{repo}"): |
| 502 | 500 | return "repo" |
style/_min_lists.scssmodified+1 -1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | // The lists pages: only what style/_min.scss does not already give them. |
| 2 | 2 | |
| 3 | -// Issue, pull and discussion rows: the title, then its meta line under it. Nothing sits at the far end. | |
| 3 | +// Issue and pull rows: the title, then its meta line under it. Nothing sits at the far end. | |
| 4 | 4 | .line.issue-row { |
| 5 | 5 | align-items: flex-start; |
| 6 | 6 | min-height: 0; |
style/_min_threads.scssmodified+0 -9
| @@ -83,15 +83,6 @@ | ||
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | -// Replies sit under their comment, indented, with a hairline down their left side. | |
| 87 | -.discussion-replies { | |
| 88 | - display: flex; | |
| 89 | - flex-direction: column; | |
| 90 | - margin-left: 12px; | |
| 91 | - padding-left: 16px; | |
| 92 | - border-left: 1px solid var(--border); | |
| 93 | -} | |
| 94 | - | |
| 95 | 86 | // The merge box is a topic, its checks are rows: no frame. |
| 96 | 87 | main .merge-box, |
| 97 | 88 | main .merge-box .status-list { |
style/_one_threads.scssmodified+2 -36
| @@ -2,8 +2,7 @@ | ||
| 2 | 2 | |
| 3 | 3 | // Lists with a rail: the sheet is as tall as its rows, as every list is; the tools row and every row |
| 4 | 4 | // stay on one line. |
| 5 | -.work:has(> .sheet > .issue-row), | |
| 6 | -.work[data-live$="/discussions/live"] { | |
| 5 | +.work:has(> .sheet > .issue-row) { | |
| 7 | 6 | align-items: start; |
| 8 | 7 | |
| 9 | 8 | > .sheet { |
| @@ -124,38 +123,6 @@ | ||
| 124 | 123 | box-shadow: none; |
| 125 | 124 | } |
| 126 | 125 | |
| 127 | -// Discussion: the opening post and its replies are entries in one sheet, the same as issue entries. | |
| 128 | -.sheet:has(> #discussion-body) { | |
| 129 | - > .sec { | |
| 130 | - padding: 16px 18px; | |
| 131 | - } | |
| 132 | - | |
| 133 | - > .sec .hint { | |
| 134 | - display: flex; | |
| 135 | - align-items: center; | |
| 136 | - gap: 8px; | |
| 137 | - margin: 0 0 6px; | |
| 138 | - font-size: 14px; | |
| 139 | - } | |
| 140 | - | |
| 141 | - .discussion-thread > .sec { | |
| 142 | - padding: 16px 18px; | |
| 143 | - border-top: 1px solid var(--border); | |
| 144 | - } | |
| 145 | - | |
| 146 | - .discussion-thread > .sec .hint { | |
| 147 | - display: flex; | |
| 148 | - align-items: center; | |
| 149 | - gap: 8px; | |
| 150 | - margin: 0 0 6px; | |
| 151 | - font-size: 14px; | |
| 152 | - } | |
| 153 | - | |
| 154 | - .discussion-thread > .acts { | |
| 155 | - margin-left: 14px; | |
| 156 | - } | |
| 157 | -} | |
| 158 | - | |
| 159 | 126 | .sheet:has(#create-label) input[type="color"] { |
| 160 | 127 | width: 38px; |
| 161 | 128 | height: var(--control-h); |
| @@ -167,8 +134,7 @@ | ||
| 167 | 134 | |
| 168 | 135 | // Phone: the filters become one row to scroll, the tools wrap, and each row keeps its name on the first line. |
| 169 | 136 | @media (max-width: 760px) { |
| 170 | - .work:has(> .sheet > .issue-row), | |
| 171 | - .work[data-live$="/discussions/live"] { | |
| 137 | + .work:has(> .sheet > .issue-row) { | |
| 172 | 138 | display: flex; |
| 173 | 139 | flex-direction: column; |
| 174 | 140 | align-items: stretch; |
style/_pull.scssmodified+0 -13
| @@ -682,19 +682,6 @@ input[type="color"] { | ||
| 682 | 682 | cursor: pointer; |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | -// Discussions: category chip and the action bar under a post. | |
| 686 | -.discussion-category { | |
| 687 | - display: inline-flex; | |
| 688 | - align-items: center; | |
| 689 | - padding: 2px 10px; | |
| 690 | - border: 1px solid var(--border); | |
| 691 | - border-radius: var(--radius-full); | |
| 692 | - background: var(--surface-2); | |
| 693 | - color: var(--text); | |
| 694 | - font-size: 12.5px; | |
| 695 | - font-weight: 600; | |
| 696 | -} | |
| 697 | - | |
| 698 | 685 | // Edit and new forms share one card width. |
| 699 | 686 | .issue-edit { |
| 700 | 687 | max-width: 60rem; |
style/main.scssmodified+0 -16
| @@ -5659,22 +5659,6 @@ button.ci-job-last { | ||
| 5659 | 5659 | padding: 12px; |
| 5660 | 5660 | } |
| 5661 | 5661 | |
| 5662 | -/* Discussions: threads of comments, replies indented under their parent, the accepted answer. */ | |
| 5663 | -.discussion-thread { | |
| 5664 | - margin-bottom: 0.5rem; | |
| 5665 | -} | |
| 5666 | - | |
| 5667 | -.discussion-replies { | |
| 5668 | - margin-left: 2rem; | |
| 5669 | - padding-left: 0.75rem; | |
| 5670 | - border-left: 2px solid var(--border); | |
| 5671 | -} | |
| 5672 | - | |
| 5673 | -.discussion-accepted { | |
| 5674 | - border-left: 3px solid var(--ok); | |
| 5675 | - padding-left: 0.75rem; | |
| 5676 | -} | |
| 5677 | - | |
| 5678 | 5662 | // Sage redesign partials. Loaded last so they override the older rules above. |
| 5679 | 5663 | @import "shell"; |
| 5680 | 5664 | @import "heatmap"; |