feat: manage material visibility and shares

The management save/update body takes is_private, author_user_id and
share_user_ids (absent keeps each; a new material gets the caller as
author), and the managed material shows them. New routes PATCH
/materials/{id}/visibility, PUT /materials/{id}/shares and GET /users,
with the MCP tools bm_manage_set_material_visibility,
bm_manage_set_material_shares and bm_manage_list_users. The /bmadmin
form gets the private switch, the author picker and shared_with.
This commit is contained in:
Jakub Zych
2026-11-08 11:56:14 +01:00
parent 418f8240a4
commit 3346cb6ff6
13 changed files with 470 additions and 53 deletions

View File

@@ -3,6 +3,7 @@
package controllers
import (
usermodels "git.golem15.com/golem15/sm-user-plugin/models"
"git.golem15.com/golem15/summercms/modules/cabana"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/jakub/sm-bm-plugin/models"
@@ -29,8 +30,11 @@ func (materialsAdmin) RequiredPermissions() []string {
return []string{PermMaterials}
}
// AdminFieldRelations binds the course and meeting pickers and the tags. The files field
// is bound by models.Material.AttachRelations.
// AdminFieldRelations binds the course and meeting pickers, the tags, the
// author picker and the users a private material is shared with. The
// author column is author_user_id, not user_id, which the backend refuses
// to fill from a body. The files field is bound by
// models.Material.AttachRelations.
func (materialsAdmin) AdminFieldRelations() []cabana.FieldRelationContract {
return []cabana.FieldRelationContract{
courseRelation("course_id"),
@@ -44,6 +48,22 @@ func (materialsAdmin) AdminFieldRelations() []cabana.FieldRelationContract {
RelatedForeignKey: "tag_id",
LabelColumn: "name",
},
{
Field: "author",
Kind: "belongsTo",
NewRelated: func() any { return &usermodels.User{} },
ForeignKey: "author_user_id",
LabelColumn: "email",
},
{
Field: "shared_with",
Kind: "belongsToMany",
NewRelated: func() any { return &usermodels.User{} },
NewPivot: func() any { return &models.MaterialShare{} },
ParentForeignKey: "material_id",
RelatedForeignKey: "user_id",
LabelColumn: "email",
},
}
}