Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmd/commandline/plugin/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var permissionKeySeq = []string{
"model.speech2text",
"model.moderation",
"app.enabled",
"node.enabled",
"storage.enabled",
"storage.size",
"endpoint.enabled",
Expand Down Expand Up @@ -78,6 +79,8 @@ func (p permission) View() string {
s += fmt.Sprintf(" %sModeration: %v %s You can invoke moderation models inside Dify if it's enabled %s\n", cursor("model.moderation"), checked(p.permission.AllowInvokeModeration()), YELLOW, RESET)
s += "Apps:\n"
s += fmt.Sprintf(" %sEnabled: %v %s Ability to invoke apps like BasicChat/ChatFlow/Agent/Workflow etc. %s\n", cursor("app.enabled"), checked(p.permission.AllowInvokeApp()), YELLOW, RESET)
s += "Nodes:\n"
s += fmt.Sprintf(" %sEnabled: %v %s Ability to invoke nodes inside Dify ChatFlow/Workflow %s\n", cursor("node.enabled"), checked(p.permission.AllowInvokeNode()), YELLOW, RESET)
s += "Resources:\n"
s += "Storage:\n"
s += fmt.Sprintf(" %sEnabled: %v %s Persistence storage for the plugin %s\n", cursor("storage.enabled"), checked(p.permission.AllowInvokeStorage()), YELLOW, RESET)
Expand Down Expand Up @@ -175,6 +178,16 @@ func (p *permission) edit() {
}
}

if p.cursor == "node.enabled" {
if p.permission.AllowInvokeNode() {
p.permission.Node = nil
} else {
p.permission.Node = &plugin_entities.PluginPermissionNodeRequirement{
Enabled: true,
}
}
}
Comment on lines +181 to +189
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic for toggling a boolean permission is almost identical to the logic for other permissions (e.g., app.enabled). This code duplication makes the edit function longer and harder to maintain with each new permission.

To improve maintainability, consider abstracting this repeated pattern. A future refactoring could introduce a helper function or a map-based dispatcher to handle these simple toggle cases, reducing redundancy and making the code more scalable.


if p.cursor == "storage.enabled" {
if p.permission.AllowInvokeStorage() {
p.permission.Storage = nil
Expand Down