feat: private materials with per-user shares
A material may be private: only its author and the users it is shared
with see it. Every student read (list, detail, course detail and
counters, the checklist linked material, the token twins) goes through
one visibility fragment. Existing materials stay public with no author.
GET/PUT /_bm/api/v1/materials/{id}/access let the author, a material
manager, toggle the flag and pick the users; the first change of an
author-less material makes the caller its author.
This commit is contained in:
@@ -211,9 +211,12 @@ func loadChecklistItems(db *gorm.DB, userID uint, checklistIDs []uint) (map[uint
|
||||
}
|
||||
materials := map[uint]*linkedMaterial{}
|
||||
if len(materialIDs) > 0 {
|
||||
// Only published materials, as in the material list.
|
||||
// Only published materials the caller may see, so a private
|
||||
// material's title never shows.
|
||||
var ms []models.Material
|
||||
if err := db.Select("id", "title").Where("id IN ? AND published_at IS NOT NULL", materialIDs).Find(&ms).Error; err != nil {
|
||||
err := db.Select("id", "title").Where("id IN ? AND published_at IS NOT NULL", materialIDs).
|
||||
Where(visibleMaterialSQL("jz_bm_materials"), userID, userID).Find(&ms).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, m := range ms {
|
||||
|
||||
Reference in New Issue
Block a user