🔥 remove: snippets (code pastes, /snippets pages, profile Snippets tab, raw snippet route)
Browse files at this commit3114692aca7f69cb127697f9c644bac69f0117a8Parent: aabd61230 changed files +10 -2894
- crates/forge-core/src/audit.rs +0 -3
- crates/forge-core/src/names.rs +0 -1
- crates/forge-core/src/store/mod.rs +0 -1
- crates/forge-core/src/store/snippets.rs +0 -574
- crates/forge-e2e/tests/e2e/community_i18n_e2e.rs +0 -43
- crates/forge-e2e/tests/e2e/main.rs +0 -2
- crates/forge-e2e/tests/e2e/snippets_e2e.rs +0 -431
- crates/forge-web-account/src/lib.rs +1 -2
- crates/forge-web-account/src/pages/admin_user_detail.rs +1 -13
- crates/forge-web-account/src/pages/mod.rs +0 -2
- crates/forge-web-account/src/pages/profile.rs +2 -60
- crates/forge-web-account/src/pages/snippets.rs +0 -912
- crates/forge-web-account/src/pages/snippets_live.rs +0 -106
- crates/forge-web-app/src/live.rs +0 -2
- crates/forge-web-app/src/raw/mod.rs +0 -6
- crates/forge-web-app/src/raw/snippet_raw.rs +0 -126
- crates/forge-web-app/src/views/mod.rs +0 -22
- crates/forge-web-base/src/i18n/audit_names.rs +0 -11
- crates/forge-web-base/src/i18n/community.rs +0 -72
- crates/forge-web/src/routes.snap +0 -10
- docs/api.md +1 -1
- docs/architecture.md +0 -1
- docs/backlog.md +0 -1
- docs/ui-language.md +2 -2
- scripts/audit/seed.py +0 -21
- scripts/audit/shoot.py +1 -3
- style/_look.scss +0 -1
- style/_min.scss +1 -2
- style/_one_people.scss +0 -247
- style/main.scss +1 -216
crates/forge-core/src/audit.rsmodified+0 -3
| @@ -77,9 +77,6 @@ audit_actions! { | |||
| 77 | MailTestQueued => "mail_test_queued", | 77 | MailTestQueued => "mail_test_queued", |
| 78 | ServerSettingsUpdated => "server_settings_updated", | 78 | ServerSettingsUpdated => "server_settings_updated", |
| 79 | ServerRestarted => "server_restarted", | 79 | ServerRestarted => "server_restarted", |
| 80 | - SnippetCreated => "snippet_created", | ||
| 81 | - SnippetUpdated => "snippet_updated", | ||
| 82 | - SnippetDeleted => "snippet_deleted", | ||
| 83 | OrgCreated => "org_created", | 80 | OrgCreated => "org_created", |
| 84 | OrgDeleted => "org_deleted", | 81 | OrgDeleted => "org_deleted", |
| 85 | OrgSettingsUpdated => "org_settings_updated", | 82 | OrgSettingsUpdated => "org_settings_updated", |
crates/forge-core/src/names.rsmodified+0 -1
| @@ -34,7 +34,6 @@ pub const RESERVED: &[&str] = &[ | |||
| 34 | "dashboard", | 34 | "dashboard", |
| 35 | "issues", | 35 | "issues", |
| 36 | "pulls", | 36 | "pulls", |
| 37 | - "snippets", | ||
| 38 | "ghost", | 37 | "ghost", |
| 39 | "favicon.ico", | 38 | "favicon.ico", |
| 40 | "robots.txt", | 39 | "robots.txt", |
crates/forge-core/src/store/mod.rsmodified+0 -1
| @@ -38,7 +38,6 @@ pub mod server_settings; | |||
| 38 | pub mod shell_activity; | 38 | pub mod shell_activity; |
| 39 | pub mod signatures; | 39 | pub mod signatures; |
| 40 | pub mod snapshot; | 40 | pub mod snapshot; |
| 41 | -pub mod snippets; | ||
| 42 | pub mod suggest; | 41 | pub mod suggest; |
| 43 | pub mod suspension; | 42 | pub mod suspension; |
| 44 | pub mod transfers; | 43 | pub mod transfers; |
crates/forge-core/src/store/snippets.rsdeleted+0 -574
| @@ -1,574 +0,0 @@ | |||
| 1 | -use serde::{Deserialize, Serialize}; | ||
| 2 | -use turso::Connection; | ||
| 3 | - | ||
| 4 | -use super::issues::parse_db; | ||
| 5 | -use super::{Store, col_int, col_text, db_err, fetch_all, fetch_opt, finish, new_id}; | ||
| 6 | -use crate::error::{Error, Result}; | ||
| 7 | -use crate::time::now_stamp; | ||
| 8 | - | ||
| 9 | -pub const MAX_FILES: usize = 10; | ||
| 10 | -pub const MAX_TOTAL_BYTES: usize = 1024 * 1024; | ||
| 11 | -pub const MAX_TITLE_CHARS: usize = 120; | ||
| 12 | -pub const MAX_DESCRIPTION_CHARS: usize = 1000; | ||
| 13 | -pub const MAX_FILE_NAME_CHARS: usize = 100; | ||
| 14 | -const LIST_LIMIT: i64 = 200; | ||
| 15 | - | ||
| 16 | -#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 17 | -pub enum SnippetVisibility { | ||
| 18 | - Public, | ||
| 19 | - Unlisted, | ||
| 20 | - Private, | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -impl SnippetVisibility { | ||
| 24 | - pub const ALL: [SnippetVisibility; 3] = [ | ||
| 25 | - SnippetVisibility::Public, | ||
| 26 | - SnippetVisibility::Unlisted, | ||
| 27 | - SnippetVisibility::Private, | ||
| 28 | - ]; | ||
| 29 | -} | ||
| 30 | - | ||
| 31 | -string_enum!(SnippetVisibility { | ||
| 32 | - Public = "public", | ||
| 33 | - Unlisted = "unlisted", | ||
| 34 | - Private = "private", | ||
| 35 | -}); | ||
| 36 | - | ||
| 37 | -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| 38 | -pub struct SnippetFile { | ||
| 39 | - pub name: String, | ||
| 40 | - pub content: String, | ||
| 41 | -} | ||
| 42 | - | ||
| 43 | -#[derive(Debug, Clone, PartialEq, Eq)] | ||
| 44 | -pub struct Snippet { | ||
| 45 | - pub id: String, | ||
| 46 | - pub owner_id: String, | ||
| 47 | - pub owner_name: String, | ||
| 48 | - pub title: String, | ||
| 49 | - pub description: String, | ||
| 50 | - pub visibility: SnippetVisibility, | ||
| 51 | - pub created_at: String, | ||
| 52 | - pub updated_at: String, | ||
| 53 | - pub files: Vec<SnippetFile>, | ||
| 54 | -} | ||
| 55 | - | ||
| 56 | -impl Snippet { | ||
| 57 | - pub fn is_visible_to(&self, viewer_id: Option<&str>) -> bool { | ||
| 58 | - self.visibility != SnippetVisibility::Private || viewer_id == Some(self.owner_id.as_str()) | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - pub fn file(&self, name: &str) -> Option<&SnippetFile> { | ||
| 62 | - self.files.iter().find(|f| f.name == name) | ||
| 63 | - } | ||
| 64 | -} | ||
| 65 | - | ||
| 66 | -#[derive(Debug, Clone, PartialEq, Eq)] | ||
| 67 | -pub struct SnippetSummary { | ||
| 68 | - pub id: String, | ||
| 69 | - pub owner_name: String, | ||
| 70 | - pub title: String, | ||
| 71 | - pub visibility: SnippetVisibility, | ||
| 72 | - pub updated_at: String, | ||
| 73 | - pub file_count: u64, | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | -#[derive(Debug, Clone, PartialEq, Eq)] | ||
| 77 | -pub struct SnippetRevision { | ||
| 78 | - pub id: String, | ||
| 79 | - pub author_name: String, | ||
| 80 | - pub created_at: String, | ||
| 81 | - pub files: Vec<SnippetFile>, | ||
| 82 | -} | ||
| 83 | - | ||
| 84 | -pub fn validate_file_name(name: &str) -> Result<()> { | ||
| 85 | - let count = name.chars().count(); | ||
| 86 | - if count == 0 || count > MAX_FILE_NAME_CHARS { | ||
| 87 | - return Err(Error::Invalid(format!( | ||
| 88 | - "file names must be 1 to {MAX_FILE_NAME_CHARS} characters" | ||
| 89 | - ))); | ||
| 90 | - } | ||
| 91 | - if name.starts_with('.') { | ||
| 92 | - return Err(Error::Invalid("file names must not start with '.'".into())); | ||
| 93 | - } | ||
| 94 | - if !name | ||
| 95 | - .chars() | ||
| 96 | - .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-')) | ||
| 97 | - { | ||
| 98 | - return Err(Error::Invalid(format!( | ||
| 99 | - "file name {name:?} may only use letters, digits, '.', '_' and '-'" | ||
| 100 | - ))); | ||
| 101 | - } | ||
| 102 | - Ok(()) | ||
| 103 | -} | ||
| 104 | - | ||
| 105 | -pub fn validate_title(title: &str) -> Result<()> { | ||
| 106 | - let trimmed = title.trim(); | ||
| 107 | - if trimmed.is_empty() || trimmed.chars().count() > MAX_TITLE_CHARS { | ||
| 108 | - return Err(Error::Invalid(format!( | ||
| 109 | - "the title must be 1 to {MAX_TITLE_CHARS} characters" | ||
| 110 | - ))); | ||
| 111 | - } | ||
| 112 | - Ok(()) | ||
| 113 | -} | ||
| 114 | - | ||
| 115 | -pub fn validate_description(description: &str) -> Result<()> { | ||
| 116 | - if description.trim().chars().count() > MAX_DESCRIPTION_CHARS { | ||
| 117 | - return Err(Error::Invalid(format!( | ||
| 118 | - "the description must be at most {MAX_DESCRIPTION_CHARS} characters" | ||
| 119 | - ))); | ||
| 120 | - } | ||
| 121 | - Ok(()) | ||
| 122 | -} | ||
| 123 | - | ||
| 124 | -pub fn validate_files(files: &[SnippetFile]) -> Result<()> { | ||
| 125 | - if files.is_empty() { | ||
| 126 | - return Err(Error::Invalid("a snippet needs at least one file".into())); | ||
| 127 | - } | ||
| 128 | - if files.len() > MAX_FILES { | ||
| 129 | - return Err(Error::Invalid(format!( | ||
| 130 | - "a snippet can hold at most {MAX_FILES} files" | ||
| 131 | - ))); | ||
| 132 | - } | ||
| 133 | - let mut total = 0usize; | ||
| 134 | - for (i, file) in files.iter().enumerate() { | ||
| 135 | - validate_file_name(&file.name)?; | ||
| 136 | - if files[..i].iter().any(|other| other.name == file.name) { | ||
| 137 | - return Err(Error::Invalid(format!( | ||
| 138 | - "two files are named {:?}", | ||
| 139 | - file.name | ||
| 140 | - ))); | ||
| 141 | - } | ||
| 142 | - if file.content.contains('\0') { | ||
| 143 | - return Err(Error::Invalid(format!( | ||
| 144 | - "{:?} looks like binary data; snippets hold text only", | ||
| 145 | - file.name | ||
| 146 | - ))); | ||
| 147 | - } | ||
| 148 | - total = total.saturating_add(file.content.len()); | ||
| 149 | - } | ||
| 150 | - if total > MAX_TOTAL_BYTES { | ||
| 151 | - return Err(Error::Invalid( | ||
| 152 | - "the files together may be at most 1 MiB".into(), | ||
| 153 | - )); | ||
| 154 | - } | ||
| 155 | - Ok(()) | ||
| 156 | -} | ||
| 157 | - | ||
| 158 | -const SNIPPET_COLS: &str = "s.id, s.owner_id, u.username, s.title, s.description, s.visibility, \ | ||
| 159 | - s.created_at, s.updated_at"; | ||
| 160 | - | ||
| 161 | -fn map_snippet(row: &turso::Row) -> Result<Snippet> { | ||
| 162 | - let visibility = col_text(row, 5)?; | ||
| 163 | - Ok(Snippet { | ||
| 164 | - id: col_text(row, 0)?, | ||
| 165 | - owner_id: col_text(row, 1)?, | ||
| 166 | - owner_name: col_text(row, 2)?, | ||
| 167 | - title: col_text(row, 3)?, | ||
| 168 | - description: col_text(row, 4)?, | ||
| 169 | - visibility: parse_db(&visibility)?, | ||
| 170 | - created_at: col_text(row, 6)?, | ||
| 171 | - updated_at: col_text(row, 7)?, | ||
| 172 | - files: Vec::new(), | ||
| 173 | - }) | ||
| 174 | -} | ||
| 175 | - | ||
| 176 | -fn summary_row(row: &turso::Row) -> Result<SnippetSummary> { | ||
| 177 | - let visibility = col_text(row, 3)?; | ||
| 178 | - Ok(SnippetSummary { | ||
| 179 | - id: col_text(row, 0)?, | ||
| 180 | - owner_name: col_text(row, 1)?, | ||
| 181 | - title: col_text(row, 2)?, | ||
| 182 | - visibility: parse_db(&visibility)?, | ||
| 183 | - updated_at: col_text(row, 4)?, | ||
| 184 | - file_count: u64::try_from(col_int(row, 5)?).unwrap_or(0), | ||
| 185 | - }) | ||
| 186 | -} | ||
| 187 | - | ||
| 188 | -fn map_file(row: &turso::Row) -> Result<SnippetFile> { | ||
| 189 | - Ok(SnippetFile { | ||
| 190 | - name: col_text(row, 0)?, | ||
| 191 | - content: col_text(row, 1)?, | ||
| 192 | - }) | ||
| 193 | -} | ||
| 194 | - | ||
| 195 | -async fn write_files(conn: &Connection, snippet_id: &str, files: &[SnippetFile]) -> Result<()> { | ||
| 196 | - for (position, file) in files.iter().enumerate() { | ||
| 197 | - conn.execute( | ||
| 198 | - "INSERT INTO snippet_files (snippet_id, name, content, position) VALUES (?1, ?2, ?3, ?4)", | ||
| 199 | - ( | ||
| 200 | - snippet_id.to_string(), | ||
| 201 | - file.name.clone(), | ||
| 202 | - file.content.clone(), | ||
| 203 | - position as i64, | ||
| 204 | - ), | ||
| 205 | - ) | ||
| 206 | - .await | ||
| 207 | - .map_err(db_err)?; | ||
| 208 | - } | ||
| 209 | - Ok(()) | ||
| 210 | -} | ||
| 211 | - | ||
| 212 | -async fn write_revision( | ||
| 213 | - conn: &Connection, | ||
| 214 | - snippet_id: &str, | ||
| 215 | - author_id: &str, | ||
| 216 | - at: &str, | ||
| 217 | - files: &[SnippetFile], | ||
| 218 | -) -> Result<()> { | ||
| 219 | - let json = serde_json::to_string(files).map_err(|e| Error::Database(e.to_string()))?; | ||
| 220 | - conn.execute( | ||
| 221 | - "INSERT INTO snippet_revisions (id, snippet_id, author_id, created_at, files_json) \ | ||
| 222 | - VALUES (?1, ?2, ?3, ?4, ?5)", | ||
| 223 | - ( | ||
| 224 | - new_id(), | ||
| 225 | - snippet_id.to_string(), | ||
| 226 | - author_id.to_string(), | ||
| 227 | - at.to_string(), | ||
| 228 | - json, | ||
| 229 | - ), | ||
| 230 | - ) | ||
| 231 | - .await | ||
| 232 | - .map_err(db_err)?; | ||
| 233 | - Ok(()) | ||
| 234 | -} | ||
| 235 | - | ||
| 236 | -impl Store { | ||
| 237 | - pub async fn create_snippet( | ||
| 238 | - &self, | ||
| 239 | - owner_id: &str, | ||
| 240 | - title: &str, | ||
| 241 | - description: &str, | ||
| 242 | - visibility: SnippetVisibility, | ||
| 243 | - files: &[SnippetFile], | ||
| 244 | - ) -> Result<Snippet> { | ||
| 245 | - validate_title(title)?; | ||
| 246 | - validate_description(description)?; | ||
| 247 | - validate_files(files)?; | ||
| 248 | - let id = new_id(); | ||
| 249 | - let now = now_stamp(); | ||
| 250 | - let conn = self.inner.conn.lock().await; | ||
| 251 | - let tx = conn.unchecked_transaction().await.map_err(db_err)?; | ||
| 252 | - let outcome: Result<()> = async { | ||
| 253 | - tx.execute( | ||
| 254 | - "INSERT INTO snippets (id, owner_id, title, description, visibility, created_at, updated_at) \ | ||
| 255 | - VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?6)", | ||
| 256 | - ( | ||
| 257 | - id.clone(), | ||
| 258 | - owner_id.to_string(), | ||
| 259 | - title.trim().to_string(), | ||
| 260 | - description.trim().to_string(), | ||
| 261 | - visibility.as_str().to_string(), | ||
| 262 | - now.clone(), | ||
| 263 | - ), | ||
| 264 | - ) | ||
| 265 | - .await | ||
| 266 | - .map_err(db_err)?; | ||
| 267 | - write_files(&tx, &id, files).await?; | ||
| 268 | - write_revision(&tx, &id, owner_id, &now, files).await | ||
| 269 | - } | ||
| 270 | - .await; | ||
| 271 | - finish(tx, outcome).await?; | ||
| 272 | - drop(conn); | ||
| 273 | - self.get_snippet(&id).await?.ok_or(Error::NotFound) | ||
| 274 | - } | ||
| 275 | - | ||
| 276 | - pub async fn update_snippet( | ||
| 277 | - &self, | ||
| 278 | - owner_id: &str, | ||
| 279 | - snippet_id: &str, | ||
| 280 | - title: &str, | ||
| 281 | - description: &str, | ||
| 282 | - visibility: SnippetVisibility, | ||
| 283 | - files: &[SnippetFile], | ||
| 284 | - ) -> Result<Snippet> { | ||
| 285 | - validate_title(title)?; | ||
| 286 | - validate_description(description)?; | ||
| 287 | - validate_files(files)?; | ||
| 288 | - let now = now_stamp(); | ||
| 289 | - let conn = self.inner.conn.lock().await; | ||
| 290 | - let tx = conn.unchecked_transaction().await.map_err(db_err)?; | ||
| 291 | - let outcome: Result<()> = async { | ||
| 292 | - let changed = tx | ||
| 293 | - .execute( | ||
| 294 | - "UPDATE snippets SET title = ?1, description = ?2, visibility = ?3, updated_at = ?4 \ | ||
| 295 | - WHERE id = ?5 AND owner_id = ?6", | ||
| 296 | - ( | ||
| 297 | - title.trim().to_string(), | ||
| 298 | - description.trim().to_string(), | ||
| 299 | - visibility.as_str().to_string(), | ||
| 300 | - now.clone(), | ||
| 301 | - snippet_id.to_string(), | ||
| 302 | - owner_id.to_string(), | ||
| 303 | - ), | ||
| 304 | - ) | ||
| 305 | - .await | ||
| 306 | - .map_err(db_err)?; | ||
| 307 | - if changed == 0 { | ||
| 308 | - return Err(Error::NotFound); | ||
| 309 | - } | ||
| 310 | - tx.execute( | ||
| 311 | - "DELETE FROM snippet_files WHERE snippet_id = ?1", | ||
| 312 | - (snippet_id.to_string(),), | ||
| 313 | - ) | ||
| 314 | - .await | ||
| 315 | - .map_err(db_err)?; | ||
| 316 | - write_files(&tx, snippet_id, files).await?; | ||
| 317 | - write_revision(&tx, snippet_id, owner_id, &now, files).await | ||
| 318 | - } | ||
| 319 | - .await; | ||
| 320 | - finish(tx, outcome).await?; | ||
| 321 | - drop(conn); | ||
| 322 | - self.get_snippet(snippet_id).await?.ok_or(Error::NotFound) | ||
| 323 | - } | ||
| 324 | - | ||
| 325 | - pub async fn delete_snippet(&self, owner_id: &str, snippet_id: &str) -> Result<bool> { | ||
| 326 | - let conn = self.inner.conn.lock().await; | ||
| 327 | - let tx = conn.unchecked_transaction().await.map_err(db_err)?; | ||
| 328 | - let outcome: Result<bool> = async { | ||
| 329 | - let owned = fetch_opt( | ||
| 330 | - &tx, | ||
| 331 | - "SELECT 1 FROM snippets WHERE id = ?1 AND owner_id = ?2", | ||
| 332 | - (snippet_id.to_string(), owner_id.to_string()), | ||
| 333 | - |row| col_int(row, 0), | ||
| 334 | - ) | ||
| 335 | - .await?; | ||
| 336 | - if owned.is_none() { | ||
| 337 | - return Ok(false); | ||
| 338 | - } | ||
| 339 | - for sql in [ | ||
| 340 | - "DELETE FROM snippet_revisions WHERE snippet_id = ?1", | ||
| 341 | - "DELETE FROM snippet_files WHERE snippet_id = ?1", | ||
| 342 | - "DELETE FROM snippets WHERE id = ?1", | ||
| 343 | - ] { | ||
| 344 | - tx.execute(sql, (snippet_id.to_string(),)) | ||
| 345 | - .await | ||
| 346 | - .map_err(db_err)?; | ||
| 347 | - } | ||
| 348 | - Ok(true) | ||
| 349 | - } | ||
| 350 | - .await; | ||
| 351 | - finish(tx, outcome).await | ||
| 352 | - } | ||
| 353 | - | ||
| 354 | - pub async fn get_snippet(&self, snippet_id: &str) -> Result<Option<Snippet>> { | ||
| 355 | - let conn = self.read_conn().await; | ||
| 356 | - let Some(mut snippet) = fetch_opt( | ||
| 357 | - &conn, | ||
| 358 | - &format!( | ||
| 359 | - "SELECT {SNIPPET_COLS} FROM snippets s JOIN users u ON u.id = s.owner_id \ | ||
| 360 | - WHERE s.id = ?1" | ||
| 361 | - ), | ||
| 362 | - (snippet_id.to_string(),), | ||
| 363 | - map_snippet, | ||
| 364 | - ) | ||
| 365 | - .await? | ||
| 366 | - else { | ||
| 367 | - return Ok(None); | ||
| 368 | - }; | ||
| 369 | - snippet.files = fetch_all( | ||
| 370 | - &conn, | ||
| 371 | - "SELECT name, content FROM snippet_files WHERE snippet_id = ?1 ORDER BY position", | ||
| 372 | - (snippet_id.to_string(),), | ||
| 373 | - map_file, | ||
| 374 | - ) | ||
| 375 | - .await?; | ||
| 376 | - Ok(Some(snippet)) | ||
| 377 | - } | ||
| 378 | - | ||
| 379 | - pub async fn list_snippets(&self, viewer_id: Option<&str>) -> Result<Vec<SnippetSummary>> { | ||
| 380 | - let conn = self.read_conn().await; | ||
| 381 | - fetch_all( | ||
| 382 | - &conn, | ||
| 383 | - "SELECT s.id, u.username, s.title, s.visibility, s.updated_at, \ | ||
| 384 | - (SELECT COUNT(*) FROM snippet_files f WHERE f.snippet_id = s.id) \ | ||
| 385 | - FROM snippets s JOIN users u ON u.id = s.owner_id \ | ||
| 386 | - WHERE s.visibility = 'public' OR s.owner_id = ?1 \ | ||
| 387 | - ORDER BY s.updated_at DESC, s.id DESC LIMIT ?2", | ||
| 388 | - (viewer_id.unwrap_or("").to_string(), LIST_LIMIT), | ||
| 389 | - summary_row, | ||
| 390 | - ) | ||
| 391 | - .await | ||
| 392 | - } | ||
| 393 | - | ||
| 394 | - pub async fn list_owner_snippets( | ||
| 395 | - &self, | ||
| 396 | - owner_id: &str, | ||
| 397 | - viewer_id: Option<&str>, | ||
| 398 | - ) -> Result<Vec<SnippetSummary>> { | ||
| 399 | - let conn = self.read_conn().await; | ||
| 400 | - fetch_all( | ||
| 401 | - &conn, | ||
| 402 | - "SELECT s.id, u.username, s.title, s.visibility, s.updated_at, \ | ||
| 403 | - (SELECT COUNT(*) FROM snippet_files f WHERE f.snippet_id = s.id) \ | ||
| 404 | - FROM snippets s JOIN users u ON u.id = s.owner_id \ | ||
| 405 | - WHERE s.owner_id = ?1 AND (s.visibility = 'public' OR s.owner_id = ?2) \ | ||
| 406 | - ORDER BY s.updated_at DESC, s.id DESC LIMIT ?3", | ||
| 407 | - ( | ||
| 408 | - owner_id.to_string(), | ||
| 409 | - viewer_id.unwrap_or("").to_string(), | ||
| 410 | - LIST_LIMIT, | ||
| 411 | - ), | ||
| 412 | - summary_row, | ||
| 413 | - ) | ||
| 414 | - .await | ||
| 415 | - } | ||
| 416 | - | ||
| 417 | - pub async fn list_snippet_revisions(&self, snippet_id: &str) -> Result<Vec<SnippetRevision>> { | ||
| 418 | - let conn = self.read_conn().await; | ||
| 419 | - fetch_all( | ||
| 420 | - &conn, | ||
| 421 | - "SELECT r.id, u.username, r.created_at, r.files_json \ | ||
| 422 | - FROM snippet_revisions r JOIN users u ON u.id = r.author_id \ | ||
| 423 | - WHERE r.snippet_id = ?1 ORDER BY r.created_at, r.id", | ||
| 424 | - (snippet_id.to_string(),), | ||
| 425 | - |row| { | ||
| 426 | - let json = col_text(row, 3)?; | ||
| 427 | - let files = serde_json::from_str::<Vec<SnippetFile>>(&json) | ||
| 428 | - .map_err(|e| Error::Database(format!("bad snippet revision: {e}")))?; | ||
| 429 | - Ok(SnippetRevision { | ||
| 430 | - id: col_text(row, 0)?, | ||
| 431 | - author_name: col_text(row, 1)?, | ||
| 432 | - created_at: col_text(row, 2)?, | ||
| 433 | - files, | ||
| 434 | - }) | ||
| 435 | - }, | ||
| 436 | - ) | ||
| 437 | - .await | ||
| 438 | - } | ||
| 439 | -} | ||
| 440 | - | ||
| 441 | -#[cfg(test)] | ||
| 442 | -mod tests { | ||
| 443 | - use super::*; | ||
| 444 | - | ||
| 445 | - fn file(name: &str, content: &str) -> SnippetFile { | ||
| 446 | - SnippetFile { | ||
| 447 | - name: name.into(), | ||
| 448 | - content: content.into(), | ||
| 449 | - } | ||
| 450 | - } | ||
| 451 | - | ||
| 452 | - #[test] | ||
| 453 | - fn file_names_are_restricted() { | ||
| 454 | - assert!(validate_file_name("main.rs").is_ok()); | ||
| 455 | - assert!(validate_file_name("my-file_2.md").is_ok()); | ||
| 456 | - assert!(validate_file_name("").is_err()); | ||
| 457 | - assert!(validate_file_name(".hidden").is_err()); | ||
| 458 | - assert!(validate_file_name("a/b").is_err()); | ||
| 459 | - assert!(validate_file_name("a b").is_err()); | ||
| 460 | - assert!(validate_file_name(&"x".repeat(101)).is_err()); | ||
| 461 | - } | ||
| 462 | - | ||
| 463 | - #[test] | ||
| 464 | - fn file_sets_are_checked() { | ||
| 465 | - assert!(validate_files(&[]).is_err()); | ||
| 466 | - assert!(validate_files(&[file("a", "1"), file("a", "2")]).is_err()); | ||
| 467 | - assert!(validate_files(&[file("a", "x\0y")]).is_err()); | ||
| 468 | - let many: Vec<SnippetFile> = (0..=MAX_FILES) | ||
| 469 | - .map(|i| file(&format!("f{i}"), "x")) | ||
| 470 | - .collect(); | ||
| 471 | - assert!(validate_files(&many).is_err()); | ||
| 472 | - let big = "x".repeat(MAX_TOTAL_BYTES / 2 + 1); | ||
| 473 | - assert!(validate_files(&[file("a", &big), file("b", &big)]).is_err()); | ||
| 474 | - assert!(validate_files(&[file("a", "one"), file("b", "two")]).is_ok()); | ||
| 475 | - } | ||
| 476 | - | ||
| 477 | - #[test] | ||
| 478 | - fn visibility_names_round_trip() { | ||
| 479 | - for v in SnippetVisibility::ALL { | ||
| 480 | - assert_eq!(v.as_str().parse::<SnippetVisibility>().ok(), Some(v)); | ||
| 481 | - } | ||
| 482 | - assert!("secret".parse::<SnippetVisibility>().is_err()); | ||
| 483 | - } | ||
| 484 | - | ||
| 485 | - #[tokio::test] | ||
| 486 | - async fn create_edit_revisions_and_delete() { | ||
| 487 | - let dir = tempfile::tempdir().expect("tempdir"); | ||
| 488 | - let store = Store::open(&dir.path().join("forge.db")) | ||
| 489 | - .await | ||
| 490 | - .expect("open"); | ||
| 491 | - let tahinli = store | ||
| 492 | - .create_user("tahinli", None, "unused", false) | ||
| 493 | - .await | ||
| 494 | - .expect("tahinli"); | ||
| 495 | - let bob = store | ||
| 496 | - .create_user("bob", None, "unused", false) | ||
| 497 | - .await | ||
| 498 | - .expect("bob"); | ||
| 499 | - | ||
| 500 | - let snippet = store | ||
| 501 | - .create_snippet( | ||
| 502 | - &tahinli.id, | ||
| 503 | - " Greeting ", | ||
| 504 | - "", | ||
| 505 | - SnippetVisibility::Private, | ||
| 506 | - &[file("hi.txt", "hello\n")], | ||
| 507 | - ) | ||
| 508 | - .await | ||
| 509 | - .expect("create"); | ||
| 510 | - assert_eq!(snippet.title, "Greeting"); | ||
| 511 | - assert_eq!(snippet.owner_name, "tahinli"); | ||
| 512 | - assert!(snippet.is_visible_to(Some(&tahinli.id))); | ||
| 513 | - assert!(!snippet.is_visible_to(Some(&bob.id))); | ||
| 514 | - assert!(!snippet.is_visible_to(None)); | ||
| 515 | - | ||
| 516 | - let listed = store.list_snippets(Some(&bob.id)).await.expect("list"); | ||
| 517 | - assert!(listed.is_empty(), "private snippet leaked into bob's list"); | ||
| 518 | - let listed = store.list_snippets(Some(&tahinli.id)).await.expect("list"); | ||
| 519 | - assert_eq!(listed.len(), 1); | ||
| 520 | - assert_eq!(listed[0].file_count, 1); | ||
| 521 | - | ||
| 522 | - let denied = store | ||
| 523 | - .update_snippet( | ||
| 524 | - &bob.id, | ||
| 525 | - &snippet.id, | ||
| 526 | - "x", | ||
| 527 | - "", | ||
| 528 | - SnippetVisibility::Public, | ||
| 529 | - &[file("hi.txt", "pwned")], | ||
| 530 | - ) | ||
| 531 | - .await; | ||
| 532 | - assert!(matches!(denied, Err(Error::NotFound))); | ||
| 533 | - | ||
| 534 | - let saved = store | ||
| 535 | - .update_snippet( | ||
| 536 | - &tahinli.id, | ||
| 537 | - &snippet.id, | ||
| 538 | - "Greeting", | ||
| 539 | - "now public", | ||
| 540 | - SnippetVisibility::Public, | ||
| 541 | - &[file("hi.txt", "hello\n"), file("bye.txt", "bye\n")], | ||
| 542 | - ) | ||
| 543 | - .await | ||
| 544 | - .expect("update"); | ||
| 545 | - assert_eq!(saved.files.len(), 2); | ||
| 546 | - assert_eq!(saved.description, "now public"); | ||
| 547 | - | ||
| 548 | - let revisions = store | ||
| 549 | - .list_snippet_revisions(&snippet.id) | ||
| 550 | - .await | ||
| 551 | - .expect("revisions"); | ||
| 552 | - assert_eq!(revisions.len(), 2); | ||
| 553 | - assert_eq!(revisions[0].files.len(), 1); | ||
| 554 | - assert_eq!(revisions[1].files.len(), 2); | ||
| 555 | - assert_eq!(revisions[1].author_name, "tahinli"); | ||
| 556 | - | ||
| 557 | - let public = store.list_snippets(None).await.expect("list"); | ||
| 558 | - assert_eq!(public.len(), 1); | ||
| 559 | - | ||
| 560 | - assert!( | ||
| 561 | - !store | ||
| 562 | - .delete_snippet(&bob.id, &snippet.id) | ||
| 563 | - .await | ||
| 564 | - .expect("delete") | ||
| 565 | - ); | ||
| 566 | - assert!( | ||
| 567 | - store | ||
| 568 | - .delete_snippet(&tahinli.id, &snippet.id) | ||
| 569 | - .await | ||
| 570 | - .expect("delete") | ||
| 571 | - ); | ||
| 572 | - assert!(store.get_snippet(&snippet.id).await.expect("get").is_none()); | ||
| 573 | - } | ||
| 574 | -} | ||
crates/forge-e2e/tests/e2e/community_i18n_e2e.rsdeleted+0 -43
| @@ -1,43 +0,0 @@ | |||
| 1 | -use std::time::Duration; | ||
| 2 | - | ||
| 3 | -use crate::common::boot_forge; | ||
| 4 | -use reqwest::header::ACCEPT_LANGUAGE; | ||
| 5 | - | ||
| 6 | -#[tokio::test] | ||
| 7 | -async fn snippets_page_follows_the_browser_language() { | ||
| 8 | - let root = tempfile::tempdir().expect("temp dir"); | ||
| 9 | - let dir = root.path().to_path_buf(); | ||
| 10 | - let (_server, ports) = boot_forge(&dir, "", &[&["create-user", "tahinli"]]).await; | ||
| 11 | - | ||
| 12 | - let client = reqwest::Client::builder() | ||
| 13 | - .timeout(Duration::from_secs(60)) | ||
| 14 | - .build() | ||
| 15 | - .expect("http client"); | ||
| 16 | - let base = format!("http://127.0.0.1:{}", ports.http); | ||
| 17 | - | ||
| 18 | - let turkish = client | ||
| 19 | - .get(format!("{base}/snippets")) | ||
| 20 | - .header(ACCEPT_LANGUAGE, "tr-TR,tr;q=0.9,en;q=0.8") | ||
| 21 | - .send() | ||
| 22 | - .await | ||
| 23 | - .expect("GET /snippets (tr)"); | ||
| 24 | - assert_eq!(turkish.status().as_u16(), 200); | ||
| 25 | - let body = turkish.text().await.expect("read body"); | ||
| 26 | - assert!(body.contains("<html lang=\"tr\""), "html lang is tr"); | ||
| 27 | - assert!(body.contains("<h1>Parçacıklar</h1>"), "Turkish heading"); | ||
| 28 | - assert!( | ||
| 29 | - body.contains("Gösterilecek parçacık yok."), | ||
| 30 | - "Turkish empty state" | ||
| 31 | - ); | ||
| 32 | - assert!(!body.contains("No snippets to show."), "no English left"); | ||
| 33 | - | ||
| 34 | - let english = client | ||
| 35 | - .get(format!("{base}/snippets")) | ||
| 36 | - .header(ACCEPT_LANGUAGE, "en-US,en;q=0.9") | ||
| 37 | - .send() | ||
| 38 | - .await | ||
| 39 | - .expect("GET /snippets (en)"); | ||
| 40 | - let body = english.text().await.expect("read body"); | ||
| 41 | - assert!(body.contains("<h1>Snippets</h1>"), "English heading"); | ||
| 42 | - assert!(body.contains("No snippets to show."), "English empty state"); | ||
| 43 | -} | ||
crates/forge-e2e/tests/e2e/main.rsmodified+0 -2
| @@ -4,7 +4,6 @@ mod account_mail_e2e; | |||
| 4 | mod branch_protection_e2e; | 4 | mod branch_protection_e2e; |
| 5 | mod browse_e2e; | 5 | mod browse_e2e; |
| 6 | mod ci_e2e; | 6 | mod ci_e2e; |
| 7 | -mod community_i18n_e2e; | ||
| 8 | mod git_e2e; | 7 | mod git_e2e; |
| 9 | mod i18n_e2e; | 8 | mod i18n_e2e; |
| 10 | mod issue_close_e2e; | 9 | mod issue_close_e2e; |
| @@ -21,7 +20,6 @@ mod repo_settings_e2e; | |||
| 21 | mod repo_transfer_e2e; | 20 | mod repo_transfer_e2e; |
| 22 | mod runner_subcommand; | 21 | mod runner_subcommand; |
| 23 | mod section_nav_e2e; | 22 | mod section_nav_e2e; |
| 24 | -mod snippets_e2e; | ||
| 25 | mod stars_e2e; | 23 | mod stars_e2e; |
| 26 | mod ui_prefs_e2e; | 24 | mod ui_prefs_e2e; |
| 27 | mod user_delete_e2e; | 25 | mod user_delete_e2e; |
crates/forge-e2e/tests/e2e/snippets_e2e.rsdeleted+0 -431
| @@ -1,431 +0,0 @@ | |||
| 1 | -use crate::common::{Http, PW, Server, boot_forge, csrf_for, login, next_changed}; | ||
| 2 | -use std::path::PathBuf; | ||
| 3 | - | ||
| 4 | -use reqwest::header::{CONTENT_TYPE, LOCATION}; | ||
| 5 | - | ||
| 6 | -fn path_of(url: &str) -> String { | ||
| 7 | - let rest = url.split_once("//").map_or(url, |(_, r)| r); | ||
| 8 | - match rest.find('/') { | ||
| 9 | - Some(i) => rest[i..].to_owned(), | ||
| 10 | - None => "/".to_owned(), | ||
| 11 | - } | ||
| 12 | -} | ||
| 13 | - | ||
| 14 | -fn link_href(body: &str, text: &str) -> String { | ||
| 15 | - let doc = scraper::Html::parse_document(body); | ||
| 16 | - let selector = scraper::Selector::parse("a").expect("selector"); | ||
| 17 | - doc.select(&selector) | ||
| 18 | - .find(|a| a.text().collect::<String>().trim() == text) | ||
| 19 | - .and_then(|a| a.value().attr("href")) | ||
| 20 | - .unwrap_or_else(|| panic!("no link {text:?} on page")) | ||
| 21 | - .to_owned() | ||
| 22 | -} | ||
| 23 | - | ||
| 24 | -struct Env { | ||
| 25 | - _root: tempfile::TempDir, | ||
| 26 | - _server: Server, | ||
| 27 | - app: Http, | ||
| 28 | - content: Http, | ||
| 29 | -} | ||
| 30 | - | ||
| 31 | -async fn start() -> Env { | ||
| 32 | - let root = tempfile::tempdir().expect("temp dir"); | ||
| 33 | - let dir: PathBuf = root.path().to_path_buf(); | ||
| 34 | - let (server, ports) = boot_forge( | ||
| 35 | - &dir, | ||
| 36 | - "", | ||
| 37 | - &[&["create-user", "tahinli"], &["create-user", "bob"]], | ||
| 38 | - ) | ||
| 39 | - .await; | ||
| 40 | - Env { | ||
| 41 | - _root: root, | ||
| 42 | - _server: server, | ||
| 43 | - app: Http::with_base(format!("http://127.0.0.1:{}", ports.http)), | ||
| 44 | - content: Http::with_base(format!("http://127.0.0.1:{}", ports.content)), | ||
| 45 | - } | ||
| 46 | -} | ||
| 47 | - | ||
| 48 | -async fn create( | ||
| 49 | - http: &Http, | ||
| 50 | - cookie: &str, | ||
| 51 | - title: &str, | ||
| 52 | - visibility: &str, | ||
| 53 | - files: &[(&str, &str)], | ||
| 54 | -) -> String { | ||
| 55 | - let csrf = csrf_for(http, "/snippets/new", cookie).await; | ||
| 56 | - let mut form: Vec<(String, String)> = vec![ | ||
| 57 | - ("csrf".into(), csrf), | ||
| 58 | - ("title".into(), title.into()), | ||
| 59 | - ("description".into(), String::new()), | ||
| 60 | - ("visibility".into(), visibility.into()), | ||
| 61 | - ]; | ||
| 62 | - for (i, (name, content)) in files.iter().enumerate() { | ||
| 63 | - form.push((format!("name_{i}"), (*name).into())); | ||
| 64 | - form.push((format!("content_{i}"), (*content).into())); | ||
| 65 | - } | ||
| 66 | - let borrowed: Vec<(&str, &str)> = form.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect(); | ||
| 67 | - let res = http | ||
| 68 | - .post_form("/snippets/new", &borrowed, Some(cookie)) | ||
| 69 | - .await; | ||
| 70 | - assert_eq!(res.status, 303, "create snippet: {}", res.body); | ||
| 71 | - let location = res.header(LOCATION).expect("location"); | ||
| 72 | - location | ||
| 73 | - .strip_prefix("/snippets/") | ||
| 74 | - .expect("redirect to the snippet") | ||
| 75 | - .to_owned() | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | -#[tokio::test] | ||
| 79 | -async fn snippet_streams_follow_writes() { | ||
| 80 | - let env = start().await; | ||
| 81 | - let tahinli = login(&env.app, "tahinli", PW).await; | ||
| 82 | - let bob = login(&env.app, "bob", PW).await; | ||
| 83 | - | ||
| 84 | - let id = create( | ||
| 85 | - &env.app, | ||
| 86 | - &tahinli, | ||
| 87 | - "Live", | ||
| 88 | - "public", | ||
| 89 | - &[("live.txt", "one\n")], | ||
| 90 | - ) | ||
| 91 | - .await; | ||
| 92 | - let item = format!("/snippets/{id}/events"); | ||
| 93 | - | ||
| 94 | - let listing = env.app.get("/snippets", Some(&tahinli)).await; | ||
| 95 | - assert!( | ||
| 96 | - listing.body.contains(r#"data-live="/snippets/events""#), | ||
| 97 | - "list follows its stream" | ||
| 98 | - ); | ||
| 99 | - let page = env | ||
| 100 | - .app | ||
| 101 | - .get(&format!("/snippets/{id}"), Some(&tahinli)) | ||
| 102 | - .await; | ||
| 103 | - assert!( | ||
| 104 | - page.body.contains(&format!(r#"data-live="{item}""#)), | ||
| 105 | - "snippet page follows its stream" | ||
| 106 | - ); | ||
| 107 | - | ||
| 108 | - let mut list_events = env.app.stream("/snippets/events", Some(&tahinli)).await; | ||
| 109 | - assert_eq!(list_events.status().as_u16(), 200, "list stream"); | ||
| 110 | - let mut item_events = env.app.stream(&item, Some(&tahinli)).await; | ||
| 111 | - assert_eq!(item_events.status().as_u16(), 200, "snippet stream"); | ||
| 112 | - | ||
| 113 | - let edit_path = format!("/snippets/{id}/edit"); | ||
| 114 | - let csrf = csrf_for(&env.app, &edit_path, &tahinli).await; | ||
| 115 | - let saved = env | ||
| 116 | - .app | ||
| 117 | - .post_form( | ||
| 118 | - &edit_path, | ||
| 119 | - &[ | ||
| 120 | - ("csrf", &csrf), | ||
| 121 | - ("title", "Live v2"), | ||
| 122 | - ("description", ""), | ||
| 123 | - ("visibility", "public"), | ||
| 124 | - ("name_0", "live.txt"), | ||
| 125 | - ("content_0", "two\n"), | ||
| 126 | - ], | ||
| 127 | - Some(&tahinli), | ||
| 128 | - ) | ||
| 129 | - .await; | ||
| 130 | - assert_eq!(saved.status, 303, "edit: {}", saved.body); | ||
| 131 | - next_changed(&mut list_events, "an edit").await; | ||
| 132 | - next_changed(&mut item_events, "an edit").await; | ||
| 133 | - | ||
| 134 | - let other = create( | ||
| 135 | - &env.app, | ||
| 136 | - &tahinli, | ||
| 137 | - "Second", | ||
| 138 | - "public", | ||
| 139 | - &[("two.txt", "2\n")], | ||
| 140 | - ) | ||
| 141 | - .await; | ||
| 142 | - next_changed(&mut list_events, "a create").await; | ||
| 143 | - | ||
| 144 | - let csrf = csrf_for(&env.app, &format!("/snippets/{other}"), &tahinli).await; | ||
| 145 | - let deleted = env | ||
| 146 | - .app | ||
| 147 | - .post_form( | ||
| 148 | - &format!("/snippets/{other}/delete"), | ||
| 149 | - &[("csrf", &csrf)], | ||
| 150 | - Some(&tahinli), | ||
| 151 | - ) | ||
| 152 | - .await; | ||
| 153 | - assert_eq!(deleted.status, 303, "delete: {}", deleted.body); | ||
| 154 | - next_changed(&mut list_events, "a delete").await; | ||
| 155 | - | ||
| 156 | - let secret = create( | ||
| 157 | - &env.app, | ||
| 158 | - &tahinli, | ||
| 159 | - "Secret", | ||
| 160 | - "private", | ||
| 161 | - &[("s.txt", "shh\n")], | ||
| 162 | - ) | ||
| 163 | - .await; | ||
| 164 | - let secret_item = format!("/snippets/{secret}/events"); | ||
| 165 | - assert_eq!( | ||
| 166 | - env.app | ||
| 167 | - .stream(&secret_item, Some(&tahinli)) | ||
| 168 | - .await | ||
| 169 | - .status() | ||
| 170 | - .as_u16(), | ||
| 171 | - 200, | ||
| 172 | - "owner opens the private stream" | ||
| 173 | - ); | ||
| 174 | - assert_eq!( | ||
| 175 | - env.app | ||
| 176 | - .stream(&secret_item, Some(&bob)) | ||
| 177 | - .await | ||
| 178 | - .status() | ||
| 179 | - .as_u16(), | ||
| 180 | - 404, | ||
| 181 | - "others get 404" | ||
| 182 | - ); | ||
| 183 | - assert_eq!( | ||
| 184 | - env.app.stream(&secret_item, None).await.status().as_u16(), | ||
| 185 | - 404, | ||
| 186 | - "anonymous gets 404" | ||
| 187 | - ); | ||
| 188 | -} | ||
| 189 | - | ||
| 190 | -#[tokio::test] | ||
| 191 | -async fn create_edit_and_revisions() { | ||
| 192 | - let env = start().await; | ||
| 193 | - let tahinli = login(&env.app, "tahinli", PW).await; | ||
| 194 | - let id = create( | ||
| 195 | - &env.app, | ||
| 196 | - &tahinli, | ||
| 197 | - "Greeting", | ||
| 198 | - "public", | ||
| 199 | - &[("hello.txt", "hello\n")], | ||
| 200 | - ) | ||
| 201 | - .await; | ||
| 202 | - | ||
| 203 | - let view = env.app.get(&format!("/snippets/{id}"), None).await; | ||
| 204 | - assert_eq!(view.status, 200); | ||
| 205 | - assert!(view.body.contains("hello"), "file contents are shown"); | ||
| 206 | - | ||
| 207 | - let edit_path = format!("/snippets/{id}/edit"); | ||
| 208 | - let csrf = csrf_for(&env.app, &edit_path, &tahinli).await; | ||
| 209 | - let saved = env | ||
| 210 | - .app | ||
| 211 | - .post_form( | ||
| 212 | - &edit_path, | ||
| 213 | - &[ | ||
| 214 | - ("csrf", &csrf), | ||
| 215 | - ("title", "Greeting v2"), | ||
| 216 | - ("description", "two files now"), | ||
| 217 | - ("visibility", "public"), | ||
| 218 | - ("name_0", "hello.txt"), | ||
| 219 | - ("content_0", "hello v2\n"), | ||
| 220 | - ("name_1", "notes.md"), | ||
| 221 | - ("content_1", "# Notes\n\nSome **bold** text.\n"), | ||
| 222 | - ], | ||
| 223 | - Some(&tahinli), | ||
| 224 | - ) | ||
| 225 | - .await; | ||
| 226 | - assert_eq!(saved.status, 303, "save edit: {}", saved.body); | ||
| 227 | - | ||
| 228 | - let view = env.app.get(&format!("/snippets/{id}"), None).await; | ||
| 229 | - assert!(view.body.contains("Greeting v2")); | ||
| 230 | - assert!(view.body.contains("<strong>"), "markdown file is rendered"); | ||
| 231 | - assert!( | ||
| 232 | - view.body.contains("<strong>bold</strong>"), | ||
| 233 | - "markdown bold renders" | ||
| 234 | - ); | ||
| 235 | - | ||
| 236 | - let history = env | ||
| 237 | - .app | ||
| 238 | - .get(&format!("/snippets/{id}/revisions"), Some(&tahinli)) | ||
| 239 | - .await; | ||
| 240 | - assert_eq!(history.status, 200); | ||
| 241 | - assert!( | ||
| 242 | - history.body.contains("Revision 2"), | ||
| 243 | - "second revision listed" | ||
| 244 | - ); | ||
| 245 | - assert!(history.body.contains("Revision 1"), "first revision listed"); | ||
| 246 | -} | ||
| 247 | - | ||
| 248 | -#[tokio::test] | ||
| 249 | -async fn private_snippet_is_hidden_from_others() { | ||
| 250 | - let env = start().await; | ||
| 251 | - let tahinli = login(&env.app, "tahinli", PW).await; | ||
| 252 | - let bob = login(&env.app, "bob", PW).await; | ||
| 253 | - let id = create( | ||
| 254 | - &env.app, | ||
| 255 | - &tahinli, | ||
| 256 | - "Secret", | ||
| 257 | - "private", | ||
| 258 | - &[("s.txt", "shh\n")], | ||
| 259 | - ) | ||
| 260 | - .await; | ||
| 261 | - | ||
| 262 | - let owner = env | ||
| 263 | - .app | ||
| 264 | - .get(&format!("/snippets/{id}"), Some(&tahinli)) | ||
| 265 | - .await; | ||
| 266 | - assert_eq!(owner.status, 200, "owner can read"); | ||
| 267 | - assert_eq!( | ||
| 268 | - env.app | ||
| 269 | - .get(&format!("/snippets/{id}"), Some(&bob)) | ||
| 270 | - .await | ||
| 271 | - .status, | ||
| 272 | - 404 | ||
| 273 | - ); | ||
| 274 | - assert_eq!( | ||
| 275 | - env.app.get(&format!("/snippets/{id}"), None).await.status, | ||
| 276 | - 404 | ||
| 277 | - ); | ||
| 278 | - | ||
| 279 | - let list = env.app.get("/snippets", Some(&bob)).await; | ||
| 280 | - assert!( | ||
| 281 | - !list.body.contains("Secret"), | ||
| 282 | - "private snippet is not listed for bob" | ||
| 283 | - ); | ||
| 284 | - | ||
| 285 | - let page = env | ||
| 286 | - .app | ||
| 287 | - .get(&format!("/snippets/{id}/edit"), Some(&bob)) | ||
| 288 | - .await; | ||
| 289 | - assert_eq!(page.status, 404, "bob cannot open the editor"); | ||
| 290 | - let bob_csrf = csrf_for(&env.app, "/snippets/new", &bob).await; | ||
| 291 | - let res = env | ||
| 292 | - .app | ||
| 293 | - .post_form( | ||
| 294 | - &format!("/snippets/{id}/delete"), | ||
| 295 | - &[("csrf", &bob_csrf)], | ||
| 296 | - Some(&bob), | ||
| 297 | - ) | ||
| 298 | - .await; | ||
| 299 | - assert_eq!(res.status, 404, "bob cannot delete"); | ||
| 300 | - assert_eq!( | ||
| 301 | - env.app | ||
| 302 | - .get(&format!("/snippets/{id}"), Some(&tahinli)) | ||
| 303 | - .await | ||
| 304 | - .status, | ||
| 305 | - 200 | ||
| 306 | - ); | ||
| 307 | -} | ||
| 308 | - | ||
| 309 | -#[tokio::test] | ||
| 310 | -async fn raw_files_use_the_user_content_origin_and_private_tokens() { | ||
| 311 | - let env = start().await; | ||
| 312 | - let tahinli = login(&env.app, "tahinli", PW).await; | ||
| 313 | - let public = create( | ||
| 314 | - &env.app, | ||
| 315 | - &tahinli, | ||
| 316 | - "Pub", | ||
| 317 | - "public", | ||
| 318 | - &[("notes.md", "# Hi\n")], | ||
| 319 | - ) | ||
| 320 | - .await; | ||
| 321 | - let private = create( | ||
| 322 | - &env.app, | ||
| 323 | - &tahinli, | ||
| 324 | - "Priv", | ||
| 325 | - "private", | ||
| 326 | - &[("data.json", "{\"a\":1}\n")], | ||
| 327 | - ) | ||
| 328 | - .await; | ||
| 329 | - | ||
| 330 | - let page = env.app.get(&format!("/snippets/{public}"), None).await; | ||
| 331 | - let raw = link_href(&page.body, "Raw"); | ||
| 332 | - let res = env.content.get(&path_of(&raw), None).await; | ||
| 333 | - assert_eq!(res.status, 200, "public raw: {raw}"); | ||
| 334 | - assert!( | ||
| 335 | - res.header(CONTENT_TYPE) | ||
| 336 | - .unwrap_or_default() | ||
| 337 | - .starts_with("text/markdown"), | ||
| 338 | - "markdown content type" | ||
| 339 | - ); | ||
| 340 | - assert_eq!(res.body, "# Hi\n"); | ||
| 341 | - | ||
| 342 | - let page = env | ||
| 343 | - .app | ||
| 344 | - .get(&format!("/snippets/{private}"), Some(&tahinli)) | ||
| 345 | - .await; | ||
| 346 | - let raw = link_href(&page.body, "Raw"); | ||
| 347 | - assert!(raw.contains("token="), "private raw link is signed: {raw}"); | ||
| 348 | - let res = env.content.get(&path_of(&raw), None).await; | ||
| 349 | - assert_eq!(res.status, 200, "private raw with token"); | ||
| 350 | - assert!( | ||
| 351 | - res.header(CONTENT_TYPE) | ||
| 352 | - .unwrap_or_default() | ||
| 353 | - .starts_with("application/json") | ||
| 354 | - ); | ||
| 355 | - let bare = raw.split('?').next().unwrap_or_default().to_owned(); | ||
| 356 | - assert_eq!( | ||
| 357 | - env.content.get(&path_of(&bare), None).await.status, | ||
| 358 | - 404, | ||
| 359 | - "no token, no file" | ||
| 360 | - ); | ||
| 361 | - | ||
| 362 | - let missing = format!("/-/snippets/{public}/nope.txt"); | ||
| 363 | - assert_eq!(env.content.get(&missing, None).await.status, 404); | ||
| 364 | -} | ||
| 365 | - | ||
| 366 | -#[tokio::test] | ||
| 367 | -async fn unlisted_is_by_link_only_and_delete_removes_it() { | ||
| 368 | - let env = start().await; | ||
| 369 | - let tahinli = login(&env.app, "tahinli", PW).await; | ||
| 370 | - let id = create( | ||
| 371 | - &env.app, | ||
| 372 | - &tahinli, | ||
| 373 | - "Link only", | ||
| 374 | - "unlisted", | ||
| 375 | - &[("a.txt", "x\n")], | ||
| 376 | - ) | ||
| 377 | - .await; | ||
| 378 | - | ||
| 379 | - let list = env.app.get("/snippets", None).await; | ||
| 380 | - assert!(!list.body.contains("Link only"), "unlisted is not listed"); | ||
| 381 | - assert_eq!( | ||
| 382 | - env.app.get(&format!("/snippets/{id}"), None).await.status, | ||
| 383 | - 200 | ||
| 384 | - ); | ||
| 385 | - | ||
| 386 | - let csrf = csrf_for(&env.app, &format!("/snippets/{id}"), &tahinli).await; | ||
| 387 | - let res = env | ||
| 388 | - .app | ||
| 389 | - .post_form( | ||
| 390 | - &format!("/snippets/{id}/delete"), | ||
| 391 | - &[("csrf", &csrf)], | ||
| 392 | - Some(&tahinli), | ||
| 393 | - ) | ||
| 394 | - .await; | ||
| 395 | - assert_eq!(res.status, 303, "delete: {}", res.body); | ||
| 396 | - assert_eq!( | ||
| 397 | - env.app.get(&format!("/snippets/{id}"), None).await.status, | ||
| 398 | - 404 | ||
| 399 | - ); | ||
| 400 | -} | ||
| 401 | - | ||
| 402 | -#[tokio::test] | ||
| 403 | -async fn bad_input_redisplays_the_form_with_an_error() { | ||
| 404 | - let env = start().await; | ||
| 405 | - let tahinli = login(&env.app, "tahinli", PW).await; | ||
| 406 | - let csrf = csrf_for(&env.app, "/snippets/new", &tahinli).await; | ||
| 407 | - let res = env | ||
| 408 | - .app | ||
| 409 | - .post_form( | ||
| 410 | - "/snippets/new", | ||
| 411 | - &[ | ||
| 412 | - ("csrf", &csrf), | ||
| 413 | - ("title", "Bad"), | ||
| 414 | - ("visibility", "public"), | ||
| 415 | - ("name_0", "a/b.txt"), | ||
| 416 | - ("content_0", "x"), | ||
| 417 | - ], | ||
| 418 | - Some(&tahinli), | ||
| 419 | - ) | ||
| 420 | - .await; | ||
| 421 | - assert_eq!(res.status, 200, "invalid input is not a redirect"); | ||
| 422 | - assert!( | ||
| 423 | - res.body.contains("may only use"), | ||
| 424 | - "error shown: {}", | ||
| 425 | - res.body | ||
| 426 | - ); | ||
| 427 | - assert!( | ||
| 428 | - res.body.contains("a/b.txt") || res.body.contains("Bad"), | ||
| 429 | - "input kept" | ||
| 430 | - ); | ||
| 431 | -} | ||
crates/forge-web-account/src/lib.rsmodified+1 -2
| @@ -4,8 +4,7 @@ | |||
| 4 | pub(crate) use forge_web_app::test_support; | 4 | pub(crate) use forge_web_app::test_support; |
| 5 | pub(crate) use forge_web_app::{ | 5 | pub(crate) use forge_web_app::{ |
| 6 | accent, alerts, api, audit, auth, backup, client_ip, custom_colour, exporter, i18n, importer, | 6 | accent, alerts, api, audit, auth, backup, client_ip, custom_colour, exporter, i18n, importer, |
| 7 | - live, mail, mirrors, raw, render, self_update, signatures, state, theme, throttle, views, | 7 | + live, mail, mirrors, render, self_update, signatures, state, theme, throttle, views, webhooks, |
| 8 | - webhooks, | ||
| 9 | }; | 8 | }; |
| 10 | #[cfg(test)] | 9 | #[cfg(test)] |
| 11 | pub(crate) use forge_web_app::{blobs, release_ops, replication}; | 10 | pub(crate) use forge_web_app::{blobs, release_ops, replication}; |
crates/forge-web-account/src/pages/admin_user_detail.rsmodified+1 -13
| @@ -52,7 +52,6 @@ struct Detail { | |||
| 52 | ssh_keys: usize, | 52 | ssh_keys: usize, |
| 53 | gpg_keys: usize, | 53 | gpg_keys: usize, |
| 54 | tokens: usize, | 54 | tokens: usize, |
| 55 | - snippets: usize, | ||
| 56 | orgs: Vec<(String, String, OrgMemberRole)>, | 55 | orgs: Vec<(String, String, OrgMemberRole)>, |
| 57 | } | 56 | } |
| 58 | 57 | ||
| @@ -118,10 +117,6 @@ async fn load(cx: &Cx) -> Result<Detail> { | |||
| 118 | ssh_keys: store.list_ssh_keys(&target.id).await?.len(), | 117 | ssh_keys: store.list_ssh_keys(&target.id).await?.len(), |
| 119 | gpg_keys: store.list_gpg_keys(&target.id).await?.len(), | 118 | gpg_keys: store.list_gpg_keys(&target.id).await?.len(), |
| 120 | tokens: store.list_tokens(&target.id).await?.len(), | 119 | tokens: store.list_tokens(&target.id).await?.len(), |
| 121 | - snippets: store | ||
| 122 | - .list_owner_snippets(&target.id, Some(&target.id)) | ||
| 123 | - .await? | ||
| 124 | - .len(), | ||
| 125 | orgs, | 120 | orgs, |
| 126 | facts: store.account_facts(&target.id).await?, | 121 | facts: store.account_facts(&target.id).await?, |
| 127 | suspension: store.suspension(&target.id).await?, | 122 | suspension: store.suspension(&target.id).await?, |
| @@ -175,7 +170,6 @@ async fn detail_body( | |||
| 175 | ssh_keys, | 170 | ssh_keys, |
| 176 | gpg_keys, | 171 | gpg_keys, |
| 177 | tokens, | 172 | tokens, |
| 178 | - snippets, | ||
| 179 | orgs, | 173 | orgs, |
| 180 | } = detail; | 174 | } = detail; |
| 181 | let base = format!("/admin/users/{}", enc(&target.id)); | 175 | let base = format!("/admin/users/{}", enc(&target.id)); |
| @@ -241,7 +235,6 @@ async fn detail_body( | |||
| 241 | let live = format!("{base}/events"); | 235 | let live = format!("{base}/events"); |
| 242 | let profile = format!("/{}", enc(&target.username)); | 236 | let profile = format!("/{}", enc(&target.username)); |
| 243 | let repos_href = format!("/{}?tab=repositories", enc(&target.username)); | 237 | let repos_href = format!("/{}?tab=repositories", enc(&target.username)); |
| 244 | - let snippets_href = format!("/{}?tab=snippets", enc(&target.username)); | ||
| 245 | let passkeys_question = s( | 238 | let passkeys_question = s( |
| 246 | lang, | 239 | lang, |
| 247 | "Remove every passkey of this user?", | 240 | "Remove every passkey of this user?", |
| @@ -280,11 +273,6 @@ async fn detail_body( | |||
| 280 | (_, 1) => "1 repository".to_owned(), | 273 | (_, 1) => "1 repository".to_owned(), |
| 281 | (_, n) => format!("{n} repositories"), | 274 | (_, n) => format!("{n} repositories"), |
| 282 | }; | 275 | }; |
| 283 | - let snippets_text = match (lang, snippets) { | ||
| 284 | - (Lang::Tr, n) => format!("{n} parçacık"), | ||
| 285 | - (_, 1) => "1 snippet".to_owned(), | ||
| 286 | - (_, n) => format!("{n} snippets"), | ||
| 287 | - }; | ||
| 288 | let Notice { done, error, link } = notice; | 276 | let Notice { done, error, link } = notice; |
| 289 | let mut sub = Vec::new(); | 277 | let mut sub = Vec::new(); |
| 290 | if !display_name.is_empty() { | 278 | if !display_name.is_empty() { |
| @@ -339,7 +327,7 @@ async fn detail_body( | |||
| 339 | </div> | 327 | </div> |
| 340 | <div class="line"> | 328 | <div class="line"> |
| 341 | <span class="key">(s(lang, "Owns", "Sahip olduğu"))</span> | 329 | <span class="key">(s(lang, "Owns", "Sahip olduğu"))</span> |
| 342 | - <span class="val"><a href=(repos_href.as_str())>(repos_text.as_str())</a> " · " <a href=(snippets_href.as_str())>(snippets_text.as_str())</a></span> | 330 | + <span class="val"><a href=(repos_href.as_str())>(repos_text.as_str())</a></span> |
| 343 | </div> | 331 | </div> |
| 344 | <div class="line"> | 332 | <div class="line"> |
| 345 | <span class="key">(s(lang, "Organizations", "Kuruluşlar"))</span> | 333 | <span class="key">(s(lang, "Organizations", "Kuruluşlar"))</span> |
crates/forge-web-account/src/pages/mod.rsmodified+0 -2
| @@ -56,7 +56,5 @@ pub mod settings_sessions; | |||
| 56 | pub mod settings_tokens; | 56 | pub mod settings_tokens; |
| 57 | pub mod setup; | 57 | pub mod setup; |
| 58 | pub mod shell_events; | 58 | pub mod shell_events; |
| 59 | -pub mod snippets; | ||
| 60 | -pub mod snippets_live; | ||
| 61 | pub mod theme_cookie; | 59 | pub mod theme_cookie; |
| 62 | pub mod user_prefs; | 60 | pub mod user_prefs; |
crates/forge-web-account/src/pages/profile.rsmodified+2 -60
| @@ -13,7 +13,6 @@ use topcoat::router::{page, path_param, query_params, route}; | |||
| 13 | use topcoat::view::{Unescaped, View, component, view}; | 13 | use topcoat::view::{Unescaped, View, component, view}; |
| 14 | 14 | ||
| 15 | use crate::auth::current_user; | 15 | use crate::auth::current_user; |
| 16 | -use crate::i18n::community::{self as cm, K as CK}; | ||
| 17 | use crate::i18n::misc::{self as mi, K as MK}; | 16 | use crate::i18n::misc::{self as mi, K as MK}; |
| 18 | use crate::i18n::orgs::{self as g, K}; | 17 | use crate::i18n::orgs::{self as g, K}; |
| 19 | use crate::i18n::{self, Lang}; | 18 | use crate::i18n::{self, Lang}; |
| @@ -22,7 +21,6 @@ use crate::pages::org_new::may_create_org; | |||
| 22 | use crate::pages::profile_calendar::{calendar_since, load_calendar}; | 21 | use crate::pages::profile_calendar::{calendar_since, load_calendar}; |
| 23 | use crate::pages::profile_pins::{PinOption, pin_options, pins_menu}; | 22 | use crate::pages::profile_pins::{PinOption, pin_options, pins_menu}; |
| 24 | use crate::pages::repo_settings::{notice_banner_for, take_notice}; | 23 | use crate::pages::repo_settings::{notice_banner_for, take_notice}; |
| 25 | -use crate::pages::snippets::{ListRow, list_row, snippet_rows}; | ||
| 26 | use crate::render::markdown::render_markdown; | 24 | use crate::render::markdown::render_markdown; |
| 27 | use crate::state::AppState; | 25 | use crate::state::AppState; |
| 28 | use crate::views::find::{Finder, finder_field}; | 26 | use crate::views::find::{Finder, finder_field}; |
| @@ -71,7 +69,6 @@ const SORTS: [(&str, K); 3] = [ | |||
| 71 | pub enum Tab { | 69 | pub enum Tab { |
| 72 | Overview, | 70 | Overview, |
| 73 | Repositories, | 71 | Repositories, |
| 74 | - Snippets, | ||
| 75 | Stars, | 72 | Stars, |
| 76 | Organizations, | 73 | Organizations, |
| 77 | } | 74 | } |
| @@ -80,7 +77,6 @@ impl Tab { | |||
| 80 | fn from_query(raw: Option<&str>) -> Self { | 77 | fn from_query(raw: Option<&str>) -> Self { |
| 81 | match raw { | 78 | match raw { |
| 82 | Some("repositories") => Self::Repositories, | 79 | Some("repositories") => Self::Repositories, |
| 83 | - Some("snippets") => Self::Snippets, | ||
| 84 | Some("stars") => Self::Stars, | 80 | Some("stars") => Self::Stars, |
| 85 | Some("organizations") => Self::Organizations, | 81 | Some("organizations") => Self::Organizations, |
| 86 | _ => Self::Overview, | 82 | _ => Self::Overview, |
| @@ -91,7 +87,6 @@ impl Tab { | |||
| 91 | match self { | 87 | match self { |
| 92 | Self::Overview => "overview", | 88 | Self::Overview => "overview", |
| 93 | Self::Repositories => "repositories", | 89 | Self::Repositories => "repositories", |
| 94 | - Self::Snippets => "snippets", | ||
| 95 | Self::Stars => "stars", | 90 | Self::Stars => "stars", |
| 96 | Self::Organizations => "organizations", | 91 | Self::Organizations => "organizations", |
| 97 | } | 92 | } |
| @@ -121,9 +116,7 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 121 | let lang = i18n::lang(cx, actor); | 116 | let lang = i18n::lang(cx, actor); |
| 122 | let own = !user.is_org() && actor.is_some_and(|u| u.id == user.id); | 117 | let own = !user.is_org() && actor.is_some_and(|u| u.id == user.id); |
| 123 | let tab = Tab::from_query(query.tab.as_deref()); | 118 | let tab = Tab::from_query(query.tab.as_deref()); |
| 124 | - let tab = if (user.is_org() && matches!(tab, Tab::Stars | Tab::Snippets)) | 119 | + let tab = if (user.is_org() && tab == Tab::Stars) || (tab == Tab::Organizations && !own) { |
| 125 | - || (tab == Tab::Organizations && !own) | ||
| 126 | - { | ||
| 127 | Tab::Overview | 120 | Tab::Overview |
| 128 | } else { | 121 | } else { |
| 129 | tab | 122 | tab |
| @@ -209,29 +202,6 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 209 | None | 202 | None |
| 210 | }; | 203 | }; |
| 211 | 204 | ||
| 212 | - let snippets: Vec<ListRow> = if user.is_org() { | ||
| 213 | - Vec::new() | ||
| 214 | - } else { | ||
| 215 | - state | ||
| 216 | - .store | ||
| 217 | - .list_owner_snippets(&user.id, actor.map(|u| u.id.as_str())) | ||
| 218 | - .await? | ||
| 219 | - .into_iter() | ||
| 220 | - .map(|summary| list_row(lang, summary)) | ||
| 221 | - .collect() | ||
| 222 | - }; | ||
| 223 | - let snippet_total = snippets.len() as u64; | ||
| 224 | - let (snippets, snippet_page, snippet_pages) = paginate(snippets, page, PER_PAGE); | ||
| 225 | - let snippet_pager = pager_links(snippet_page, snippet_pages, |n| { | ||
| 226 | - profile_href( | ||
| 227 | - &user.username, | ||
| 228 | - Tab::Snippets.key(), | ||
| 229 | - &Finder::default(), | ||
| 230 | - SORTS[0].0, | ||
| 231 | - n, | ||
| 232 | - ) | ||
| 233 | - }); | ||
| 234 | - | ||
| 235 | let (orgs, org_create_allowed) = match actor { | 205 | let (orgs, org_create_allowed) = match actor { |
| 236 | Some(viewer_user) if tab == Tab::Organizations => { | 206 | Some(viewer_user) if tab == Tab::Organizations => { |
| 237 | let mut cards = Vec::new(); | 207 | let mut cards = Vec::new(); |
| @@ -363,8 +333,7 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 363 | star_total: star_total, cards: cards, from_pins: from_pins, | 333 | star_total: star_total, cards: cards, from_pins: from_pins, |
| 364 | pins_menu_data: pins_menu_data, pins_error: pins_error, edit_profile: own, listing: listing, | 334 | pins_menu_data: pins_menu_data, pins_error: pins_error, edit_profile: own, listing: listing, |
| 365 | org_member: org_member, org_owner: org_owner, org_can_create: org_can_create, | 335 | org_member: org_member, org_owner: org_owner, org_can_create: org_can_create, |
| 366 | - heat: heat, snippets: snippets, snippet_total: snippet_total, | 336 | + heat: heat, orgs: orgs, org_create_allowed: org_create_allowed, |
| 367 | - snippet_paging: (snippet_page, snippet_pages, snippet_pager), orgs: orgs, org_create_allowed: org_create_allowed, | ||
| 368 | own_profile: own)) | 337 | own_profile: own)) |
| 369 | }) | 338 | }) |
| 370 | } | 339 | } |
| @@ -568,16 +537,10 @@ async fn profile_card( | |||
| 568 | org_owner: bool, | 537 | org_owner: bool, |
| 569 | org_can_create: bool, | 538 | org_can_create: bool, |
| 570 | heat: Option<(Calendar, Option<DayDetail>)>, | 539 | heat: Option<(Calendar, Option<DayDetail>)>, |
| 571 | - snippets: Vec<ListRow>, | ||
| 572 | - snippet_total: u64, | ||
| 573 | - snippet_paging: (u64, u64, (Vec<PageLink>, Option<String>, Option<String>)), | ||
| 574 | own_profile: bool, | 540 | own_profile: bool, |
| 575 | orgs: Vec<OrgCard>, | 541 | orgs: Vec<OrgCard>, |
| 576 | org_create_allowed: bool, | 542 | org_create_allowed: bool, |
| 577 | ) -> Result<impl View> { | 543 | ) -> Result<impl View> { |
| 578 | - let has_snippets = !snippets.is_empty(); | ||
| 579 | - let (snippet_page, snippet_pages, (snippet_links, snippet_prev, snippet_next)) = snippet_paging; | ||
| 580 | - let snippets_on = tab == Tab::Snippets; | ||
| 581 | let orgs_on = tab == Tab::Organizations; | 544 | let orgs_on = tab == Tab::Organizations; |
| 582 | let has_orgs = !orgs.is_empty(); | 545 | let has_orgs = !orgs.is_empty(); |
| 583 | let src = avatar_url(&user.username, avatar.as_deref()); | 546 | let src = avatar_url(&user.username, avatar.as_deref()); |
| @@ -593,7 +556,6 @@ async fn profile_card( | |||
| 593 | profile_items(lang, &user.username, is_org, own_profile, org_member); | 556 | profile_items(lang, &user.username, is_org, own_profile, org_member); |
| 594 | let tab_counts = vec![ | 557 | let tab_counts = vec![ |
| 595 | ("repositories", repo_total.to_string()), | 558 | ("repositories", repo_total.to_string()), |
| 596 | - ("snippets", snippet_total.to_string()), | ||
| 597 | ("stars", star_total.to_string()), | 559 | ("stars", star_total.to_string()), |
| 598 | ]; | 560 | ]; |
| 599 | let base = format!("/{}", enc(&user.username)); | 561 | let base = format!("/{}", enc(&user.username)); |
| @@ -656,9 +618,6 @@ async fn profile_card( | |||
| 656 | if (org_can_create || own_profile) && repos_on { | 618 | if (org_can_create || own_profile) && repos_on { |
| 657 | <a class="button" href=(new_repo_href.as_str())>(g::t(lang, K::NewRepository))</a> | 619 | <a class="button" href=(new_repo_href.as_str())>(g::t(lang, K::NewRepository))</a> |
| 658 | } | 620 | } |
| 659 | - if own_profile && snippets_on { | ||
| 660 | - <a class="button" href="/snippets/new">(cm::t(lang, CK::NewSnippet))</a> | ||
| 661 | - } | ||
| 662 | if org_create_allowed && orgs_on { | 621 | if org_create_allowed && orgs_on { |
| 663 | <a class="button" href="/org/new">(g::t(lang, K::NewOrganization))</a> | 622 | <a class="button" href="/org/new">(g::t(lang, K::NewOrganization))</a> |
| 664 | } | 623 | } |
| @@ -749,17 +708,6 @@ async fn profile_card( | |||
| 749 | pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) | 708 | pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) |
| 750 | </section> | 709 | </section> |
| 751 | } | 710 | } |
| 752 | - if snippets_on { | ||
| 753 | - <section class="sec snippet-listing"> | ||
| 754 | - <h2>(cm::t(lang, CK::Snippets))</h2> | ||
| 755 | - if has_snippets { | ||
| 756 | - snippet_rows(lang: lang, rows: snippets) | ||
| 757 | - } else { | ||
| 758 | - <p class="state">(cm::t(lang, CK::NoSnippets))</p> | ||
| 759 | - } | ||
| 760 | - pager(page: snippet_page, pages: snippet_pages, links: snippet_links, prev: snippet_prev, next: snippet_next, lang: lang) | ||
| 761 | - </section> | ||
| 762 | - } | ||
| 763 | if orgs_on { | 711 | if orgs_on { |
| 764 | <section class="sec profile-orgs"> | 712 | <section class="sec profile-orgs"> |
| 765 | <h2>(g::t(lang, K::Organizations))</h2> | 713 | <h2>(g::t(lang, K::Organizations))</h2> |
| @@ -804,14 +752,8 @@ pub async fn own_profile_tabs( | |||
| 804 | .store | 752 | .store |
| 805 | .count_visible_repos(RepoScope::StarredBy(&user.id), actor) | 753 | .count_visible_repos(RepoScope::StarredBy(&user.id), actor) |
| 806 | .await?; | 754 | .await?; |
| 807 | - let snippets = state | ||
| 808 | - .store | ||
| 809 | - .list_owner_snippets(&user.id, Some(user.id.as_str())) | ||
| 810 | - .await? | ||
| 811 | - .len(); | ||
| 812 | counts = vec![ | 755 | counts = vec![ |
| 813 | ("repositories", repos.to_string()), | 756 | ("repositories", repos.to_string()), |
| 814 | - ("snippets", snippets.to_string()), | ||
| 815 | ("stars", stars.to_string()), | 757 | ("stars", stars.to_string()), |
| 816 | ]; | 758 | ]; |
| 817 | } | 759 | } |
crates/forge-web-account/src/pages/snippets.rsdeleted+0 -912
| @@ -1,912 +0,0 @@ | |||
| 1 | -use std::collections::HashMap; | ||
| 2 | - | ||
| 3 | -use forge_core::store::snippets::{ | ||
| 4 | - MAX_FILES, MAX_TOTAL_BYTES, Snippet, SnippetFile, SnippetRevision, SnippetSummary, | ||
| 5 | - SnippetVisibility, | ||
| 6 | -}; | ||
| 7 | -use forge_core::{AuditAction, Session, User}; | ||
| 8 | -use topcoat::Result; | ||
| 9 | -use topcoat::context::{Cx, context}; | ||
| 10 | -use topcoat::router::content::Form; | ||
| 11 | -use topcoat::router::error::{SeeOther, not_found, see_other}; | ||
| 12 | -use topcoat::router::{page, path_param, route}; | ||
| 13 | -use topcoat::view::{Unescaped, View, component, view}; | ||
| 14 | - | ||
| 15 | -use crate::audit::{self, Actor, Target}; | ||
| 16 | -use crate::auth::{current_user, require_csrf, require_user}; | ||
| 17 | -use crate::i18n::community::{self as g, K}; | ||
| 18 | -use crate::i18n::{self, Lang}; | ||
| 19 | -use crate::pages::snippets_live::{bump_snippet, item_live_url, list_live_url}; | ||
| 20 | -use crate::raw::snippet_raw::snippet_raw_url; | ||
| 21 | -use crate::render::highlight::highlight_lines; | ||
| 22 | -use crate::render::markdown::render_markdown; | ||
| 23 | -use crate::state::AppState; | ||
| 24 | -use crate::views::parts::{SubPart, confirm_act, head}; | ||
| 25 | -use crate::views::{alert, empty_state, rel_time, shell, user_facing_message}; | ||
| 26 | - | ||
| 27 | -path_param!(id); | ||
| 28 | - | ||
| 29 | -struct Slot { | ||
| 30 | - number: usize, | ||
| 31 | - name: String, | ||
| 32 | - content: String, | ||
| 33 | -} | ||
| 34 | - | ||
| 35 | -#[derive(Clone, Default)] | ||
| 36 | -struct Draft { | ||
| 37 | - title: String, | ||
| 38 | - description: String, | ||
| 39 | - visibility: String, | ||
| 40 | - files: Vec<(usize, SnippetFile)>, | ||
| 41 | -} | ||
| 42 | - | ||
| 43 | -impl Draft { | ||
| 44 | - fn blank() -> Self { | ||
| 45 | - Draft { | ||
| 46 | - visibility: SnippetVisibility::Private.as_str().to_owned(), | ||
| 47 | - ..Draft::default() | ||
| 48 | - } | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - fn from_snippet(snippet: &Snippet) -> Self { | ||
| 52 | - Draft { | ||
| 53 | - title: snippet.title.clone(), | ||
| 54 | - description: snippet.description.clone(), | ||
| 55 | - visibility: snippet.visibility.as_str().to_owned(), | ||
| 56 | - files: snippet.files.iter().cloned().enumerate().collect(), | ||
| 57 | - } | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - fn from_form(form: &HashMap<String, String>) -> Self { | ||
| 61 | - let field = |key: String| form.get(&key).cloned().unwrap_or_default(); | ||
| 62 | - let mut files = Vec::new(); | ||
| 63 | - for number in 0..MAX_FILES { | ||
| 64 | - if !form.contains_key(&format!("name_{number}")) { | ||
| 65 | - continue; | ||
| 66 | - } | ||
| 67 | - let name = field(format!("name_{number}")).trim().to_owned(); | ||
| 68 | - let content = field(format!("content_{number}")).replace("\r\n", "\n"); | ||
| 69 | - files.push((number, SnippetFile { name, content })); | ||
| 70 | - } | ||
| 71 | - Draft { | ||
| 72 | - title: field("title".into()), | ||
| 73 | - description: field("description".into()), | ||
| 74 | - visibility: field("visibility".into()), | ||
| 75 | - files, | ||
| 76 | - } | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - fn saved_files(&self) -> Vec<SnippetFile> { | ||
| 80 | - self.files | ||
| 81 | - .iter() | ||
| 82 | - .map(|(_, file)| file) | ||
| 83 | - .filter(|file| !(file.name.is_empty() && file.content.trim().is_empty())) | ||
| 84 | - .cloned() | ||
| 85 | - .collect() | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - fn remove(&mut self, number: usize) { | ||
| 89 | - self.files.retain(|(n, _)| *n != number); | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - fn position(&self, number: usize) -> Option<usize> { | ||
| 93 | - self.files.iter().position(|(n, _)| *n == number) | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - fn add_blank(&mut self) { | ||
| 97 | - if self.files.len() >= MAX_FILES { | ||
| 98 | - return; | ||
| 99 | - } | ||
| 100 | - let free = (0..MAX_FILES).find(|n| self.files.iter().all(|(m, _)| m != n)); | ||
| 101 | - if let Some(number) = free { | ||
| 102 | - let file = SnippetFile { | ||
| 103 | - name: String::new(), | ||
| 104 | - content: String::new(), | ||
| 105 | - }; | ||
| 106 | - self.files.push((number, file)); | ||
| 107 | - } | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - fn slots(&self) -> Vec<Slot> { | ||
| 111 | - if self.files.is_empty() { | ||
| 112 | - return vec![Slot { | ||
| 113 | - number: 0, | ||
| 114 | - name: String::new(), | ||
| 115 | - content: String::new(), | ||
| 116 | - }]; | ||
| 117 | - } | ||
| 118 | - self.files | ||
| 119 | - .iter() | ||
| 120 | - .map(|(number, file)| { | ||
| 121 | - let content = if file.content.starts_with('\n') { | ||
| 122 | - format!("\n{}", file.content) | ||
| 123 | - } else { | ||
| 124 | - file.content.clone() | ||
| 125 | - }; | ||
| 126 | - Slot { | ||
| 127 | - number: *number, | ||
| 128 | - name: file.name.clone(), | ||
| 129 | - content, | ||
| 130 | - } | ||
| 131 | - }) | ||
| 132 | - .collect() | ||
| 133 | - } | ||
| 134 | -} | ||
| 135 | - | ||
| 136 | -fn apply_slot_step(draft: &mut Draft, form: &HashMap<String, String>) -> Option<usize> { | ||
| 137 | - if form.get("op").map(String::as_str) == Some("add") { | ||
| 138 | - draft.add_blank(); | ||
| 139 | - Some(draft.files.len().saturating_sub(1)) | ||
| 140 | - } else if let Some(number) = form.get("remove") { | ||
| 141 | - let number: usize = number.parse().unwrap_or(usize::MAX); | ||
| 142 | - let position = draft.position(number).unwrap_or(0); | ||
| 143 | - draft.remove(number); | ||
| 144 | - Some(position.saturating_sub(1)) | ||
| 145 | - } else { | ||
| 146 | - None | ||
| 147 | - } | ||
| 148 | -} | ||
| 149 | - | ||
| 150 | -fn posted_tab(draft: &Draft, form: &HashMap<String, String>) -> usize { | ||
| 151 | - form.get("tab") | ||
| 152 | - .and_then(|tab| tab.parse().ok()) | ||
| 153 | - .and_then(|number| draft.position(number)) | ||
| 154 | - .unwrap_or(0) | ||
| 155 | -} | ||
| 156 | - | ||
| 157 | -enum FileBody { | ||
| 158 | - Markdown(String), | ||
| 159 | - Highlighted(String), | ||
| 160 | - Plain(String), | ||
| 161 | -} | ||
| 162 | - | ||
| 163 | -struct FileView { | ||
| 164 | - name: String, | ||
| 165 | - raw: String, | ||
| 166 | - body: FileBody, | ||
| 167 | -} | ||
| 168 | - | ||
| 169 | -struct RevisionView { | ||
| 170 | - number: usize, | ||
| 171 | - author: String, | ||
| 172 | - at: String, | ||
| 173 | - file_names: String, | ||
| 174 | -} | ||
| 175 | - | ||
| 176 | -pub(crate) struct ListRow { | ||
| 177 | - id: String, | ||
| 178 | - title: String, | ||
| 179 | - owner: String, | ||
| 180 | - visibility: &'static str, | ||
| 181 | - files: String, | ||
| 182 | - updated_at: String, | ||
| 183 | -} | ||
| 184 | - | ||
| 185 | -pub(crate) fn list_row(lang: Lang, summary: SnippetSummary) -> ListRow { | ||
| 186 | - ListRow { | ||
| 187 | - id: summary.id, | ||
| 188 | - title: summary.title, | ||
| 189 | - owner: summary.owner_name, | ||
| 190 | - visibility: visibility_label(lang, summary.visibility), | ||
| 191 | - files: g::files_count(lang, summary.file_count), | ||
| 192 | - updated_at: summary.updated_at, | ||
| 193 | - } | ||
| 194 | -} | ||
| 195 | - | ||
| 196 | -fn visibility_label(lang: Lang, visibility: SnippetVisibility) -> &'static str { | ||
| 197 | - match visibility { | ||
| 198 | - SnippetVisibility::Public => g::t(lang, K::VisibilityPublic), | ||
| 199 | - SnippetVisibility::Unlisted => g::t(lang, K::VisibilityUnlisted), | ||
| 200 | - SnippetVisibility::Private => g::t(lang, K::VisibilityPrivate), | ||
| 201 | - } | ||
| 202 | -} | ||
| 203 | - | ||
| 204 | -fn extension(name: &str) -> String { | ||
| 205 | - name.rsplit_once('.') | ||
| 206 | - .map(|(_, ext)| ext.to_ascii_lowercase()) | ||
| 207 | - .unwrap_or_default() | ||
| 208 | -} | ||
| 209 | - | ||
| 210 | -fn file_view(state: &AppState, snippet: &Snippet, file: &SnippetFile) -> FileView { | ||
| 211 | - let body = if matches!(extension(&file.name).as_str(), "md" | "markdown") { | ||
| 212 | - FileBody::Markdown(render_markdown(&file.content, None)) | ||
| 213 | - } else { | ||
| 214 | - match highlight_lines(&file.name, &file.content) { | ||
| 215 | - Some(lines) => FileBody::Highlighted(lines.join("\n")), | ||
| 216 | - None => FileBody::Plain(file.content.clone()), | ||
| 217 | - } | ||
| 218 | - }; | ||
| 219 | - FileView { | ||
| 220 | - name: file.name.clone(), | ||
| 221 | - raw: snippet_raw_url(state, snippet, &file.name), | ||
| 222 | - body, | ||
| 223 | - } | ||
| 224 | -} | ||
| 225 | - | ||
| 226 | -pub(crate) async fn readable( | ||
| 227 | - cx: &Cx, | ||
| 228 | - viewer_id: Option<&str>, | ||
| 229 | - snippet_id: &str, | ||
| 230 | -) -> Result<Snippet> { | ||
| 231 | - let store = &context::<AppState>(cx).store; | ||
| 232 | - match store.get_snippet(snippet_id).await? { | ||
| 233 | - Some(snippet) if snippet.is_visible_to(viewer_id) => Ok(snippet), | ||
| 234 | - _ => Err(not_found().into()), | ||
| 235 | - } | ||
| 236 | -} | ||
| 237 | - | ||
| 238 | -async fn owned(cx: &Cx, user: &User, snippet_id: &str) -> Result<Snippet> { | ||
| 239 | - let store = &context::<AppState>(cx).store; | ||
| 240 | - match store.get_snippet(snippet_id).await? { | ||
| 241 | - Some(snippet) if snippet.owner_id == user.id => Ok(snippet), | ||
| 242 | - _ => Err(not_found().into()), | ||
| 243 | - } | ||
| 244 | -} | ||
| 245 | - | ||
| 246 | -async fn record_snippet(cx: &Cx, user: &User, action: AuditAction, snippet: &Snippet) { | ||
| 247 | - audit::record( | ||
| 248 | - &context::<AppState>(cx).store, | ||
| 249 | - Some(cx), | ||
| 250 | - Actor::User(user), | ||
| 251 | - action, | ||
| 252 | - Target { | ||
| 253 | - kind: "snippet", | ||
| 254 | - id: &snippet.id, | ||
| 255 | - name: &snippet.title, | ||
| 256 | - }, | ||
| 257 | - serde_json::Value::Null, | ||
| 258 | - ) | ||
| 259 | - .await; | ||
| 260 | - bump_snippet(context::<AppState>(cx), &snippet.id); | ||
| 261 | -} | ||
| 262 | - | ||
| 263 | -#[component] | ||
| 264 | -pub(crate) async fn snippet_rows(cx: &Cx, lang: Lang, rows: Vec<ListRow>) -> Result<impl View> { | ||
| 265 | - Ok(view! { | ||
| 266 | - <div class="snippet-list"> | ||
| 267 | - for row in rows.into_iter() { | ||
| 268 | - <a class="line" href=(format!("/snippets/{}", row.id)) data-kb-row=""> | ||
| 269 | - <span class="name">(row.title)</span> | ||
| 270 | - <span class="val">(row.owner) " · " (row.visibility) " · " (row.files) " · " (g::updated_before(lang)) rel_time(lang: lang, stamp: row.updated_at.as_str()) (g::updated_after(lang))</span> | ||
| 271 | - </a> | ||
| 272 | - } | ||
| 273 | - </div> | ||
| 274 | - }) | ||
| 275 | -} | ||
| 276 | - | ||
| 277 | -#[component] | ||
| 278 | -async fn snippet_list_body( | ||
| 279 | - cx: &Cx, | ||
| 280 | - lang: Lang, | ||
| 281 | - rows: Vec<ListRow>, | ||
| 282 | - signed_in: bool, | ||
| 283 | - live: Option<String>, | ||
| 284 | -) -> Result<impl View> { | ||
| 285 | - Ok(view! { | ||
| 286 | - head(title: g::t(lang, K::Snippets), | ||
| 287 | - if signed_in { | ||
| 288 | - <a class="button primary" href="/snippets/new">(g::t(lang, K::NewSnippet))</a> | ||
| 289 | - } | ||
| 290 | - ) | ||
| 291 | - <div class="sheet" data-live=(live.as_deref())> | ||
| 292 | - if rows.is_empty() { | ||
| 293 | - empty_state(title: g::t(lang, K::NoSnippets)) | ||
| 294 | - } else { | ||
| 295 | - snippet_rows(lang: lang, rows: rows) | ||
| 296 | - } | ||
| 297 | - </div> | ||
| 298 | - }) | ||
| 299 | -} | ||
| 300 | - | ||
| 301 | -#[component] | ||
| 302 | -async fn snippet_files( | ||
| 303 | - cx: &Cx, | ||
| 304 | - lang: Lang, | ||
| 305 | - slots: Vec<Slot>, | ||
| 306 | - active: usize, | ||
| 307 | - removable: bool, | ||
| 308 | - can_add: bool, | ||
| 309 | - counter: String, | ||
| 310 | -) -> Result<impl View> { | ||
| 311 | - let blanks = slots.iter().filter(|s| s.name.trim().is_empty()).count(); | ||
| 312 | - let tabs: Vec<(usize, String, bool)> = slots | ||
| 313 | - .iter() | ||
| 314 | - .enumerate() | ||
| 315 | - .map(|(index, slot)| { | ||
| 316 | - let label = if slot.name.trim().is_empty() { | ||
| 317 | - let untitled = g::t(lang, K::Untitled); | ||
| 318 | - if blanks > 1 { | ||
| 319 | - format!("{untitled} {}", index + 1) | ||
| 320 | - } else { | ||
| 321 | - untitled.to_owned() | ||
| 322 | - } | ||
| 323 | - } else { | ||
| 324 | - slot.name.clone() | ||
| 325 | - }; | ||
| 326 | - (slot.number, label, index == active) | ||
| 327 | - }) | ||
| 328 | - .collect(); | ||
| 329 | - Ok(view! { | ||
| 330 | - <div class="snippet-files"> | ||
| 331 | - <span class="snippet-files-label" aria-hidden="true">(g::t(lang, K::Files))</span> | ||
| 332 | - <div class="snippet-tabbar"> | ||
| 333 | - <div class="snippet-tabs" role="group" aria-label=(g::t(lang, K::Files))> | ||
| 334 | - for (number, label, checked) in tabs.into_iter() { | ||
| 335 | - <input type="radio" class="snippet-tab-radio" id=(format!("snippet-tab-{number}")) | ||
| 336 | - name="tab" value=(number.to_string()) checked=(checked)> | ||
| 337 | - <label class="snippet-tab" for=(format!("snippet-tab-{number}"))>(label)</label> | ||
| 338 | - } | ||
| 339 | - </div> | ||
| 340 | - <p class="hint snippet-count">(counter)</p> | ||
| 341 | - </div> | ||
| 342 | - if can_add { | ||
| 343 | - <div class="acts"> | ||
| 344 | - <button type="submit" class="act snippet-tab-add" name="op" value="add" formnovalidate=(true)>(g::t(lang, K::AddFile))</button> | ||
| 345 | - </div> | ||
| 346 | - } | ||
| 347 | - for (index, slot) in slots.into_iter().enumerate() { | ||
| 348 | - <fieldset class=(format!("snippet-panel snippet-panel-{}", slot.number))> | ||
| 349 | - <legend class="sr-only">(g::t(lang, K::FileLabel))(index + 1)</legend> | ||
| 350 | - <div class="field"> | ||
| 351 | - <label for=(format!("snippet-name-{}", slot.number))>(g::t(lang, K::FileName))</label> | ||
| 352 | - <input type="text" id=(format!("snippet-name-{}", slot.number)) class="snippet-name" name=(format!("name_{}", slot.number)) value=(slot.name) | ||
| 353 | - maxlength="100" placeholder=(g::t(lang, K::FileNamePlaceholder))> | ||
| 354 | - </div> | ||
| 355 | - <div class="field"> | ||
| 356 | - <label for=(format!("snippet-content-{}", slot.number))>(g::t(lang, K::FileContents))</label> | ||
| 357 | - <textarea id=(format!("snippet-content-{}", slot.number)) class="code snippet-content" name=(format!("content_{}", slot.number)) | ||
| 358 | - spellcheck="false">(slot.content)</textarea> | ||
| 359 | - </div> | ||
| 360 | - if removable { | ||
| 361 | - <div class="acts"> | ||
| 362 | - <button type="submit" class="act quiet snippet-remove" name="remove" value=(slot.number.to_string()) | ||
| 363 | - formnovalidate=(true)>(g::t(lang, K::RemoveFile))</button> | ||
| 364 | - </div> | ||
| 365 | - } | ||
| 366 | - </fieldset> | ||
| 367 | - } | ||
| 368 | - </div> | ||
| 369 | - }) | ||
| 370 | -} | ||
| 371 | - | ||
| 372 | -#[component] | ||
| 373 | -async fn snippet_form( | ||
| 374 | - cx: &Cx, | ||
| 375 | - lang: Lang, | ||
| 376 | - csrf: &str, | ||
| 377 | - action: &str, | ||
| 378 | - draft: &Draft, | ||
| 379 | - active: usize, | ||
| 380 | - error: Option<String>, | ||
| 381 | -) -> Result<impl View> { | ||
| 382 | - let title = draft.title.as_str(); | ||
| 383 | - let description = draft.description.as_str(); | ||
| 384 | - let public = draft.visibility == "public"; | ||
| 385 | - let unlisted = draft.visibility == "unlisted"; | ||
| 386 | - let private = draft.visibility == "private"; | ||
| 387 | - let slots = draft.slots(); | ||
| 388 | - let removable = slots.len() > 1; | ||
| 389 | - let can_add = slots.len() < MAX_FILES; | ||
| 390 | - let counter = g::files_limit( | ||
| 391 | - lang, | ||
| 392 | - slots.len(), | ||
| 393 | - MAX_FILES, | ||
| 394 | - MAX_TOTAL_BYTES / (1024 * 1024), | ||
| 395 | - ); | ||
| 396 | - Ok(view! { | ||
| 397 | - if let Some(message) = error { | ||
| 398 | - alert(message: message.as_str()) | ||
| 399 | - } | ||
| 400 | - <form method="post" action=(action) class="fields snippet-form"> | ||
| 401 | - <input type="hidden" name="csrf" value=(csrf)> | ||
| 402 | - <div class="field"> | ||
| 403 | - <label for="snippet-title">(g::t(lang, K::Title))</label> | ||
| 404 | - <input id="snippet-title" type="text" class="snippet-title" name="title" value=(title) maxlength="120" required=(true) | ||
| 405 | - placeholder=(g::t(lang, K::SnippetTitlePlaceholder))> | ||
| 406 | - </div> | ||
| 407 | - <div class="field"> | ||
| 408 | - <label for="snippet-description">(g::t(lang, K::Description))</label> | ||
| 409 | - <input id="snippet-description" type="text" class="snippet-desc" name="description" value=(description) maxlength="1000" | ||
| 410 | - placeholder=(g::t(lang, K::DescriptionOptional))> | ||
| 411 | - </div> | ||
| 412 | - <div class="field" role="radiogroup" aria-labelledby="snippet-visibility"> | ||
| 413 | - <label id="snippet-visibility">(g::t(lang, K::Visibility))</label> | ||
| 414 | - <div class="choice"> | ||
| 415 | - <label title=(g::t(lang, K::PublicOption))> | ||
| 416 | - <input type="radio" name="visibility" value="public" checked=(public)> | ||
| 417 | - <span>(g::t(lang, K::VisibilityPublic))</span> | ||
| 418 | - </label> | ||
| 419 | - <label title=(g::t(lang, K::UnlistedOption))> | ||
| 420 | - <input type="radio" name="visibility" value="unlisted" checked=(unlisted)> | ||
| 421 | - <span>(g::t(lang, K::VisibilityUnlisted))</span> | ||
| 422 | - </label> | ||
| 423 | - <label title=(g::t(lang, K::PrivateOption))> | ||
| 424 | - <input type="radio" name="visibility" value="private" checked=(private)> | ||
| 425 | - <span>(g::t(lang, K::VisibilityPrivate))</span> | ||
| 426 | - </label> | ||
| 427 | - </div> | ||
| 428 | - </div> | ||
| 429 | - <button type="submit" class="primary">(g::t(lang, K::SaveSnippet))</button> | ||
| 430 | - snippet_files(lang: lang, slots: slots, active: active, removable: removable, can_add: can_add, | ||
| 431 | - counter: counter) | ||
| 432 | - </form> | ||
| 433 | - }) | ||
| 434 | -} | ||
| 435 | - | ||
| 436 | -#[component] | ||
| 437 | -async fn snippet_body( | ||
| 438 | - cx: &Cx, | ||
| 439 | - lang: Lang, | ||
| 440 | - snippet_id: &str, | ||
| 441 | - title: &str, | ||
| 442 | - owner: &str, | ||
| 443 | - description: &str, | ||
| 444 | - visibility: &'static str, | ||
| 445 | - updated_at: &str, | ||
| 446 | - files: Vec<FileView>, | ||
| 447 | - owner_csrf: Option<String>, | ||
| 448 | - live: Option<String>, | ||
| 449 | -) -> Result<impl View> { | ||
| 450 | - let is_owner = owner_csrf.is_some(); | ||
| 451 | - let edit_href = format!("/snippets/{snippet_id}/edit"); | ||
| 452 | - let history_href = format!("/snippets/{snippet_id}/revisions"); | ||
| 453 | - let delete_action = format!("/snippets/{snippet_id}/delete"); | ||
| 454 | - Ok(view! { | ||
| 455 | - head(title: title, sub: vec![SubPart::text(owner), SubPart::text(visibility)], | ||
| 456 | - <a class="button" href=(history_href)>(g::t(lang, K::Revisions))</a> | ||
| 457 | - if let Some(token) = owner_csrf { | ||
| 458 | - <a class="button" href=(edit_href)>(g::t(lang, K::Edit))</a> | ||
| 459 | - confirm_act(lang: lang, label: g::t(lang, K::Delete), action: delete_action.as_str(), csrf: token.as_str()) | ||
| 460 | - } | ||
| 461 | - ) | ||
| 462 | - if is_owner { | ||
| 463 | - crate::pages::profile::own_profile_tabs(lang: lang, username: owner.to_owned(), current: crate::pages::profile::Tab::Snippets) | ||
| 464 | - } | ||
| 465 | - <div class="sheet" data-live=(live.as_deref())> | ||
| 466 | - <section class="sec"> | ||
| 467 | - if !description.is_empty() { | ||
| 468 | - <p>(description)</p> | ||
| 469 | - } | ||
| 470 | - <p class="hint">(g::updated_before(lang)) rel_time(lang: lang, stamp: updated_at) (g::updated_after(lang))</p> | ||
| 471 | - </section> | ||
| 472 | - for file in files.into_iter() { | ||
| 473 | - <section class="sec snippet-file"> | ||
| 474 | - <div class="sheet-tools"> | ||
| 475 | - <strong>(file.name.clone())</strong> | ||
| 476 | - <a class="act" href=(file.raw.clone())>(g::t(lang, K::Raw))</a> | ||
| 477 | - </div> | ||
| 478 | - if let FileBody::Markdown(html) = &file.body { | ||
| 479 | - <div class="markdown-body">(Unescaped::new_unchecked(html.clone()))</div> | ||
| 480 | - } else if let FileBody::Highlighted(html) = &file.body { | ||
| 481 | - <pre class="code snippet-code"><code>(Unescaped::new_unchecked(html.clone()))</code></pre> | ||
| 482 | - } else if let FileBody::Plain(text) = &file.body { | ||
| 483 | - <pre class="code snippet-code"><code>(text.clone())</code></pre> | ||
| 484 | - } | ||
| 485 | - </section> | ||
| 486 | - } | ||
| 487 | - </div> | ||
| 488 | - }) | ||
| 489 | -} | ||
| 490 | - | ||
| 491 | -#[component] | ||
| 492 | -async fn revisions_body( | ||
| 493 | - cx: &Cx, | ||
| 494 | - lang: Lang, | ||
| 495 | - snippet_id: &str, | ||
| 496 | - title: &str, | ||
| 497 | - revisions: Vec<RevisionView>, | ||
| 498 | - live: Option<String>, | ||
| 499 | - owner_tabs: Option<String>, | ||
| 500 | -) -> Result<impl View> { | ||
| 501 | - let back = format!("/snippets/{snippet_id}"); | ||
| 502 | - let heading = g::revisions_of(lang, title); | ||
| 503 | - Ok(view! { | ||
| 504 | - head(title: heading.as_str(), | ||
| 505 | - <a class="button" href=(back)>(g::t(lang, K::BackToSnippet))</a> | ||
| 506 | - ) | ||
| 507 | - if let Some(owner) = owner_tabs { | ||
| 508 | - crate::pages::profile::own_profile_tabs(lang: lang, username: owner, current: crate::pages::profile::Tab::Snippets) | ||
| 509 | - } | ||
| 510 | - <div class="sheet" data-live=(live.as_deref())> | ||
| 511 | - if revisions.is_empty() { | ||
| 512 | - <p class="state">(g::t(lang, K::NoRevisions))</p> | ||
| 513 | - } else { | ||
| 514 | - for rev in revisions.into_iter() { | ||
| 515 | - <div class="line" data-kb-row=""> | ||
| 516 | - <span class="name">(g::t(lang, K::RevisionLabel))(rev.number)</span> | ||
| 517 | - <span class="val">(rev.author) " · " rel_time(lang: lang, stamp: rev.at.as_str()) " · " (rev.file_names)</span> | ||
| 518 | - </div> | ||
| 519 | - } | ||
| 520 | - } | ||
| 521 | - </div> | ||
| 522 | - }) | ||
| 523 | -} | ||
| 524 | - | ||
| 525 | -#[component] | ||
| 526 | -async fn snippet_form_page( | ||
| 527 | - cx: &Cx, | ||
| 528 | - lang: Lang, | ||
| 529 | - viewer: &(User, Session), | ||
| 530 | - heading: &str, | ||
| 531 | - action: &str, | ||
| 532 | - draft: Draft, | ||
| 533 | - error: Option<String>, | ||
| 534 | - active: usize, | ||
| 535 | -) -> Result<impl View> { | ||
| 536 | - let csrf = viewer.1.csrf_token.clone(); | ||
| 537 | - let tab_user = viewer.0.username.clone(); | ||
| 538 | - Ok(view! { | ||
| 539 | - shell(title: heading, viewer: Some(viewer), | ||
| 540 | - head(title: heading) | ||
| 541 | - crate::pages::profile::own_profile_tabs(lang: lang, username: tab_user, current: crate::pages::profile::Tab::Snippets) | ||
| 542 | - <div class="sheet"> | ||
| 543 | - snippet_form(lang: lang, csrf: csrf.as_str(), action: action, | ||
| 544 | - draft: &draft, active: active, error: error) | ||
| 545 | - </div> | ||
| 546 | - ) | ||
| 547 | - }) | ||
| 548 | -} | ||
| 549 | - | ||
| 550 | -#[page("/snippets")] | ||
| 551 | -async fn snippets_list(cx: &Cx) -> Result<impl View> { | ||
| 552 | - let viewer = current_user(cx).await?; | ||
| 553 | - let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user)); | ||
| 554 | - let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone()); | ||
| 555 | - let summaries: Vec<SnippetSummary> = context::<AppState>(cx) | ||
| 556 | - .store | ||
| 557 | - .list_snippets(viewer_id.as_deref()) | ||
| 558 | - .await?; | ||
| 559 | - let rows: Vec<ListRow> = summaries.into_iter().map(|s| list_row(lang, s)).collect(); | ||
| 560 | - let signed_in = viewer.is_some(); | ||
| 561 | - let title = g::t(lang, K::Snippets); | ||
| 562 | - Ok(view! { | ||
| 563 | - shell(title: title, viewer: viewer.as_ref(), | ||
| 564 | - snippet_list_body(lang: lang, rows: rows, signed_in: signed_in, live: Some(list_live_url().to_owned())) | ||
| 565 | - ) | ||
| 566 | - }) | ||
| 567 | -} | ||
| 568 | - | ||
| 569 | -#[page("/snippets/new")] | ||
| 570 | -async fn snippet_new(cx: &Cx) -> Result<impl View> { | ||
| 571 | - let viewer = require_user(cx).await?; | ||
| 572 | - let lang = i18n::lang(cx, Some(&viewer.0)); | ||
| 573 | - Ok(view! { | ||
| 574 | - snippet_form_page(lang: lang, viewer: &viewer, heading: g::t(lang, K::NewSnippet), action: "/snippets/new", | ||
| 575 | - draft: Draft::blank(), error: None, active: 0) | ||
| 576 | - }) | ||
| 577 | -} | ||
| 578 | - | ||
| 579 | -#[page(POST "/snippets/new")] | ||
| 580 | -async fn snippet_create(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Result<impl View> { | ||
| 581 | - let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?; | ||
| 582 | - let lang = i18n::lang(cx, Some(&user)); | ||
| 583 | - let mut draft = Draft::from_form(&form); | ||
| 584 | - let mut error = None; | ||
| 585 | - let step = apply_slot_step(&mut draft, &form); | ||
| 586 | - if step.is_none() { | ||
| 587 | - let store = &context::<AppState>(cx).store; | ||
| 588 | - let files = draft.saved_files(); | ||
| 589 | - let saved = match draft.visibility.parse::<SnippetVisibility>() { | ||
| 590 | - Err(_) => Err(g::t(lang, K::ChooseVisibility).to_owned()), | ||
| 591 | - Ok(visibility) => match store | ||
| 592 | - .create_snippet( | ||
| 593 | - &user.id, | ||
| 594 | - &draft.title, | ||
| 595 | - &draft.description, | ||
| 596 | - visibility, | ||
| 597 | - &files, | ||
| 598 | - ) | ||
| 599 | - .await | ||
| 600 | - { | ||
| 601 | - Ok(snippet) => Ok(snippet), | ||
| 602 | - Err(e) => match user_facing_message(&e) { | ||
| 603 | - Some(message) => Err(message), | ||
| 604 | - None => return Err(e.into()), | ||
| 605 | - }, | ||
| 606 | - }, | ||
| 607 | - }; | ||
| 608 | - match saved { | ||
| 609 | - Ok(snippet) => { | ||
| 610 | - record_snippet(cx, &user, AuditAction::SnippetCreated, &snippet).await; | ||
| 611 | - return Err(see_other(format!("/snippets/{}", snippet.id)).into()); | ||
| 612 | - } | ||
| 613 | - Err(message) => error = Some(message), | ||
| 614 | - } | ||
| 615 | - } | ||
| 616 | - let active = step.unwrap_or_else(|| posted_tab(&draft, &form)); | ||
| 617 | - let viewer = require_user(cx).await?; | ||
| 618 | - Ok(view! { | ||
| 619 | - snippet_form_page(lang: lang, viewer: &viewer, heading: g::t(lang, K::NewSnippet), action: "/snippets/new", | ||
| 620 | - draft: draft, error: error, active: active) | ||
| 621 | - }) | ||
| 622 | -} | ||
| 623 | - | ||
| 624 | -#[page("/snippets/{id}")] | ||
| 625 | -async fn snippet_view(cx: &Cx) -> Result<impl View> { | ||
| 626 | - let snippet_id = id(cx).to_owned(); | ||
| 627 | - let viewer = current_user(cx).await?; | ||
| 628 | - let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user)); | ||
| 629 | - let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone()); | ||
| 630 | - let snippet = readable(cx, viewer_id.as_deref(), &snippet_id).await?; | ||
| 631 | - let state = context::<AppState>(cx); | ||
| 632 | - let files: Vec<FileView> = snippet | ||
| 633 | - .files | ||
| 634 | - .iter() | ||
| 635 | - .map(|file| file_view(state, &snippet, file)) | ||
| 636 | - .collect(); | ||
| 637 | - let owner_csrf = match &viewer { | ||
| 638 | - Some((user, session)) if user.id == snippet.owner_id => Some(session.csrf_token.clone()), | ||
| 639 | - _ => None, | ||
| 640 | - }; | ||
| 641 | - let visibility = visibility_label(lang, snippet.visibility); | ||
| 642 | - Ok(view! { | ||
| 643 | - shell(title: snippet.title.as_str(), viewer: viewer.as_ref(), | ||
| 644 | - snippet_body(lang: lang, snippet_id: snippet.id.as_str(), title: snippet.title.as_str(), | ||
| 645 | - owner: snippet.owner_name.as_str(), description: snippet.description.as_str(), | ||
| 646 | - visibility: visibility, updated_at: snippet.updated_at.as_str(), files: files, | ||
| 647 | - owner_csrf: owner_csrf, live: Some(item_live_url(snippet.id.as_str()))) | ||
| 648 | - ) | ||
| 649 | - }) | ||
| 650 | -} | ||
| 651 | - | ||
| 652 | -#[page("/snippets/{id}/edit")] | ||
| 653 | -async fn snippet_edit(cx: &Cx) -> Result<impl View> { | ||
| 654 | - let snippet_id = id(cx).to_owned(); | ||
| 655 | - let viewer = require_user(cx).await?; | ||
| 656 | - let lang = i18n::lang(cx, Some(&viewer.0)); | ||
| 657 | - let snippet = owned(cx, &viewer.0, &snippet_id).await?; | ||
| 658 | - let action = format!("/snippets/{snippet_id}/edit"); | ||
| 659 | - let draft = Draft::from_snippet(&snippet); | ||
| 660 | - Ok(view! { | ||
| 661 | - snippet_form_page(lang: lang, viewer: &viewer, heading: g::t(lang, K::EditSnippet), action: action.as_str(), | ||
| 662 | - draft: draft, error: None, active: 0) | ||
| 663 | - }) | ||
| 664 | -} | ||
| 665 | - | ||
| 666 | -#[page(POST "/snippets/{id}/edit")] | ||
| 667 | -async fn snippet_update(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Result<impl View> { | ||
| 668 | - let snippet_id = id(cx).to_owned(); | ||
| 669 | - let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?; | ||
| 670 | - let lang = i18n::lang(cx, Some(&user)); | ||
| 671 | - owned(cx, &user, &snippet_id).await?; | ||
| 672 | - let mut draft = Draft::from_form(&form); | ||
| 673 | - let mut error = None; | ||
| 674 | - let step = apply_slot_step(&mut draft, &form); | ||
| 675 | - if step.is_none() { | ||
| 676 | - let store = &context::<AppState>(cx).store; | ||
| 677 | - let files = draft.saved_files(); | ||
| 678 | - let saved = match draft.visibility.parse::<SnippetVisibility>() { | ||
| 679 | - Err(_) => Err(g::t(lang, K::ChooseVisibility).to_owned()), | ||
| 680 | - Ok(visibility) => match store | ||
| 681 | - .update_snippet( | ||
| 682 | - &user.id, | ||
| 683 | - &snippet_id, | ||
| 684 | - &draft.title, | ||
| 685 | - &draft.description, | ||
| 686 | - visibility, | ||
| 687 | - &files, | ||
| 688 | - ) | ||
| 689 | - .await | ||
| 690 | - { | ||
| 691 | - Ok(snippet) => Ok(snippet), | ||
| 692 | - Err(e) => match user_facing_message(&e) { | ||
| 693 | - Some(message) => Err(message), | ||
| 694 | - None => return Err(e.into()), | ||
| 695 | - }, | ||
| 696 | - }, | ||
| 697 | - }; | ||
| 698 | - match saved { | ||
| 699 | - Ok(snippet) => { | ||
| 700 | - record_snippet(cx, &user, AuditAction::SnippetUpdated, &snippet).await; | ||
| 701 | - return Err(see_other(format!("/snippets/{}", snippet.id)).into()); | ||
| 702 | - } | ||
| 703 | - Err(message) => error = Some(message), | ||
| 704 | - } | ||
| 705 | - } | ||
| 706 | - let active = step.unwrap_or_else(|| posted_tab(&draft, &form)); | ||
| 707 | - let viewer = require_user(cx).await?; | ||
| 708 | - let action = format!("/snippets/{snippet_id}/edit"); | ||
| 709 | - Ok(view! { | ||
| 710 | - snippet_form_page(lang: lang, viewer: &viewer, heading: g::t(lang, K::EditSnippet), action: action.as_str(), | ||
| 711 | - draft: draft, error: error, active: active) | ||
| 712 | - }) | ||
| 713 | -} | ||
| 714 | - | ||
| 715 | -#[page("/snippets/{id}/revisions")] | ||
| 716 | -async fn snippet_revisions(cx: &Cx) -> Result<impl View> { | ||
| 717 | - let snippet_id = id(cx).to_owned(); | ||
| 718 | - let viewer = current_user(cx).await?; | ||
| 719 | - let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone()); | ||
| 720 | - let snippet = readable(cx, viewer_id.as_deref(), &snippet_id).await?; | ||
| 721 | - let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user)); | ||
| 722 | - let store = &context::<AppState>(cx).store; | ||
| 723 | - let revisions: Vec<SnippetRevision> = store.list_snippet_revisions(&snippet.id).await?; | ||
| 724 | - let rows: Vec<RevisionView> = revisions | ||
| 725 | - .into_iter() | ||
| 726 | - .enumerate() | ||
| 727 | - .map(|(index, rev)| RevisionView { | ||
| 728 | - number: index + 1, | ||
| 729 | - author: rev.author_name, | ||
| 730 | - at: rev.created_at.clone(), | ||
| 731 | - file_names: rev | ||
| 732 | - .files | ||
| 733 | - .iter() | ||
| 734 | - .map(|f| f.name.as_str()) | ||
| 735 | - .collect::<Vec<_>>() | ||
| 736 | - .join(", "), | ||
| 737 | - }) | ||
| 738 | - .rev() | ||
| 739 | - .collect(); | ||
| 740 | - Ok(view! { | ||
| 741 | - shell(title: snippet.title.as_str(), viewer: viewer.as_ref(), | ||
| 742 | - revisions_body(lang: lang, snippet_id: snippet.id.as_str(), title: snippet.title.as_str(), | ||
| 743 | - revisions: rows, live: Some(item_live_url(snippet.id.as_str())), | ||
| 744 | - owner_tabs: viewer.as_ref().filter(|(user, _)| user.id == snippet.owner_id).map(|(user, _)| user.username.clone())) | ||
| 745 | - ) | ||
| 746 | - }) | ||
| 747 | -} | ||
| 748 | - | ||
| 749 | -#[route(POST "/snippets/{id}/delete")] | ||
| 750 | -async fn snippet_delete(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Result<SeeOther> { | ||
| 751 | - let snippet_id = id(cx).to_owned(); | ||
| 752 | - let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?; | ||
| 753 | - let snippet = owned(cx, &user, &snippet_id).await?; | ||
| 754 | - let store = &context::<AppState>(cx).store; | ||
| 755 | - if store.delete_snippet(&user.id, &snippet.id).await? { | ||
| 756 | - record_snippet(cx, &user, AuditAction::SnippetDeleted, &snippet).await; | ||
| 757 | - } | ||
| 758 | - Ok(see_other("/snippets")) | ||
| 759 | -} | ||
| 760 | - | ||
| 761 | -#[cfg(test)] | ||
| 762 | -mod tests { | ||
| 763 | - use super::*; | ||
| 764 | - | ||
| 765 | - fn form(pairs: &[(&str, &str)]) -> HashMap<String, String> { | ||
| 766 | - pairs | ||
| 767 | - .iter() | ||
| 768 | - .map(|(k, v)| ((*k).to_owned(), (*v).to_owned())) | ||
| 769 | - .collect() | ||
| 770 | - } | ||
| 771 | - | ||
| 772 | - #[test] | ||
| 773 | - fn draft_saves_drop_blank_cards_and_keep_leading_newlines() { | ||
| 774 | - let draft = Draft::from_form(&form(&[ | ||
| 775 | - ("title", "t"), | ||
| 776 | - ("visibility", "public"), | ||
| 777 | - ("name_0", "a.txt"), | ||
| 778 | - ("content_0", "one\r\ntwo"), | ||
| 779 | - ("name_1", ""), | ||
| 780 | - ("content_1", " "), | ||
| 781 | - ("name_2", "b.rs"), | ||
| 782 | - ("content_2", ""), | ||
| 783 | - ])); | ||
| 784 | - assert_eq!( | ||
| 785 | - draft.files.len(), | ||
| 786 | - 3, | ||
| 787 | - "blank cards: every card is kept while editing" | ||
| 788 | - ); | ||
| 789 | - let saved = draft.saved_files(); | ||
| 790 | - assert_eq!(saved.len(), 2, "blank cards: a save drops the blank ones"); | ||
| 791 | - assert_eq!( | ||
| 792 | - saved[0].content, "one\ntwo", | ||
| 793 | - "blank cards: CRLF is normalised" | ||
| 794 | - ); | ||
| 795 | - assert_eq!(saved[1].name, "b.rs", "blank cards: the kept file"); | ||
| 796 | - | ||
| 797 | - let mut draft = Draft::blank(); | ||
| 798 | - draft.files = vec![( | ||
| 799 | - 0, | ||
| 800 | - SnippetFile { | ||
| 801 | - name: "a".into(), | ||
| 802 | - content: "\nx".into(), | ||
| 803 | - }, | ||
| 804 | - )]; | ||
| 805 | - assert_eq!(draft.slots()[0].content, "\n\nx", "leading newline"); | ||
| 806 | - } | ||
| 807 | - | ||
| 808 | - #[test] | ||
| 809 | - fn card_steps_add_remove_and_show_the_right_tab() { | ||
| 810 | - let draft = Draft::blank(); | ||
| 811 | - let slots = draft.slots(); | ||
| 812 | - assert_eq!(slots.len(), 1, "new form: one card"); | ||
| 813 | - assert_eq!( | ||
| 814 | - (slots[0].number, slots[0].name.as_str()), | ||
| 815 | - (0, ""), | ||
| 816 | - "new form: the card is empty" | ||
| 817 | - ); | ||
| 818 | - | ||
| 819 | - let mut draft = Draft::blank(); | ||
| 820 | - for _ in 0..MAX_FILES + 3 { | ||
| 821 | - draft.add_blank(); | ||
| 822 | - } | ||
| 823 | - assert_eq!(draft.slots().len(), MAX_FILES, "add: stops at the limit"); | ||
| 824 | - let numbers: Vec<usize> = draft.slots().iter().map(|s| s.number).collect(); | ||
| 825 | - assert_eq!( | ||
| 826 | - numbers, | ||
| 827 | - (0..MAX_FILES).collect::<Vec<_>>(), | ||
| 828 | - "add: numbers run from zero" | ||
| 829 | - ); | ||
| 830 | - | ||
| 831 | - let mut draft = Draft::blank(); | ||
| 832 | - draft.add_blank(); | ||
| 833 | - draft.add_blank(); | ||
| 834 | - draft.add_blank(); | ||
| 835 | - draft.files[1].1.name = "b.txt".into(); | ||
| 836 | - draft.remove(0); | ||
| 837 | - let numbers: Vec<usize> = draft.slots().iter().map(|s| s.number).collect(); | ||
| 838 | - assert_eq!(numbers, vec![1, 2], "remove: numbers are kept"); | ||
| 839 | - assert_eq!( | ||
| 840 | - draft.slots()[0].name, | ||
| 841 | - "b.txt", | ||
| 842 | - "remove: the other card's name" | ||
| 843 | - ); | ||
| 844 | - | ||
| 845 | - let add = form(&[("op", "add"), ("name_0", "a")]); | ||
| 846 | - let mut draft = Draft::from_form(&add); | ||
| 847 | - assert_eq!(apply_slot_step(&mut draft, &add), Some(1), "add click: tab"); | ||
| 848 | - assert_eq!(draft.slots().len(), 2, "add click: two cards"); | ||
| 849 | - let remove = form(&[("remove", "1"), ("name_0", "a"), ("name_1", "")]); | ||
| 850 | - let mut draft = Draft::from_form(&remove); | ||
| 851 | - assert_eq!( | ||
| 852 | - apply_slot_step(&mut draft, &remove), | ||
| 853 | - Some(0), | ||
| 854 | - "remove click: tab" | ||
| 855 | - ); | ||
| 856 | - assert_eq!(draft.slots().len(), 1, "remove click: one card"); | ||
| 857 | - assert_eq!( | ||
| 858 | - apply_slot_step(&mut Draft::blank(), &form(&[("title", "t")])), | ||
| 859 | - None, | ||
| 860 | - "save: not a card step" | ||
| 861 | - ); | ||
| 862 | - | ||
| 863 | - let mut draft = Draft::blank(); | ||
| 864 | - let add = form(&[("op", "add"), ("name_0", "a")]); | ||
| 865 | - assert_eq!( | ||
| 866 | - apply_slot_step(&mut draft, &add), | ||
| 867 | - Some(0), | ||
| 868 | - "add shows: first add" | ||
| 869 | - ); | ||
| 870 | - assert_eq!( | ||
| 871 | - apply_slot_step(&mut draft, &add), | ||
| 872 | - Some(1), | ||
| 873 | - "add shows: new last" | ||
| 874 | - ); | ||
| 875 | - assert_eq!(draft.slots().len(), 2, "add shows: two cards"); | ||
| 876 | - | ||
| 877 | - let mut draft = Draft::blank(); | ||
| 878 | - for _ in 0..3 { | ||
| 879 | - draft.add_blank(); | ||
| 880 | - } | ||
| 881 | - let remove = form(&[("remove", "2")]); | ||
| 882 | - assert_eq!( | ||
| 883 | - apply_slot_step(&mut draft, &remove), | ||
| 884 | - Some(1), | ||
| 885 | - "remove shows: before" | ||
| 886 | - ); | ||
| 887 | - let remove = form(&[("remove", "0")]); | ||
| 888 | - assert_eq!( | ||
| 889 | - apply_slot_step(&mut draft, &remove), | ||
| 890 | - Some(0), | ||
| 891 | - "remove shows: first" | ||
| 892 | - ); | ||
| 893 | - | ||
| 894 | - let mut draft = Draft::blank(); | ||
| 895 | - for _ in 0..3 { | ||
| 896 | - draft.add_blank(); | ||
| 897 | - } | ||
| 898 | - let numbers: Vec<usize> = draft.slots().iter().map(|s| s.number).collect(); | ||
| 899 | - assert_eq!(numbers, vec![0, 1, 2], "failed save: three cards"); | ||
| 900 | - assert_eq!( | ||
| 901 | - posted_tab(&draft, &form(&[("tab", "2")])), | ||
| 902 | - 2, | ||
| 903 | - "failed save: posted tab" | ||
| 904 | - ); | ||
| 905 | - assert_eq!( | ||
| 906 | - posted_tab(&draft, &form(&[("tab", "9")])), | ||
| 907 | - 0, | ||
| 908 | - "failed save: unknown tab" | ||
| 909 | - ); | ||
| 910 | - assert_eq!(posted_tab(&draft, &form(&[])), 0, "failed save: no tab"); | ||
| 911 | - } | ||
| 912 | -} | ||
crates/forge-web-account/src/pages/snippets_live.rsdeleted+0 -106
| @@ -1,106 +0,0 @@ | |||
| 1 | -use forge_core::store::Store; | ||
| 2 | -use forge_core::store::snippets::{Snippet, SnippetSummary}; | ||
| 3 | -use topcoat::Result; | ||
| 4 | -use topcoat::context::{Cx, context}; | ||
| 5 | -use topcoat::router::response::Response; | ||
| 6 | -use topcoat::router::{path_param, route}; | ||
| 7 | - | ||
| 8 | -use crate::auth::current_user; | ||
| 9 | -use crate::live::{Topic, stream_changes}; | ||
| 10 | -use crate::pages::snippets::readable; | ||
| 11 | -use crate::state::AppState; | ||
| 12 | - | ||
| 13 | -path_param!(id); | ||
| 14 | - | ||
| 15 | -pub fn list_live_url() -> &'static str { | ||
| 16 | - "/snippets/events" | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | -pub fn item_live_url(snippet_id: &str) -> String { | ||
| 20 | - format!("/snippets/{snippet_id}/events") | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -pub fn bump_snippet(state: &AppState, snippet_id: &str) { | ||
| 24 | - state.live.bump(&Topic::Snippets); | ||
| 25 | - state.live.bump(&Topic::Snippet(snippet_id.to_owned())); | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -async fn list_fingerprint(store: &Store, viewer_id: Option<&str>) -> Result<String> { | ||
| 29 | - let summaries: Vec<SnippetSummary> = store.list_snippets(viewer_id).await?; | ||
| 30 | - Ok(summaries | ||
| 31 | - .iter() | ||
| 32 | - .map(|s| { | ||
| 33 | - format!( | ||
| 34 | - "{} {} {} {} {} {}", | ||
| 35 | - s.id, | ||
| 36 | - s.title, | ||
| 37 | - s.owner_name, | ||
| 38 | - s.visibility.as_str(), | ||
| 39 | - s.updated_at, | ||
| 40 | - s.file_count | ||
| 41 | - ) | ||
| 42 | - }) | ||
| 43 | - .collect::<Vec<_>>() | ||
| 44 | - .join("\n")) | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | -fn snippet_fingerprint(viewer_id: Option<&str>, snippet: Option<Snippet>) -> String { | ||
| 48 | - match snippet { | ||
| 49 | - Some(s) if s.is_visible_to(viewer_id) => { | ||
| 50 | - let files: Vec<String> = s | ||
| 51 | - .files | ||
| 52 | - .iter() | ||
| 53 | - .map(|f| format!("{}\n{}", f.name, f.content)) | ||
| 54 | - .collect(); | ||
| 55 | - format!( | ||
| 56 | - "{}\n{}\n{}\n{}\n{}\n{}", | ||
| 57 | - s.title, | ||
| 58 | - s.description, | ||
| 59 | - s.owner_name, | ||
| 60 | - s.visibility.as_str(), | ||
| 61 | - s.updated_at, | ||
| 62 | - files.join("\n") | ||
| 63 | - ) | ||
| 64 | - } | ||
| 65 | - _ => "gone".to_owned(), | ||
| 66 | - } | ||
| 67 | -} | ||
| 68 | - | ||
| 69 | -#[route(GET "/snippets/events")] | ||
| 70 | -async fn snippets_events(cx: &Cx) -> Result<Response> { | ||
| 71 | - let viewer = current_user(cx).await?; | ||
| 72 | - let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone()); | ||
| 73 | - let state = context::<AppState>(cx); | ||
| 74 | - let store = state.store.clone(); | ||
| 75 | - stream_changes(cx, &state.live, &[Topic::Snippets], move || { | ||
| 76 | - let store = store.clone(); | ||
| 77 | - let viewer_id = viewer_id.clone(); | ||
| 78 | - async move { list_fingerprint(&store, viewer_id.as_deref()).await } | ||
| 79 | - }) | ||
| 80 | - .await | ||
| 81 | -} | ||
| 82 | - | ||
| 83 | -#[route(GET "/snippets/{id}/events")] | ||
| 84 | -async fn snippet_events(cx: &Cx) -> Result<Response> { | ||
| 85 | - let snippet_id = id(cx).to_owned(); | ||
| 86 | - let viewer = current_user(cx).await?; | ||
| 87 | - let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone()); | ||
| 88 | - readable(cx, viewer_id.as_deref(), &snippet_id).await?; | ||
| 89 | - let state = context::<AppState>(cx); | ||
| 90 | - let store = state.store.clone(); | ||
| 91 | - stream_changes( | ||
| 92 | - cx, | ||
| 93 | - &state.live, | ||
| 94 | - &[Topic::Snippet(snippet_id.clone())], | ||
| 95 | - move || { | ||
| 96 | - let store = store.clone(); | ||
| 97 | - let viewer_id = viewer_id.clone(); | ||
| 98 | - let snippet_id = snippet_id.clone(); | ||
| 99 | - async move { | ||
| 100 | - let snippet = store.get_snippet(&snippet_id).await?; | ||
| 101 | - Ok(snippet_fingerprint(viewer_id.as_deref(), snippet)) | ||
| 102 | - } | ||
| 103 | - }, | ||
| 104 | - ) | ||
| 105 | - .await | ||
| 106 | -} | ||
crates/forge-web-app/src/live.rsmodified+0 -2
| @@ -27,8 +27,6 @@ pub enum Topic { | |||
| 27 | ReviewRequests(String), | 27 | ReviewRequests(String), |
| 28 | Imports(String), | 28 | Imports(String), |
| 29 | Explore, | 29 | Explore, |
| 30 | - Snippets, | ||
| 31 | - Snippet(String), | ||
| 32 | Org(String), | 30 | Org(String), |
| 33 | AdminUsers, | 31 | AdminUsers, |
| 34 | AdminUser(String), | 32 | AdminUser(String), |
crates/forge-web-app/src/raw/mod.rsmodified+0 -6
| @@ -1,5 +1,4 @@ | |||
| 1 | pub mod media; | 1 | pub mod media; |
| 2 | -pub mod snippet_raw; | ||
| 3 | 2 | ||
| 4 | use std::path::{Path, PathBuf}; | 3 | use std::path::{Path, PathBuf}; |
| 5 | use std::process::Stdio; | 4 | use std::process::Stdio; |
| @@ -102,11 +101,6 @@ pub fn router(state: AppState) -> Router { | |||
| 102 | "/{owner}/{repo}/-/media/{*rest}", | 101 | "/{owner}/{repo}/-/media/{*rest}", |
| 103 | crate::raw::media::media_file, | 102 | crate::raw::media::media_file, |
| 104 | )) | 103 | )) |
| 105 | - .route(RouteFn::new( | ||
| 106 | - vec![Method::GET, Method::HEAD], | ||
| 107 | - "/-/snippets/{id}/{*rest}", | ||
| 108 | - crate::raw::snippet_raw::snippet_file, | ||
| 109 | - )) | ||
| 110 | .route(RouteFn::new(Method::GET, "/healthz", healthz)) | 104 | .route(RouteFn::new(Method::GET, "/healthz", healthz)) |
| 111 | .with(Compression::disable()) | 105 | .with(Compression::disable()) |
| 112 | .with(state) | 106 | .with(state) |
crates/forge-web-app/src/raw/snippet_raw.rsdeleted+0 -126
| @@ -1,126 +0,0 @@ | |||
| 1 | -use forge_core::raw_token::verify_raw; | ||
| 2 | -use forge_core::store::snippets::{Snippet, SnippetVisibility}; | ||
| 3 | -use sha2::{Digest, Sha256}; | ||
| 4 | -use topcoat::context::{Cx, context}; | ||
| 5 | -use topcoat::router::request::{headers, method}; | ||
| 6 | -use topcoat::router::response::Response; | ||
| 7 | -use topcoat::router::{ | ||
| 8 | - Body, Method, RouteFuture, StatusCode, header, parse_query_params, path_param_segment, | ||
| 9 | - path_param_segments, | ||
| 10 | -}; | ||
| 11 | - | ||
| 12 | -use crate::raw::{ | ||
| 13 | - CACHE_NONE, CACHE_PRIVATE, CACHE_PUBLIC, Meta, TEXT, TokenQuery, encode_path, finish, now_unix, | ||
| 14 | - plain, signed_url, | ||
| 15 | -}; | ||
| 16 | -use crate::state::AppState; | ||
| 17 | - | ||
| 18 | -const MARKDOWN: &str = "text/markdown; charset=utf-8"; | ||
| 19 | -const JSON: &str = "application/json; charset=utf-8"; | ||
| 20 | - | ||
| 21 | -pub fn snippet_raw_url(state: &AppState, snippet: &Snippet, file: &str) -> String { | ||
| 22 | - let encoded = format!( | ||
| 23 | - "-/snippets/{}/{}", | ||
| 24 | - encode_path(&snippet.id), | ||
| 25 | - encode_path(file) | ||
| 26 | - ); | ||
| 27 | - signed_url( | ||
| 28 | - state, | ||
| 29 | - &encoded, | ||
| 30 | - &snippet.id, | ||
| 31 | - snippet.visibility == SnippetVisibility::Private, | ||
| 32 | - ) | ||
| 33 | -} | ||
| 34 | - | ||
| 35 | -pub fn snippet_file(cx: &Cx, _body: Body) -> RouteFuture<'_> { | ||
| 36 | - Box::pin(async move { Ok(serve(cx).await) }) | ||
| 37 | -} | ||
| 38 | - | ||
| 39 | -fn content_type(file_name: &str) -> &'static str { | ||
| 40 | - match file_name | ||
| 41 | - .rsplit_once('.') | ||
| 42 | - .map(|(_, ext)| ext.to_ascii_lowercase()) | ||
| 43 | - .as_deref() | ||
| 44 | - { | ||
| 45 | - Some("md" | "markdown") => MARKDOWN, | ||
| 46 | - Some("json") => JSON, | ||
| 47 | - _ => TEXT, | ||
| 48 | - } | ||
| 49 | -} | ||
| 50 | - | ||
| 51 | -async fn serve(cx: &Cx) -> Response { | ||
| 52 | - let state = context::<AppState>(cx).clone(); | ||
| 53 | - let id = path_param_segment(cx, "id").to_owned(); | ||
| 54 | - let segments: Vec<&str> = path_param_segments(cx, "rest").collect(); | ||
| 55 | - let [name] = segments.as_slice() else { | ||
| 56 | - return plain(StatusCode::NOT_FOUND, CACHE_NONE, None); | ||
| 57 | - }; | ||
| 58 | - let name = (*name).to_owned(); | ||
| 59 | - let is_head = method(cx) == Method::HEAD; | ||
| 60 | - let token = parse_query_params::<TokenQuery>(cx) | ||
| 61 | - .ok() | ||
| 62 | - .and_then(|query| query.token); | ||
| 63 | - let if_none_match = headers(cx) | ||
| 64 | - .get(header::IF_NONE_MATCH) | ||
| 65 | - .and_then(|v| v.to_str().ok()) | ||
| 66 | - .map(str::to_owned); | ||
| 67 | - | ||
| 68 | - let snippet = match state.store.get_snippet(&id).await { | ||
| 69 | - Ok(Some(snippet)) => snippet, | ||
| 70 | - Ok(None) => return plain(StatusCode::NOT_FOUND, CACHE_NONE, None), | ||
| 71 | - Err(e) => { | ||
| 72 | - tracing::error!(error = %e, "snippet raw: lookup failed"); | ||
| 73 | - return plain(StatusCode::INTERNAL_SERVER_ERROR, CACHE_NONE, None); | ||
| 74 | - } | ||
| 75 | - }; | ||
| 76 | - let cache = match snippet.visibility { | ||
| 77 | - SnippetVisibility::Public => CACHE_PUBLIC, | ||
| 78 | - SnippetVisibility::Unlisted => CACHE_PRIVATE, | ||
| 79 | - SnippetVisibility::Private => { | ||
| 80 | - let valid = token | ||
| 81 | - .as_deref() | ||
| 82 | - .is_some_and(|t| verify_raw(&state.key, t, &snippet.id, now_unix())); | ||
| 83 | - if !valid { | ||
| 84 | - return plain(StatusCode::NOT_FOUND, CACHE_NONE, None); | ||
| 85 | - } | ||
| 86 | - CACHE_PRIVATE | ||
| 87 | - } | ||
| 88 | - }; | ||
| 89 | - | ||
| 90 | - let Some(file) = snippet.file(&name) else { | ||
| 91 | - return plain(StatusCode::NOT_FOUND, CACHE_NONE, None); | ||
| 92 | - }; | ||
| 93 | - let etag = hex::encode(Sha256::digest(file.content.as_bytes())); | ||
| 94 | - let quoted = format!("\"{etag}\""); | ||
| 95 | - if if_none_match | ||
| 96 | - .as_deref() | ||
| 97 | - .is_some_and(|value| super::etag_matches(value, "ed)) | ||
| 98 | - { | ||
| 99 | - return finish(StatusCode::NOT_MODIFIED, Body::empty(), &etag, cache, None); | ||
| 100 | - } | ||
| 101 | - | ||
| 102 | - let meta = Meta { | ||
| 103 | - content_type: content_type(&name), | ||
| 104 | - attachment: false, | ||
| 105 | - len: file.content.len() as u64, | ||
| 106 | - }; | ||
| 107 | - let body = if is_head { | ||
| 108 | - Body::empty() | ||
| 109 | - } else { | ||
| 110 | - Body::from(bytes::Bytes::from(file.content.clone().into_bytes())) | ||
| 111 | - }; | ||
| 112 | - finish(StatusCode::OK, body, &etag, cache, Some(meta)) | ||
| 113 | -} | ||
| 114 | - | ||
| 115 | -#[cfg(test)] | ||
| 116 | -mod tests { | ||
| 117 | - use super::*; | ||
| 118 | - | ||
| 119 | - #[test] | ||
| 120 | - fn content_types_follow_extensions() { | ||
| 121 | - assert_eq!(content_type("notes.md"), MARKDOWN); | ||
| 122 | - assert_eq!(content_type("data.JSON"), JSON); | ||
| 123 | - assert_eq!(content_type("main.rs"), TEXT); | ||
| 124 | - assert_eq!(content_type("README"), TEXT); | ||
| 125 | - } | ||
| 126 | -} | ||
crates/forge-web-app/src/views/mod.rsmodified+0 -22
| @@ -36,7 +36,6 @@ use crate::i18n::admin::{self as ad, K as AK}; | |||
| 36 | use crate::i18n::authoring::{self as au, K as AuK}; | 36 | use crate::i18n::authoring::{self as au, K as AuK}; |
| 37 | use crate::i18n::browse as br; | 37 | use crate::i18n::browse as br; |
| 38 | use crate::i18n::code::{self as g, K}; | 38 | use crate::i18n::code::{self as g, K}; |
| 39 | -use crate::i18n::community::{self as cm, K as CK}; | ||
| 40 | use crate::i18n::link::{self as lk, K as LinkKey}; | 39 | use crate::i18n::link::{self as lk, K as LinkKey}; |
| 41 | use crate::i18n::migrate::{self as mg, K as MGK}; | 40 | use crate::i18n::migrate::{self as mg, K as MGK}; |
| 42 | use crate::i18n::misc::{self as mi, K as MK}; | 41 | use crate::i18n::misc::{self as mi, K as MK}; |
| @@ -98,7 +97,6 @@ const TOP_LEVEL_PAGES: &[&str] = &[ | |||
| 98 | "settings", | 97 | "settings", |
| 99 | "admin", | 98 | "admin", |
| 100 | "new", | 99 | "new", |
| 101 | - "snippets", | ||
| 102 | "login", | 100 | "login", |
| 103 | "logout", | 101 | "logout", |
| 104 | "register", | 102 | "register", |
| @@ -180,25 +178,6 @@ fn path_segments(lang: Lang, path: &str, title: &str) -> Vec<(String, Option<Str | |||
| 180 | .collect::<Vec<_>>() | 178 | .collect::<Vec<_>>() |
| 181 | .as_slice() | 179 | .as_slice() |
| 182 | { | 180 | { |
| 183 | - ["snippets", id, rest @ ..] => { | ||
| 184 | - let mut segments = vec![( | ||
| 185 | - cm::t(lang, CK::Snippets).to_owned(), | ||
| 186 | - Some("/snippets".to_owned()), | ||
| 187 | - )]; | ||
| 188 | - match rest { | ||
| 189 | - [] => segments.push((title.to_owned(), None)), | ||
| 190 | - [.., last] => { | ||
| 191 | - let back = if *last == "revisions" { | ||
| 192 | - title.to_owned() | ||
| 193 | - } else { | ||
| 194 | - s(lang, "Snippet", "Parçacık").to_owned() | ||
| 195 | - }; | ||
| 196 | - segments.push((back, Some(format!("/snippets/{}", enc(id))))); | ||
| 197 | - segments.push((step_label(lang, last), None)); | ||
| 198 | - } | ||
| 199 | - } | ||
| 200 | - return segments; | ||
| 201 | - } | ||
| 202 | ["org", name, rest @ ..] if *name != "new" && !rest.is_empty() => { | 181 | ["org", name, rest @ ..] if *name != "new" && !rest.is_empty() => { |
| 203 | let page = titled.unwrap_or_else(|| step_label(lang, rest[rest.len() - 1])); | 182 | let page = titled.unwrap_or_else(|| step_label(lang, rest[rest.len() - 1])); |
| 204 | return vec![((*name).to_owned(), Some(user_href(name))), (page, None)]; | 183 | return vec![((*name).to_owned(), Some(user_href(name))), (page, None)]; |
| @@ -841,7 +820,6 @@ pub fn profile_items( | |||
| 841 | tab("repositories", o::t(lang, OK::Repositories)), | 820 | tab("repositories", o::t(lang, OK::Repositories)), |
| 842 | ]; | 821 | ]; |
| 843 | if !is_org { | 822 | if !is_org { |
| 844 | - items.push(tab("snippets", cm::t(lang, CK::Snippets))); | ||
| 845 | items.push(tab("stars", o::t(lang, OK::TabStars))); | 823 | items.push(tab("stars", o::t(lang, OK::TabStars))); |
| 846 | } | 824 | } |
| 847 | if own_profile { | 825 | if own_profile { |
crates/forge-web-base/src/i18n/audit_names.rsmodified+0 -11
| @@ -122,12 +122,6 @@ pub fn action_name(lang: Lang, action: &str) -> Option<&'static str> { | |||
| 122 | ("server_settings_updated", Lang::Tr) => Some("Sunucu ayarları güncellendi"), | 122 | ("server_settings_updated", Lang::Tr) => Some("Sunucu ayarları güncellendi"), |
| 123 | ("server_restarted", Lang::En) => Some("Server restarted"), | 123 | ("server_restarted", Lang::En) => Some("Server restarted"), |
| 124 | ("server_restarted", Lang::Tr) => Some("Sunucu yeniden başlatıldı"), | 124 | ("server_restarted", Lang::Tr) => Some("Sunucu yeniden başlatıldı"), |
| 125 | - ("snippet_created", Lang::En) => Some("Snippet created"), | ||
| 126 | - ("snippet_created", Lang::Tr) => Some("Parçacık oluşturuldu"), | ||
| 127 | - ("snippet_updated", Lang::En) => Some("Snippet updated"), | ||
| 128 | - ("snippet_updated", Lang::Tr) => Some("Parçacık güncellendi"), | ||
| 129 | - ("snippet_deleted", Lang::En) => Some("Snippet deleted"), | ||
| 130 | - ("snippet_deleted", Lang::Tr) => Some("Parçacık silindi"), | ||
| 131 | ("org_created", Lang::En) => Some("Organization created"), | 125 | ("org_created", Lang::En) => Some("Organization created"), |
| 132 | ("org_created", Lang::Tr) => Some("Kuruluş oluşturuldu"), | 126 | ("org_created", Lang::Tr) => Some("Kuruluş oluşturuldu"), |
| 133 | ("org_deleted", Lang::En) => Some("Organization deleted"), | 127 | ("org_deleted", Lang::En) => Some("Organization deleted"), |
| @@ -226,8 +220,6 @@ pub fn target_kind_name(lang: Lang, kind: &str) -> Option<&'static str> { | |||
| 226 | ("server", Lang::Tr) => Some("sunucu"), | 220 | ("server", Lang::Tr) => Some("sunucu"), |
| 227 | ("session", Lang::En) => Some("session"), | 221 | ("session", Lang::En) => Some("session"), |
| 228 | ("session", Lang::Tr) => Some("oturum"), | 222 | ("session", Lang::Tr) => Some("oturum"), |
| 229 | - ("snippet", Lang::En) => Some("snippet"), | ||
| 230 | - ("snippet", Lang::Tr) => Some("parçacık"), | ||
| 231 | ("ssh_key", Lang::En) => Some("SSH key"), | 223 | ("ssh_key", Lang::En) => Some("SSH key"), |
| 232 | ("ssh_key", Lang::Tr) => Some("SSH anahtarı"), | 224 | ("ssh_key", Lang::Tr) => Some("SSH anahtarı"), |
| 233 | ("team", Lang::En) => Some("team"), | 225 | ("team", Lang::En) => Some("team"), |
| @@ -426,9 +418,6 @@ mod tests { | |||
| 426 | "mail_test_queued", | 418 | "mail_test_queued", |
| 427 | "server_settings_updated", | 419 | "server_settings_updated", |
| 428 | "server_restarted", | 420 | "server_restarted", |
| 429 | - "snippet_created", | ||
| 430 | - "snippet_updated", | ||
| 431 | - "snippet_deleted", | ||
| 432 | "org_created", | 421 | "org_created", |
| 433 | "org_deleted", | 422 | "org_deleted", |
| 434 | "org_settings_updated", | 423 | "org_settings_updated", |
crates/forge-web-base/src/i18n/community.rsmodified+0 -72
| @@ -12,34 +12,8 @@ strings! { | |||
| 12 | 12 | ||
| 13 | Home => "Home", "Ana sayfa"; | 13 | Home => "Home", "Ana sayfa"; |
| 14 | 14 | ||
| 15 | - Snippets => "Snippets", "Parçacıklar"; | ||
| 16 | - NewSnippet => "New snippet", "Yeni parçacık"; | ||
| 17 | - NoSnippets => "No snippets to show.", "Gösterilecek parçacık yok."; | ||
| 18 | - Visibility => "Visibility", "Görünürlük"; | ||
| 19 | VisibilityPublic => "Public", "Herkese açık"; | 15 | VisibilityPublic => "Public", "Herkese açık"; |
| 20 | - VisibilityUnlisted => "Unlisted", "Listelenmez"; | ||
| 21 | VisibilityPrivate => "Private", "Özel"; | 16 | VisibilityPrivate => "Private", "Özel"; |
| 22 | - PublicOption => "Public: listed on /snippets", "Herkese açık: /snippets üzerinde listelenir"; | ||
| 23 | - UnlistedOption => "Unlisted: anyone with the link", "Listelenmez: bağlantıya sahip herkes"; | ||
| 24 | - PrivateOption => "Private: only you", "Özel: yalnızca siz"; | ||
| 25 | - FileLabel => "File ", "Dosya "; | ||
| 26 | - FileNamePlaceholder => "file name, for example notes.md", "dosya adı, örneğin notes.md"; | ||
| 27 | - FileName => "File name", "Dosya adı"; | ||
| 28 | - FileContents => "File contents", "Dosya içeriği"; | ||
| 29 | - Untitled => "untitled", "adsız"; | ||
| 30 | - Files => "Files", "Dosyalar"; | ||
| 31 | - SnippetTitlePlaceholder => "Snippet title", "Parçacık başlığı"; | ||
| 32 | - DescriptionOptional => "Description (optional)", "Açıklama (isteğe bağlı)"; | ||
| 33 | - AddFile => "Add file", "Dosya ekle"; | ||
| 34 | - RemoveFile => "Remove file", "Dosyayı kaldır"; | ||
| 35 | - SaveSnippet => "Save snippet", "Parçacığı kaydet"; | ||
| 36 | - EditSnippet => "Edit snippet", "Parçacığı düzenle"; | ||
| 37 | - Raw => "Raw", "Ham"; | ||
| 38 | - Revisions => "Revisions", "Revizyonlar"; | ||
| 39 | - BackToSnippet => "Back to the snippet", "Parçacığa dön"; | ||
| 40 | - NoRevisions => "No revisions.", "Revizyon yok."; | ||
| 41 | - RevisionLabel => "Revision ", "Revizyon "; | ||
| 42 | - ChooseVisibility => "Choose a visibility.", "Bir görünürlük seçin."; | ||
| 43 | } | 17 | } |
| 44 | 18 | ||
| 45 | pub fn comments_count(lang: Lang, count: i64) -> String { | 19 | pub fn comments_count(lang: Lang, count: i64) -> String { |
| @@ -56,48 +30,6 @@ pub fn comment_login_lead(lang: Lang) -> &'static str { | |||
| 56 | } | 30 | } |
| 57 | } | 31 | } |
| 58 | 32 | ||
| 59 | -pub fn page_too_large(lang: Lang, max: usize) -> String { | ||
| 60 | - match lang { | ||
| 61 | - Lang::En => format!("The page is larger than {max} bytes."), | ||
| 62 | - Lang::Tr => format!("Sayfa {max} bayttan büyük."), | ||
| 63 | - } | ||
| 64 | -} | ||
| 65 | - | ||
| 66 | -pub fn updated_before(lang: Lang) -> &'static str { | ||
| 67 | - match lang { | ||
| 68 | - Lang::En => "updated ", | ||
| 69 | - Lang::Tr => "", | ||
| 70 | - } | ||
| 71 | -} | ||
| 72 | - | ||
| 73 | -pub fn updated_after(lang: Lang) -> &'static str { | ||
| 74 | - match lang { | ||
| 75 | - Lang::En => "", | ||
| 76 | - Lang::Tr => " güncellendi", | ||
| 77 | - } | ||
| 78 | -} | ||
| 79 | - | ||
| 80 | -pub fn files_count(lang: Lang, count: u64) -> String { | ||
| 81 | - match lang { | ||
| 82 | - Lang::En => format!("{count} {}", if count == 1 { "file" } else { "files" }), | ||
| 83 | - Lang::Tr => format!("{count} dosya"), | ||
| 84 | - } | ||
| 85 | -} | ||
| 86 | - | ||
| 87 | -pub fn files_limit(lang: Lang, count: usize, max_files: usize, max_mib: usize) -> String { | ||
| 88 | - match lang { | ||
| 89 | - Lang::En => format!("{count} of {max_files} files · {max_mib} MiB max"), | ||
| 90 | - Lang::Tr => format!("{count} / {max_files} dosya · en fazla {max_mib} MiB"), | ||
| 91 | - } | ||
| 92 | -} | ||
| 93 | - | ||
| 94 | -pub fn revisions_of(lang: Lang, title: &str) -> String { | ||
| 95 | - match lang { | ||
| 96 | - Lang::En => format!("Revisions of {title}"), | ||
| 97 | - Lang::Tr => format!("{title} revizyonları"), | ||
| 98 | - } | ||
| 99 | -} | ||
| 100 | - | ||
| 101 | #[cfg(test)] | 33 | #[cfg(test)] |
| 102 | mod tests { | 34 | mod tests { |
| 103 | use super::*; | 35 | use super::*; |
| @@ -117,8 +49,6 @@ mod tests { | |||
| 117 | .filter(|key| t(Lang::En, **key) != t(Lang::Tr, **key)) | 49 | .filter(|key| t(Lang::En, **key) != t(Lang::Tr, **key)) |
| 118 | .count(); | 50 | .count(); |
| 119 | assert!(differing >= 3, "only {differing} keys differ"); | 51 | assert!(differing >= 3, "only {differing} keys differ"); |
| 120 | - assert_eq!(t(Lang::Tr, K::NewSnippet), "Yeni parçacık"); | ||
| 121 | - assert_eq!(t(Lang::En, K::NewSnippet), "New snippet"); | ||
| 122 | } | 52 | } |
| 123 | 53 | ||
| 124 | #[test] | 54 | #[test] |
| @@ -127,7 +57,5 @@ mod tests { | |||
| 127 | assert_eq!(comments_count(Lang::En, 3), "3 comments"); | 57 | assert_eq!(comments_count(Lang::En, 3), "3 comments"); |
| 128 | assert_eq!(comments_count(Lang::Tr, 3), "3 yorum"); | 58 | assert_eq!(comments_count(Lang::Tr, 3), "3 yorum"); |
| 129 | assert_eq!(crate::i18n::page_label(Lang::Tr, 2), "Sayfa 2"); | 59 | assert_eq!(crate::i18n::page_label(Lang::Tr, 2), "Sayfa 2"); |
| 130 | - assert_eq!(files_count(Lang::En, 2), "2 files"); | ||
| 131 | - assert_eq!(files_count(Lang::En, 1), "1 file"); | ||
| 132 | } | 60 | } |
| 133 | } | 61 | } |
crates/forge-web/src/routes.snapmodified+0 -10
| @@ -75,13 +75,6 @@ page /settings/tokens Only([GET]) | |||
| 75 | page /settings/tokens Only([POST]) | 75 | page /settings/tokens Only([POST]) |
| 76 | page /setup Only([GET]) | 76 | page /setup Only([GET]) |
| 77 | page /setup Only([POST]) | 77 | page /setup Only([POST]) |
| 78 | -page /snippets Only([GET]) | ||
| 79 | -page /snippets/new Only([GET]) | ||
| 80 | -page /snippets/new Only([POST]) | ||
| 81 | -page /snippets/{id} Only([GET]) | ||
| 82 | -page /snippets/{id}/edit Only([GET]) | ||
| 83 | -page /snippets/{id}/edit Only([POST]) | ||
| 84 | -page /snippets/{id}/revisions Only([GET]) | ||
| 85 | page /verify/{token} Only([GET]) | 78 | page /verify/{token} Only([GET]) |
| 86 | page /verify/{token} Only([POST]) | 79 | page /verify/{token} Only([POST]) |
| 87 | page /{owner}/{repo} Only([GET]) | 80 | page /{owner}/{repo} Only([GET]) |
| @@ -325,9 +318,6 @@ route /settings/sessions/revoke Only([POST]) | |||
| 325 | route /settings/sessions/revoke-others Only([POST]) | 318 | route /settings/sessions/revoke-others Only([POST]) |
| 326 | route /settings/sessions/{id} Only([GET]) | 319 | route /settings/sessions/{id} Only([GET]) |
| 327 | route /settings/tokens/delete Only([POST]) | 320 | route /settings/tokens/delete Only([POST]) |
| 328 | -route /snippets/events Only([GET]) | ||
| 329 | -route /snippets/{id}/delete Only([POST]) | ||
| 330 | -route /snippets/{id}/events Only([GET]) | ||
| 331 | route /theme/custom.css Only([GET]) | 321 | route /theme/custom.css Only([GET]) |
| 332 | route /users/{username}/events Only([GET]) | 322 | route /users/{username}/events Only([GET]) |
| 333 | route /{owner}/{repo} Any | 323 | route /{owner}/{repo} Any |
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 | Not carried over: topics and LFS objects (the clone brings the code only), user emails and | 435 | Not carried over: topics and LFS objects (the clone brings the code only), user emails and |
| 436 | avatars (people arrive as plain user names, so the target creates placeholders you can re-map), | 436 | avatars (people arrive as plain user names, so the target creates placeholders you can re-map), |
| 437 | -team reviews, snippets, CI runs and secrets. | 437 | +team reviews, CI runs and secrets. |
docs/architecture.mdmodified+0 -1
| @@ -267,7 +267,6 @@ Pages update without a reload. A write that changes what a page shows calls `Liv | |||
| 267 | | Issues `/{owner}/{repo}/issues` and an issue | `/{owner}/{repo}/issues/live`, `/{owner}/{repo}/issues/{number}/live` | the repo issues (list, labels, milestones, tabs) and the one issue | | 267 | | Issues `/{owner}/{repo}/issues` and an issue | `/{owner}/{repo}/issues/live`, `/{owner}/{repo}/issues/{number}/live` | the repo issues (list, labels, milestones, tabs) and the one issue | |
| 268 | | Pull requests `/{owner}/{repo}/pulls` and a pull | `/{owner}/{repo}/pulls/events`, `/{owner}/{repo}/pulls/{number}/events` | the repo pull list, and the one pull (conversation, commits, files) | | 268 | | Pull requests `/{owner}/{repo}/pulls` and a pull | `/{owner}/{repo}/pulls/events`, `/{owner}/{repo}/pulls/{number}/events` | the repo pull list, and the one pull (conversation, commits, files) | |
| 269 | | Explore `/explore` | `/explore/events`, with the search, sort and page | the public listing | | 269 | | Explore `/explore` | `/explore/events`, with the search, sort and page | the public listing | |
| 270 | -| Snippets `/snippets`, a snippet and its revisions | `/snippets/events` (list), `/snippets/{id}/events` (one snippet) | the snippet list and the snippet; a private snippet answers 404 to everyone but its owner | | ||
| 271 | | Org members `/org/{org}/members` | `/org/{org}/members/events` | the org (members, roles, description) | | 270 | | Org members `/org/{org}/members` | `/org/{org}/members/events` | the org (members, roles, description) | |
| 272 | | Org teams `/org/{org}/teams` | `/org/{org}/teams/events` | the org (teams and their coverage) | | 271 | | Org teams `/org/{org}/teams` | `/org/{org}/teams/events` | the org (teams and their coverage) | |
| 273 | | Org team `/org/{org}/teams/{team}` | `/org/{org}/teams/{team}/events` | the org (members, linked repos) and each linked repo (name, visibility) | | 272 | | Org team `/org/{org}/teams/{team}` | `/org/{org}/teams/{team}/events` | the org (members, linked repos) and each linked repo (name, visibility) | |
docs/backlog.mdmodified+0 -1
| @@ -86,7 +86,6 @@ Status: `[ ]` todo, `[~]` in progress, `[x]` done. | |||
| 86 | - [x] M1 mail core (lettre, outbox worker, admin mail settings) | 86 | - [x] M1 mail core (lettre, outbox worker, admin mail settings) |
| 87 | - [x] M2 mail flows (password reset, email verification, invites; notification emails move to M3) | 87 | - [x] M2 mail flows (password reset, email verification, invites; notification emails move to M3) |
| 88 | - [x] M3 notification emails (per-user opt-out on `/settings/notifications`, threaded by Message-ID) | 88 | - [x] M3 notification emails (per-user opt-out on `/settings/notifications`, threaded by Message-ID) |
| 89 | -- [x] S1 snippets | ||
| 90 | - [x] T1 theme and language preferences (dark mode toggle) | 89 | - [x] T1 theme and language preferences (dark mode toggle) |
| 91 | - [x] I18 i18n infrastructure (En/Tr) and the shell, auth and settings pages | 90 | - [x] I18 i18n infrastructure (En/Tr) and the shell, auth and settings pages |
| 92 | - [x] I18b remaining pages translated (11 per-group key modules in i18n/, Turkish review pass done) | 91 | - [x] I18b remaining pages translated (11 per-group key modules in i18n/, Turkish review pass done) |
docs/ui-language.mdmodified+2 -2
| @@ -72,7 +72,7 @@ no `margin-left:auto`, no `justify-content:space-between`, no second column at t | |||
| 72 | one), whatever it is made of: an `a.act`, a form's `button.act` or a reveal's `summary.act` in the head | 72 | one), whatever it is made of: an `a.act`, a form's `button.act` or a reveal's `summary.act` in the head |
| 73 | takes the pill's look, so no head shows a bare word beside a button. | 73 | takes the pill's look, so no head shows a bare word beside a button. |
| 74 | On a tabbed page the head's action follows the tab: a profile shows Edit profile on Overview, New | 74 | On a tabbed page the head's action follows the tab: a profile shows Edit profile on Overview, New |
| 75 | - repository on Repositories, New snippet on Snippets and New organization on Organizations, and the | 75 | + repository on Repositories and New organization on Organizations, and the |
| 76 | list itself carries no second "New ..." line under it. | 76 | list itself carries no second "New ..." line under it. |
| 77 | - **Facts**: a page that describes one thing (an account, an organization) lists it as `.sec.facts`: | 77 | - **Facts**: a page that describes one thing (an account, an organization) lists it as `.sec.facts`: |
| 78 | compact 34px lines of a `.key` on the label column, the `.val`, and the action for that fact on the | 78 | compact 34px lines of a `.key` on the label column, the `.val`, and the action for that fact on the |
| @@ -207,7 +207,7 @@ Turkish page shows no English, an English page no Turkish. | |||
| 207 | no sheet, row or scrolling list cuts it. | 207 | no sheet, row or scrolling list cuts it. |
| 208 | - A tab's own pages sit in its rail: the Security log is a Security rail item, not a page of its own. | 208 | - A tab's own pages sit in its rail: the Security log is a Security rail item, not a page of its own. |
| 209 | - No page is an orphan. A page that makes or shows something of yours (a new repository, an import, a | 209 | - No page is an orphan. A page that makes or shows something of yours (a new repository, an import, a |
| 210 | - snippet, a new organization) shows your profile tabs with the area it belongs to marked, and the inbox | 210 | + new organization) shows your profile tabs with the area it belongs to marked, and the inbox |
| 211 | pages (Notifications, Needs you, Review requests) share one rail, so a mouse reaches every neighbour. | 211 | pages (Notifications, Needs you, Review requests) share one rail, so a mouse reaches every neighbour. |
| 212 | - An action a server cannot carry out shows as unavailable: no "send again" when mail is not set up. | 212 | - An action a server cannot carry out shows as unavailable: no "send again" when mail is not set up. |
| 213 | - Avatars without an uploaded image are drawn in the page (a letter on a colour from the name), so a | 213 | - Avatars without an uploaded image are drawn in the page (a letter on a colour from the name), so a |
scripts/audit/seed.pymodified+0 -21
| @@ -389,27 +389,6 @@ def _(): | |||
| 389 | "body": "Draft notes.", "draft": True, "prerelease": True}).encode(), h) | 389 | "body": "Draft notes.", "draft": True, "prerelease": True}).encode(), h) |
| 390 | 390 | ||
| 391 | 391 | ||
| 392 | -@step("snippets") | ||
| 393 | -def _(): | ||
| 394 | - r = ok(admin.post("/snippets/new", {"title": "Backup cron", "description": "Nightly backup with restic", | ||
| 395 | - "visibility": "public", "name_0": "backup.sh", | ||
| 396 | - "content_0": "#!/bin/sh\nrestic backup /var/lib/forge\n", | ||
| 397 | - "name_1": "notes.md", "content_1": "# Notes\n\nRun at 03:00.\n"}), "snippet") | ||
| 398 | - m = re.search(r"/snippets/([A-Za-z0-9_-]+)", r.url or "") | ||
| 399 | - sid = m.group(1) if m and m.group(1) != "new" else None | ||
| 400 | - if not sid: | ||
| 401 | - m = re.findall(r'/snippets/([A-Za-z0-9_-]+)"', admin.get("/snippets").text) | ||
| 402 | - sid = next((x for x in m if x != "new"), None) | ||
| 403 | - seed["snippet_id"] = sid | ||
| 404 | - if sid: | ||
| 405 | - r = admin.get(f"/snippets/{sid}/edit") | ||
| 406 | - admin.post(f"/snippets/{sid}/edit", {"title": "Backup cron", "description": "Nightly backup with restic (edited)", | ||
| 407 | - "visibility": "public", "name_0": "backup.sh", | ||
| 408 | - "content_0": "#!/bin/sh\nset -eu\nrestic backup /var/lib/forge\n"}) | ||
| 409 | - other.post("/snippets/new", {"title": "fish prompt", "description": "", "visibility": "public", | ||
| 410 | - "name_0": "config.fish", "content_0": "set -g fish_greeting\n"}) | ||
| 411 | - | ||
| 412 | - | ||
| 413 | @step("organization, members and teams") | 392 | @step("organization, members and teams") |
| 414 | def _(): | 393 | def _(): |
| 415 | ok(admin.post("/org/new", {"name": ORG, "description": "The people building forge."}), "org") | 394 | ok(admin.post("/org/new", {"name": ORG, "description": "The people building forge."}), "org") |
scripts/audit/shoot.pymodified+1 -3
| @@ -403,7 +403,7 @@ def concrete(pat): | |||
| 403 | rest = pat | 403 | rest = pat |
| 404 | fill = {"{owner}": o, "{repo}": r, "{org}": s["org"], "{team}": s.get("team") or "core", | 404 | fill = {"{owner}": o, "{repo}": r, "{org}": s["org"], "{team}": s.get("team") or "core", |
| 405 | "{username}": o, "{token}": "expired-token-0000", "{user_id}": s.get("user_id"), | 405 | "{username}": o, "{token}": "expired-token-0000", "{user_id}": s.get("user_id"), |
| 406 | - "{id}": s.get("snippet_id"), "{release_id}": s.get("release_id"), | 406 | + "{release_id}": s.get("release_id"), |
| 407 | "{milestone_id}": s.get("milestone_id"), "{run_number}": s.get("run_number"), | 407 | "{milestone_id}": s.get("milestone_id"), "{run_number}": s.get("run_number"), |
| 408 | "{job_id}": s.get("job_id"), "{oid}": s.get("head_oid"), "{tag}": "v0.2.0", | 408 | "{job_id}": s.get("job_id"), "{oid}": s.get("head_oid"), "{tag}": "v0.2.0", |
| 409 | "{hook_id}": s.get("hook_id"), "{mirror_id}": None, | 409 | "{hook_id}": s.get("hook_id"), "{mirror_id}": None, |
| @@ -488,8 +488,6 @@ def area_of(pat): | |||
| 488 | return "admin" | 488 | return "admin" |
| 489 | if p.startswith(("/settings", "/notifications")): | 489 | if p.startswith(("/settings", "/notifications")): |
| 490 | return "settings" | 490 | return "settings" |
| 491 | - if p.startswith(("/snippets", "/gists")): | ||
| 492 | - return "snippets" | ||
| 493 | if p.startswith(("/orgs", "/{org}")) or p in ("/{username}", "/explore", "/search") or p.startswith("/{username}"): | 491 | if p.startswith(("/orgs", "/{org}")) or p in ("/{username}", "/explore", "/search") or p.startswith("/{username}"): |
| 494 | return "profile-orgs" | 492 | return "profile-orgs" |
| 495 | if "/actions" in p or "/ci" in p or "/runs" in p or "/runners" in p or "/artifacts" in p: | 493 | if "/actions" in p or "/ci" in p or "/runs" in p or "/runners" in p or "/artifacts" in p: |
style/_look.scssmodified+0 -1
| @@ -56,7 +56,6 @@ th, | |||
| 56 | .pin-card, | 56 | .pin-card, |
| 57 | .ci-side, | 57 | .ci-side, |
| 58 | .ci-main, | 58 | .ci-main, |
| 59 | -.snippet-form .snippet-files, | ||
| 60 | .readme { | 59 | .readme { |
| 61 | border-color: transparent; | 60 | border-color: transparent; |
| 62 | background: var(--surface); | 61 | background: var(--surface); |
style/_min.scssmodified+1 -2
| @@ -533,8 +533,7 @@ main label:not(.colour-choice, .find-opt, .choice > label):has(> input[type="rad | |||
| 533 | // Nothing here is a box: topics sit straight on the page. | 533 | // Nothing here is a box: topics sit straight on the page. |
| 534 | main[data-width="read"] .explore, | 534 | main[data-width="read"] .explore, |
| 535 | main[data-width="read"] .heat, | 535 | main[data-width="read"] .heat, |
| 536 | -main .lang-list, | 536 | +main .lang-list { |
| 537 | -main .snippet-files { | ||
| 538 | border: 0; | 537 | border: 0; |
| 539 | border-radius: 0; | 538 | border-radius: 0; |
| 540 | background: none; | 539 | background: none; |
style/_one_people.scssmodified+0 -247
| @@ -1,16 +1,3 @@ | |||
| 1 | -// people: page parts in the one page language (docs/ui-language.md). Tokens only. | ||
| 2 | -// Scoped to this area's pages: profile, organizations, explore, notifications and snippets. | ||
| 3 | - | ||
| 4 | -// Head: the avatar is a small round mark before the name, with no ring. A person's and an | ||
| 5 | -// organization's are the same 40px. | ||
| 6 | -.head-title > img.profile-avatar { | ||
| 7 | - order: -1; | ||
| 8 | - width: 40px; | ||
| 9 | - height: 40px; | ||
| 10 | - border: 0; | ||
| 11 | - background: none; | ||
| 12 | -} | ||
| 13 | - | ||
| 14 | // Contribution heatmap: it is one topic in the sheet, so it drops its own card. Its heading is the | 1 | // Contribution heatmap: it is one topic in the sheet, so it drops its own card. Its heading is the |
| 15 | // sheet's topic heading and its numbers are the page's text size. | 2 | // sheet's topic heading and its numbers are the page's text size. |
| 16 | .sheet .heat { | 3 | .sheet .heat { |
| @@ -66,7 +53,6 @@ | |||
| 66 | gap: 4px 14px; | 53 | gap: 4px 14px; |
| 67 | } | 54 | } |
| 68 | 55 | ||
| 69 | - | ||
| 70 | // A line of text under the tools row is a hint for the list, aligned with its rows. | 56 | // A line of text under the tools row is a hint for the list, aligned with its rows. |
| 71 | .sheet-tools + p { | 57 | .sheet-tools + p { |
| 72 | margin: 0; | 58 | margin: 0; |
| @@ -76,7 +62,6 @@ | |||
| 76 | line-height: 20px; | 62 | line-height: 20px; |
| 77 | } | 63 | } |
| 78 | 64 | ||
| 79 | - | ||
| 80 | // Notifications: a row is one flex line, the link takes the room and the tool sits at its right. | 65 | // Notifications: a row is one flex line, the link takes the room and the tool sits at its right. |
| 81 | // The icon is a dot, not a ring. | 66 | // The icon is a dot, not a ring. |
| 82 | .notif-row { | 67 | .notif-row { |
| @@ -117,89 +102,6 @@ | |||
| 117 | margin-left: calc(var(--label-w, 130px) + 16px); | 102 | margin-left: calc(var(--label-w, 130px) + 16px); |
| 118 | } | 103 | } |
| 119 | 104 | ||
| 120 | -// Snippets: the fields are the shared fields. The file editor is part of the form, its file tabs a | ||
| 121 | -// row of quiet tools on the controls' edge, and Save sits last on screen though it comes first in | ||
| 122 | -// the form, so Enter still saves. | ||
| 123 | -.snippet-form > button[type="submit"] { | ||
| 124 | - order: 1; | ||
| 125 | - margin-top: 6px; | ||
| 126 | -} | ||
| 127 | - | ||
| 128 | -.snippet-form .snippet-content { | ||
| 129 | - height: 240px; | ||
| 130 | -} | ||
| 131 | - | ||
| 132 | -.snippet-form > .snippet-files { | ||
| 133 | - display: flex; | ||
| 134 | - flex-direction: column; | ||
| 135 | - gap: 6px; | ||
| 136 | - margin-top: 8px; | ||
| 137 | - padding: 0; | ||
| 138 | - border: 0; | ||
| 139 | - border-radius: 0; | ||
| 140 | - background: none; | ||
| 141 | - box-shadow: none; | ||
| 142 | - overflow: visible; | ||
| 143 | - | ||
| 144 | - &:has(.snippet-name:focus, .snippet-content:focus) { | ||
| 145 | - border: 0; | ||
| 146 | - box-shadow: none; | ||
| 147 | - } | ||
| 148 | - | ||
| 149 | - > .snippet-tabbar, | ||
| 150 | - > .acts { | ||
| 151 | - margin-left: calc(var(--label-w) + 16px); | ||
| 152 | - } | ||
| 153 | - | ||
| 154 | - > .snippet-tabbar { | ||
| 155 | - display: flex; | ||
| 156 | - align-items: center; | ||
| 157 | - gap: 12px; | ||
| 158 | - padding: 0; | ||
| 159 | - border: 0; | ||
| 160 | - background: none; | ||
| 161 | - } | ||
| 162 | -} | ||
| 163 | - | ||
| 164 | -.snippet-form .snippet-tabs { | ||
| 165 | - display: flex; | ||
| 166 | - flex-wrap: wrap; | ||
| 167 | - gap: 4px; | ||
| 168 | -} | ||
| 169 | - | ||
| 170 | -.snippet-form .snippet-tab { | ||
| 171 | - display: inline-flex; | ||
| 172 | - align-items: center; | ||
| 173 | - height: 32px; | ||
| 174 | - margin: 0; | ||
| 175 | - padding: 0 14px; | ||
| 176 | - border: 0; | ||
| 177 | - border-radius: 16px; | ||
| 178 | - background: none; | ||
| 179 | - box-shadow: none; | ||
| 180 | - color: var(--muted); | ||
| 181 | - font-family: var(--mono); | ||
| 182 | - font-size: 13px; | ||
| 183 | - cursor: pointer; | ||
| 184 | -} | ||
| 185 | - | ||
| 186 | -.snippet-tab-radio:checked + .snippet-tab { | ||
| 187 | - background: var(--surface); | ||
| 188 | - box-shadow: 0 0 0 1px var(--border); | ||
| 189 | - color: var(--text); | ||
| 190 | - font-weight: 600; | ||
| 191 | -} | ||
| 192 | - | ||
| 193 | -.snippet-form .snippet-panel { | ||
| 194 | - display: flex; | ||
| 195 | - flex-direction: column; | ||
| 196 | - gap: 6px; | ||
| 197 | - min-width: 0; | ||
| 198 | - margin: 0; | ||
| 199 | - padding: 0; | ||
| 200 | - border: 0; | ||
| 201 | -} | ||
| 202 | - | ||
| 203 | // A notification is one line: its title whole, then the detail cut to the room left, then Mark read. | 105 | // A notification is one line: its title whole, then the detail cut to the room left, then Mark read. |
| 204 | .notif-row > .line { | 106 | .notif-row > .line { |
| 205 | display: flex; | 107 | display: flex; |
| @@ -234,29 +136,6 @@ | |||
| 234 | } | 136 | } |
| 235 | } | 137 | } |
| 236 | 138 | ||
| 237 | -.snippet-form .snippet-tab-add { | ||
| 238 | - width: auto; | ||
| 239 | - height: 30px; | ||
| 240 | - padding: 0 10px; | ||
| 241 | - border-radius: 12px; | ||
| 242 | - font-size: 14px; | ||
| 243 | -} | ||
| 244 | - | ||
| 245 | -.snippet-form .snippet-count { | ||
| 246 | - margin: 0; | ||
| 247 | -} | ||
| 248 | - | ||
| 249 | -.snippet-form .snippet-panel > .field + .field, | ||
| 250 | -.snippet-form .snippet-panel > .acts { | ||
| 251 | - margin-top: 6px; | ||
| 252 | -} | ||
| 253 | - | ||
| 254 | -.snippet-form .snippet-name, | ||
| 255 | -.snippet-form .snippet-content { | ||
| 256 | - font-family: var(--mono); | ||
| 257 | - font-size: 13.5px; | ||
| 258 | -} | ||
| 259 | - | ||
| 260 | // A phone stacks a notification: its line across the row, then Mark read under it on the same edge. | 139 | // A phone stacks a notification: its line across the row, then Mark read under it on the same edge. |
| 261 | @media (max-width: 700px) { | 140 | @media (max-width: 700px) { |
| 262 | .notif-row { | 141 | .notif-row { |
| @@ -279,129 +158,3 @@ | |||
| 279 | } | 158 | } |
| 280 | } | 159 | } |
| 281 | } | 160 | } |
| 282 | - | ||
| 283 | -@media (max-width: 700px) { | ||
| 284 | - .snippet-form > .snippet-files { | ||
| 285 | - > .snippet-tabbar { | ||
| 286 | - flex-wrap: wrap; | ||
| 287 | - margin-left: 0; | ||
| 288 | - } | ||
| 289 | - | ||
| 290 | - > .acts { | ||
| 291 | - margin-left: -10px; | ||
| 292 | - } | ||
| 293 | - } | ||
| 294 | -} | ||
| 295 | - | ||
| 296 | -// A snippet's file reads as a file page does: the code is the topic itself, not a box in it. | ||
| 297 | -.sheet > .snippet-file > pre.snippet-code { | ||
| 298 | - margin: 0; | ||
| 299 | - padding: 4px 0; | ||
| 300 | - border: 0; | ||
| 301 | - border-radius: 0; | ||
| 302 | - background: none; | ||
| 303 | -} | ||
| 304 | - | ||
| 305 | -.snippet-form .snippet-tabs { | ||
| 306 | - flex: 0 1 auto; | ||
| 307 | -} | ||
| 308 | - | ||
| 309 | -// A snippet's files are one row on the control column: the file chips, Add file, then how many of | ||
| 310 | -// how many, the way every control starts on the fields' edge. | ||
| 311 | -.snippet-form > .snippet-files { | ||
| 312 | - display: flex; | ||
| 313 | - flex-direction: row; | ||
| 314 | - flex-wrap: wrap; | ||
| 315 | - align-items: center; | ||
| 316 | - column-gap: 8px; | ||
| 317 | - row-gap: 6px; | ||
| 318 | - padding-left: calc(var(--label-w, 130px) + 16px); | ||
| 319 | - | ||
| 320 | - > .snippet-tabbar { | ||
| 321 | - display: contents; | ||
| 322 | - } | ||
| 323 | - | ||
| 324 | - .snippet-tabs { | ||
| 325 | - order: 1; | ||
| 326 | - margin: 0; | ||
| 327 | - padding: 0; | ||
| 328 | - } | ||
| 329 | - | ||
| 330 | - > .acts { | ||
| 331 | - order: 2; | ||
| 332 | - margin: 0; | ||
| 333 | - } | ||
| 334 | - | ||
| 335 | - .snippet-count { | ||
| 336 | - order: 3; | ||
| 337 | - margin: 0; | ||
| 338 | - } | ||
| 339 | - | ||
| 340 | - > fieldset { | ||
| 341 | - order: 4; | ||
| 342 | - flex: 1 1 100%; | ||
| 343 | - margin: 0 0 0 calc(-1 * (var(--label-w, 130px) + 16px)); | ||
| 344 | - } | ||
| 345 | - | ||
| 346 | - @media (max-width: 700px) { | ||
| 347 | - padding-left: 0; | ||
| 348 | - | ||
| 349 | - > fieldset { | ||
| 350 | - margin-left: 0; | ||
| 351 | - } | ||
| 352 | - } | ||
| 353 | -} | ||
| 354 | - | ||
| 355 | -// The files row reads like every field: its word in the label column, then the files as one | ||
| 356 | -// choice switch in the kit's own look, Add file and the count beside it. | ||
| 357 | -.snippet-form > .snippet-files { | ||
| 358 | - padding-left: 0; | ||
| 359 | - | ||
| 360 | - > .snippet-files-label { | ||
| 361 | - order: 0; | ||
| 362 | - flex: 0 0 var(--label-w, 130px); | ||
| 363 | - margin-right: 8px; | ||
| 364 | - color: var(--text); | ||
| 365 | - font-size: 15px; | ||
| 366 | - font-weight: 500; | ||
| 367 | - } | ||
| 368 | - | ||
| 369 | - .snippet-tabs { | ||
| 370 | - gap: 0; | ||
| 371 | - padding: 3px; | ||
| 372 | - border-radius: 19px; | ||
| 373 | - background: var(--surface-2); | ||
| 374 | - } | ||
| 375 | - | ||
| 376 | - .snippet-tab { | ||
| 377 | - height: 32px; | ||
| 378 | - padding: 0 16px; | ||
| 379 | - border-radius: 16px; | ||
| 380 | - line-height: 1; | ||
| 381 | - font-family: inherit; | ||
| 382 | - font-size: 14px; | ||
| 383 | - font-weight: 500; | ||
| 384 | - } | ||
| 385 | - | ||
| 386 | - .snippet-tab-radio:checked + .snippet-tab { | ||
| 387 | - background: var(--surface); | ||
| 388 | - box-shadow: 0 0 0 1px var(--border); | ||
| 389 | - color: var(--text); | ||
| 390 | - font-weight: 500; | ||
| 391 | - } | ||
| 392 | - | ||
| 393 | - .snippet-tab-radio:focus-visible + .snippet-tab { | ||
| 394 | - outline: 2px solid var(--focus); | ||
| 395 | - outline-offset: 1px; | ||
| 396 | - } | ||
| 397 | -} | ||
| 398 | - | ||
| 399 | -@media (max-width: 700px) { | ||
| 400 | - .snippet-form > .snippet-files > .snippet-files-label { | ||
| 401 | - flex-basis: 100%; | ||
| 402 | - } | ||
| 403 | -} | ||
| 404 | - | ||
| 405 | -.snippet-form > .snippet-files > fieldset { | ||
| 406 | - margin-left: 0; | ||
| 407 | -} | ||
style/main.scssmodified+1 -216
| @@ -2025,7 +2025,7 @@ code { | |||
| 2025 | } | 2025 | } |
| 2026 | 2026 | ||
| 2027 | // The sidebar side (appearance settings): the same segmented pill as the New repository | 2027 | // The sidebar side (appearance settings): the same segmented pill as the New repository |
| 2028 | -// visibility toggle (.segmented.snippet-segmented), sized to --control-h like the selects. | 2028 | +// visibility toggle, sized to --control-h like the selects. |
| 2029 | .side-picker { | 2029 | .side-picker { |
| 2030 | border: 0; | 2030 | border: 0; |
| 2031 | padding: 0; | 2031 | padding: 0; |
| @@ -5444,221 +5444,6 @@ button.ci-job-last { | |||
| 5444 | color: var(--muted); | 5444 | color: var(--muted); |
| 5445 | } | 5445 | } |
| 5446 | 5446 | ||
| 5447 | -// Editor: a console-style page. A header row (title, visibility, Save), then one document | ||
| 5448 | -// column: the title card, the file cards and a row with "Add file". 880px wide by default. The | ||
| 5449 | -// code area can be dragged wider; the form then grows with it, up to the page column's width. | ||
| 5450 | -.snippet-form { | ||
| 5451 | - display: flex; | ||
| 5452 | - flex-direction: column; | ||
| 5453 | - gap: 16px; | ||
| 5454 | - width: fit-content; | ||
| 5455 | - min-width: min(880px, 100%); | ||
| 5456 | - max-width: 100%; | ||
| 5457 | - | ||
| 5458 | - svg { | ||
| 5459 | - flex: none; | ||
| 5460 | - width: 16px; | ||
| 5461 | - height: 16px; | ||
| 5462 | - fill: none; | ||
| 5463 | - stroke: currentColor; | ||
| 5464 | - stroke-width: 2; | ||
| 5465 | - stroke-linecap: round; | ||
| 5466 | - stroke-linejoin: round; | ||
| 5467 | - } | ||
| 5468 | -} | ||
| 5469 | - | ||
| 5470 | -// Visibility: three icon-and-word segments in one 32px pill. The radios are hidden; the focus | ||
| 5471 | -// ring is drawn on the segment's text, and the long description is the segment's title. | ||
| 5472 | -.snippet-visibility { | ||
| 5473 | - min-width: 0; | ||
| 5474 | - margin: 0; | ||
| 5475 | - padding: 0; | ||
| 5476 | - border: 0; | ||
| 5477 | -} | ||
| 5478 | - | ||
| 5479 | - | ||
| 5480 | - | ||
| 5481 | - | ||
| 5482 | - | ||
| 5483 | -// Tab strip: the tabs scroll sideways inside it, the counter sits at the right end. | ||
| 5484 | -.snippet-tabbar { | ||
| 5485 | - display: flex; | ||
| 5486 | - flex-wrap: wrap; | ||
| 5487 | - align-items: stretch; | ||
| 5488 | - gap: 0 12px; | ||
| 5489 | - padding-right: 12px; | ||
| 5490 | - background: var(--surface-2); | ||
| 5491 | - // A long tab strip scrolls inside the card; it must not widen the form on its own. | ||
| 5492 | - contain: inline-size; | ||
| 5493 | -} | ||
| 5494 | - | ||
| 5495 | -.snippet-tabs { | ||
| 5496 | - display: flex; | ||
| 5497 | - align-items: flex-end; | ||
| 5498 | - padding-top: 6px; | ||
| 5499 | - flex: 1 1 auto; | ||
| 5500 | - min-width: 0; | ||
| 5501 | - max-width: 100%; | ||
| 5502 | - overflow-x: auto; | ||
| 5503 | - overflow-y: hidden; | ||
| 5504 | - padding-left: 6px; | ||
| 5505 | - scrollbar-width: thin; | ||
| 5506 | -} | ||
| 5507 | - | ||
| 5508 | -.snippet-count { | ||
| 5509 | - flex: none; | ||
| 5510 | - margin-left: auto; | ||
| 5511 | - align-self: center; | ||
| 5512 | - white-space: nowrap; | ||
| 5513 | - font-variant-numeric: tabular-nums; | ||
| 5514 | -} | ||
| 5515 | - | ||
| 5516 | -// The radio is hidden; the label is the tab. The focus ring is drawn on the label. | ||
| 5517 | -.snippet-tab-radio { | ||
| 5518 | - position: absolute; | ||
| 5519 | - width: 1px; | ||
| 5520 | - height: 1px; | ||
| 5521 | - margin: 0; | ||
| 5522 | - padding: 0; | ||
| 5523 | - border: 0; | ||
| 5524 | - opacity: 0; | ||
| 5525 | - outline: none; | ||
| 5526 | -} | ||
| 5527 | - | ||
| 5528 | -.snippet-form .snippet-tab { | ||
| 5529 | - flex: none; | ||
| 5530 | - display: inline-flex; | ||
| 5531 | - flex-direction: row; // the global label is a column; keep the text centred in the tab | ||
| 5532 | - justify-content: flex-start; | ||
| 5533 | - align-items: center; | ||
| 5534 | - gap: 0; | ||
| 5535 | - box-sizing: border-box; | ||
| 5536 | - max-width: 200px; | ||
| 5537 | - height: 30px; | ||
| 5538 | - margin: 0 1px; | ||
| 5539 | - padding: 0 12px; | ||
| 5540 | - line-height: 1; | ||
| 5541 | - border: 1px solid transparent; | ||
| 5542 | - border-bottom: 0; | ||
| 5543 | - border-radius: var(--radius-md) var(--radius-md) 0 0; | ||
| 5544 | - color: var(--muted); | ||
| 5545 | - font-family: var(--mono); | ||
| 5546 | - font-size: 0.8125rem; | ||
| 5547 | - white-space: nowrap; | ||
| 5548 | - overflow: hidden; | ||
| 5549 | - text-overflow: ellipsis; | ||
| 5550 | - cursor: pointer; | ||
| 5551 | - user-select: none; | ||
| 5552 | - | ||
| 5553 | - &:hover { | ||
| 5554 | - color: var(--text); | ||
| 5555 | - } | ||
| 5556 | -} | ||
| 5557 | - | ||
| 5558 | -.snippet-tab-radio:checked + .snippet-tab { | ||
| 5559 | - background: var(--surface); | ||
| 5560 | - border-color: var(--border); | ||
| 5561 | - box-shadow: inset 0 2px 0 var(--accent); | ||
| 5562 | - color: var(--text); | ||
| 5563 | -} | ||
| 5564 | - | ||
| 5565 | -.snippet-tab-radio:focus-visible + .snippet-tab { | ||
| 5566 | - outline: 2px solid var(--focus); | ||
| 5567 | - outline-offset: -2px; | ||
| 5568 | -} | ||
| 5569 | - | ||
| 5570 | -// "Add file" as a compact "+" at the end of the strip. | ||
| 5571 | -.snippet-form .snippet-tab-add { | ||
| 5572 | - flex: none; | ||
| 5573 | - display: inline-flex; | ||
| 5574 | - align-items: center; | ||
| 5575 | - justify-content: center; | ||
| 5576 | - align-self: flex-end; | ||
| 5577 | - width: 30px; | ||
| 5578 | - height: 30px; | ||
| 5579 | - margin: 0 0 0 4px; | ||
| 5580 | - padding: 0; | ||
| 5581 | - border: 0; | ||
| 5582 | - border-radius: var(--radius-md); | ||
| 5583 | - background: transparent; | ||
| 5584 | - color: var(--muted); | ||
| 5585 | - | ||
| 5586 | - &:hover { | ||
| 5587 | - background: var(--surface); | ||
| 5588 | - color: var(--text); | ||
| 5589 | - } | ||
| 5590 | - | ||
| 5591 | - &:focus-visible { | ||
| 5592 | - outline: none; | ||
| 5593 | - box-shadow: 0 0 0 2px var(--focus); | ||
| 5594 | - } | ||
| 5595 | -} | ||
| 5596 | - | ||
| 5597 | -// One panel per file: the name row, then the code area. Hidden unless its tab is checked. | ||
| 5598 | -.snippet-form .snippet-panel { | ||
| 5599 | - display: none; | ||
| 5600 | - min-width: 0; | ||
| 5601 | - margin: 0; | ||
| 5602 | - padding: 0; | ||
| 5603 | - border: 0; | ||
| 5604 | -} | ||
| 5605 | - | ||
| 5606 | - | ||
| 5607 | -.snippet-form .snippet-remove { | ||
| 5608 | - align-self: auto; | ||
| 5609 | - flex: none; | ||
| 5610 | - width: 28px; | ||
| 5611 | - height: 28px; | ||
| 5612 | - padding: 0; | ||
| 5613 | - justify-content: center; | ||
| 5614 | - border: 0; | ||
| 5615 | - border-radius: var(--radius-md); | ||
| 5616 | - background: transparent; | ||
| 5617 | - color: var(--muted); | ||
| 5618 | - | ||
| 5619 | - &:hover { | ||
| 5620 | - background: var(--surface-2); | ||
| 5621 | - color: var(--text); | ||
| 5622 | - } | ||
| 5623 | - | ||
| 5624 | - &:focus-visible { | ||
| 5625 | - outline: none; | ||
| 5626 | - box-shadow: 0 0 0 2px var(--focus); | ||
| 5627 | - } | ||
| 5628 | -} | ||
| 5629 | - | ||
| 5630 | - | ||
| 5631 | -// Each panel shows when its tab is checked. One rule per file slot (MAX_FILES in Rust). | ||
| 5632 | -@for $i from 0 through 9 { | ||
| 5633 | - .snippet-files:has(#snippet-tab-#{$i}:checked) .snippet-panel-#{$i} { | ||
| 5634 | - display: block; | ||
| 5635 | - } | ||
| 5636 | -} | ||
| 5637 | - | ||
| 5638 | -@media (max-width: 599px) { | ||
| 5639 | - .snippet-form .snippet-content { | ||
| 5640 | - resize: vertical; | ||
| 5641 | - } | ||
| 5642 | -} | ||
| 5643 | - | ||
| 5644 | -@media (max-width: 480px) { | ||
| 5645 | - | ||
| 5646 | -} | ||
| 5647 | - | ||
| 5648 | -.snippet-description { | ||
| 5649 | - color: var(--muted); | ||
| 5650 | -} | ||
| 5651 | - | ||
| 5652 | -.snippet-file { | ||
| 5653 | - margin-top: 16px; | ||
| 5654 | -} | ||
| 5655 | - | ||
| 5656 | -.snippet-code { | ||
| 5657 | - margin: 0; | ||
| 5658 | - overflow-x: auto; | ||
| 5659 | - padding: 12px; | ||
| 5660 | -} | ||
| 5661 | - | ||
| 5662 | // Sage redesign partials. Loaded last so they override the older rules above. | 5447 | // Sage redesign partials. Loaded last so they override the older rules above. |
| 5663 | @import "shell"; | 5448 | @import "shell"; |
| 5664 | @import "heatmap"; | 5449 | @import "heatmap"; |