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:
@@ -199,7 +199,7 @@ func newTagsJSON(tags []models.Tag) []tagJSON {
|
||||
return out
|
||||
}
|
||||
|
||||
// materialListJSON is a published material in a list.
|
||||
// materialListJSON is a published material the caller may see, in a list.
|
||||
type materialListJSON struct {
|
||||
ID uint `json:"id"`
|
||||
CourseID *uint `json:"course_id"`
|
||||
@@ -212,6 +212,7 @@ type materialListJSON struct {
|
||||
PublishedAt string `json:"published_at"`
|
||||
Tags []tagJSON `json:"tags"`
|
||||
FilesCount int64 `json:"files_count"`
|
||||
IsPrivate bool `json:"is_private"`
|
||||
}
|
||||
|
||||
func newMaterialListJSON(m models.Material, files int64) materialListJSON {
|
||||
@@ -226,6 +227,7 @@ func newMaterialListJSON(m models.Material, files int64) materialListJSON {
|
||||
URL: m.URL,
|
||||
Tags: newTagsJSON(m.Tags),
|
||||
FilesCount: files,
|
||||
IsPrivate: m.IsPrivate,
|
||||
}
|
||||
if m.PublishedAt != nil {
|
||||
out.PublishedAt = models.FormatDateTime(*m.PublishedAt)
|
||||
@@ -233,11 +235,13 @@ func newMaterialListJSON(m models.Material, files int64) materialListJSON {
|
||||
return out
|
||||
}
|
||||
|
||||
// materialDetailJSON is a published material with its body and files.
|
||||
// materialDetailJSON is a published material the caller may see, with its
|
||||
// body and files. CanManage is true for the caller who may change its access.
|
||||
type materialDetailJSON struct {
|
||||
materialListJSON
|
||||
Body *string `json:"body"`
|
||||
Files []fileJSON `json:"files"`
|
||||
Body *string `json:"body"`
|
||||
Files []fileJSON `json:"files"`
|
||||
CanManage bool `json:"can_manage"`
|
||||
}
|
||||
|
||||
// fileJSON is one attached file.
|
||||
|
||||
Reference in New Issue
Block a user