Qor管理员禁用创建按钮并更新所选项目。

huangapple go评论65阅读模式
英文:

Qor admin disable create button and update selected item

问题

在qor admin中,如何禁用创建按钮并禁用更新选定的项目?我已经尝试过,但我只能在每个记录的操作中隐藏删除按钮。这是我的代码:

borrowerLog := a.adm.AddResource(&model.BorrowerHistoryLog{}, &admin.Config{Name: "Borrower Log", Menu: []string{"Borrower"}})
borrowerLog.IndexAttrs("-ID")
borrowerLog.Action(&admin.Action{
	Name: "Delete",
	Visible: func(record interface{}, context *admin.Context) bool {
		return false
	},
})

whitelist := a.adm.AddResource(&model.Whitelist{}, &admin.Config{Name: "Whitelist", Menu: []string{"Client"}})
whitelist.IndexAttrs("-ID")

请注意,这只是隐藏了删除按钮,如果你想要完全禁用创建和更新功能,你需要进行其他的配置。

英文:

In qor admin, how do I disable the create button and disable update the selected item? I've tried, but I can only hide the Delete button in action for each record. Here is my code:

borrowerLog := a.adm.AddResource(&model.BorrowerHistoryLog{}, &admin.Config{Name: "Borrower Log", Menu: []string{"Borrower"}})
borrowerLog.IndexAttrs("-ID")
borrowerLog.Action(&admin.Action{
	Name: "Delete",
	Visible: func(record interface{}, context *admin.Context) bool {
		return false
	},
})

whitelist := a.adm.AddResource(&model.Whitelist{}, &admin.Config{Name: "Whitelist", Menu: []string{"Client"}})
whitelist.IndexAttrs("-ID"

答案1

得分: 0

我已经得到了答案,只需为管理员配置添加自定义权限。

customPermission := roles.Allow(roles.Read, roles.Anyone).Deny(roles.Create, roles.Anyone).Deny(roles.Update, roles.Anyone).Deny(roles.Delete, roles.Anyone)
borrowerLog := a.adm.AddResource(&model.BorrowerHistoryLog{}, &admin.Config{Name: "Borrower Log", Menu: []string{"Borrower"}, Permission: customPermission})
英文:

I've got my answer, just add custom permission for the admin config

customPermission := roles.Allow(roles.Read, roles.Anyone).Deny(roles.Create, roles.Anyone).Deny(roles.Update, roles.Anyone).Deny(roles.Delete, roles.Anyone)
borrowerLog := a.adm.AddResource(&model.BorrowerHistoryLog{}, &admin.Config{Name: "Borrower Log", Menu: []string{"Borrower"}, Permission: customPermission})

huangapple
  • 本文由 发表于 2021年6月24日 20:22:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/68115682.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定