| 331 | } |
| 332 | |
| 333 | func TestCanWrite(t *testing.T) { |
| 334 | tests := []struct { |
| 335 | name string |
| 336 | user *model.User |
| 337 | meta *model.Meta |
| 338 | path string |
| 339 | want bool |
| 340 | reason string |
| 341 | }{ |
| 342 | { |
| 343 | name: "nil user should allow access", |
| 344 | user: nil, |
| 345 | meta: nil, |
| 346 | path: "/any", |
| 347 | want: true, |
| 348 | reason: "nil user represents internal/system context and bypasses per-user write restrictions", |
| 349 | }, |
| 350 | { |
| 351 | name: "nil meta should allow access", |
| 352 | user: &model.User{ |
| 353 | ID: 1, |
| 354 | }, |
| 355 | meta: nil, |
| 356 | path: "/any", |
| 357 | want: true, |
| 358 | reason: "nil meta means no restrictions", |
| 359 | }, |
| 360 | { |
| 361 | name: "empty WriteUsers list should allow access", |
| 362 | user: &model.User{ |
| 363 | ID: 1, |
| 364 | }, |
| 365 | meta: &model.Meta{ |
| 366 | Path: "/folder", |
| 367 | WriteUsers: []uint{}, |
| 368 | }, |
| 369 | path: "/folder", |
| 370 | want: true, |
| 371 | reason: "empty WriteUsers means no user-level restrictions", |
| 372 | }, |
| 373 | { |
| 374 | name: "user in WriteUsers list with exact path match", |
| 375 | user: &model.User{ |
| 376 | ID: 1, |
| 377 | }, |
| 378 | meta: &model.Meta{ |
| 379 | Path: "/folder", |
| 380 | WriteUsers: []uint{1, 2, 3}, |
| 381 | WriteUsersSub: false, |
| 382 | }, |
| 383 | path: "/folder", |
| 384 | want: true, |
| 385 | reason: "user ID 1 is in WriteUsers list", |
| 386 | }, |
| 387 | { |
| 388 | name: "user not in WriteUsers list with exact path match", |
| 389 | user: &model.User{ |
| 390 | ID: 5, |