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.
72 lines
2.4 KiB
Go
72 lines
2.4 KiB
Go
// Code generated by summer make. DO NOT EDIT.
|
|
|
|
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"
|
|
)
|
|
|
|
var (
|
|
_ pact.AdminController = materialsAdmin{}
|
|
_ pact.AdminRecordSource = materialsAdmin{}
|
|
_ pact.AdminPermissioned = materialsAdmin{}
|
|
)
|
|
|
|
// materialsAdmin is the admin controller for materials.
|
|
type materialsAdmin struct{ temporalHooks }
|
|
|
|
func (materialsAdmin) ID() string { return "jz.bm.materials" }
|
|
func (materialsAdmin) ModelName() string { return "Material" }
|
|
func (materialsAdmin) ConfigDir() string { return "controllers/materials" }
|
|
|
|
// NewRecord returns the model the generic admin handlers query and fill.
|
|
func (materialsAdmin) NewRecord() any { return &models.Material{} }
|
|
|
|
// RequiredPermissions is checked before any schema or record is served.
|
|
func (materialsAdmin) RequiredPermissions() []string {
|
|
return []string{PermMaterials}
|
|
}
|
|
|
|
// 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"),
|
|
meetingRelation(),
|
|
{
|
|
Field: "tags",
|
|
Kind: "belongsToMany",
|
|
NewRelated: func() any { return &models.Tag{} },
|
|
NewPivot: func() any { return &models.MaterialTag{} },
|
|
ParentForeignKey: "material_id",
|
|
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",
|
|
},
|
|
}
|
|
}
|
|
|
|
// MaterialsController returns the jz.bm.materials admin controller.
|
|
func MaterialsController() pact.AdminController { return materialsAdmin{} }
|