-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(base): add dashboard and form share shortcuts #2282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wanghm25
wants to merge
1
commit into
larksuite:main
Choose a base branch
from
wanghm25:codex/base-share-management-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package base | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/larksuite/cli/shortcuts/common" | ||
| ) | ||
|
|
||
| var dashboardShareUpdateFlagNames = []string{ | ||
| "enabled", | ||
| "access-scope", | ||
| "show-source", | ||
| "enable-auto-analysis", | ||
| } | ||
|
|
||
| var BaseDashboardShareGet = common.Shortcut{ | ||
| Service: "base", | ||
| Command: "+dashboard-share-get", | ||
| Description: "Get dashboard share status and settings", | ||
| Risk: "read", | ||
| Scopes: []string{"base:dashboard:read"}, | ||
| AuthTypes: authTypes(), | ||
| Flags: []common.Flag{ | ||
| baseTokenFlag(true), | ||
| dashboardIDFlag(true), | ||
| }, | ||
| DryRun: func(_ context.Context, runtime *common.RuntimeContext) *common.DryRunAPI { | ||
| return common.NewDryRunAPI(). | ||
| GET("/open-apis/base/v3/bases/:base_token/dashboards/:dashboard_id/share"). | ||
| Set("base_token", runtime.Str("base-token")). | ||
| Set("dashboard_id", runtime.Str("dashboard-id")) | ||
| }, | ||
| Execute: func(_ context.Context, runtime *common.RuntimeContext) error { | ||
| data, err := baseV3Call(runtime, "GET", baseV3Path( | ||
| "bases", runtime.Str("base-token"), "dashboards", runtime.Str("dashboard-id"), "share", | ||
| ), nil, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| runtime.Out(data, nil) | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| var BaseDashboardShareUpdate = common.Shortcut{ | ||
| Service: "base", | ||
| Command: "+dashboard-share-update", | ||
| Description: "Update dashboard share status and settings", | ||
| Risk: "write", | ||
| Scopes: []string{"base:dashboard:update"}, | ||
| AuthTypes: authTypes(), | ||
| Flags: []common.Flag{ | ||
| baseTokenFlag(true), | ||
| dashboardIDFlag(true), | ||
| {Name: "enabled", Type: "bool", Desc: "enable or disable dashboard sharing"}, | ||
| {Name: "access-scope", Desc: "share access scope", Enum: shareAccessScopeEnums}, | ||
| {Name: "show-source", Type: "bool", Desc: "show the entry back to the source Base"}, | ||
| {Name: "enable-auto-analysis", Type: "bool", Desc: "enable intelligent analysis on the shared dashboard"}, | ||
| }, | ||
| Tips: []string{ | ||
| "Boolean settings use PATCH semantics: pass --show-source=false or --enable-auto-analysis=false to explicitly turn them off.", | ||
| "Update exactly one field per invocation; run separate commands to change multiple share fields.", | ||
| }, | ||
| Validate: func(_ context.Context, runtime *common.RuntimeContext) error { | ||
| return validateSingleShareUpdate(runtime, dashboardShareUpdateFlagNames...) | ||
| }, | ||
| DryRun: func(_ context.Context, runtime *common.RuntimeContext) *common.DryRunAPI { | ||
| return common.NewDryRunAPI(). | ||
| PATCH("/open-apis/base/v3/bases/:base_token/dashboards/:dashboard_id/share"). | ||
| Body(buildDashboardShareUpdateBody(runtime)). | ||
| Set("base_token", runtime.Str("base-token")). | ||
| Set("dashboard_id", runtime.Str("dashboard-id")) | ||
| }, | ||
| Execute: func(_ context.Context, runtime *common.RuntimeContext) error { | ||
| data, err := baseV3Call(runtime, "PATCH", baseV3Path( | ||
| "bases", runtime.Str("base-token"), "dashboards", runtime.Str("dashboard-id"), "share", | ||
| ), nil, buildDashboardShareUpdateBody(runtime)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| runtime.Out(data, nil) | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| func buildDashboardShareUpdateBody(runtime *common.RuntimeContext) map[string]interface{} { | ||
| body := map[string]interface{}{} | ||
| addCommonShareUpdateFields(runtime, body) | ||
|
|
||
| settings := map[string]interface{}{} | ||
| if runtime.Changed("show-source") { | ||
| settings["show_source"] = runtime.Bool("show-source") | ||
| } | ||
| if runtime.Changed("enable-auto-analysis") { | ||
| settings["enable_auto_analysis"] = runtime.Bool("enable-auto-analysis") | ||
| } | ||
| if len(settings) > 0 { | ||
| body["settings"] = settings | ||
| } | ||
| return body | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package base | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/larksuite/cli/shortcuts/common" | ||
| ) | ||
|
|
||
| var formShareUpdateFlagNames = []string{ | ||
| "enabled", | ||
| "access-scope", | ||
| "allow-anonymous", | ||
| "require-login", | ||
| } | ||
|
|
||
| var BaseFormShareGet = common.Shortcut{ | ||
| Service: "base", | ||
| Command: "+form-share-get", | ||
| Description: "Get form share status and settings", | ||
| Risk: "read", | ||
| Scopes: []string{"base:form:read"}, | ||
| AuthTypes: authTypes(), | ||
| Flags: []common.Flag{ | ||
| baseTokenFlag(true), | ||
| {Name: "table-id", Desc: "table ID", Required: true}, | ||
| {Name: "form-id", Desc: "form ID", Required: true}, | ||
| }, | ||
| DryRun: func(_ context.Context, runtime *common.RuntimeContext) *common.DryRunAPI { | ||
| return common.NewDryRunAPI(). | ||
| GET("/open-apis/base/v3/bases/:base_token/tables/:table_id/forms/:form_id/share"). | ||
| Set("base_token", runtime.Str("base-token")). | ||
| Set("table_id", runtime.Str("table-id")). | ||
| Set("form_id", runtime.Str("form-id")) | ||
| }, | ||
| Execute: func(_ context.Context, runtime *common.RuntimeContext) error { | ||
| data, err := baseV3Call(runtime, "GET", baseV3Path( | ||
| "bases", runtime.Str("base-token"), "tables", runtime.Str("table-id"), "forms", runtime.Str("form-id"), "share", | ||
| ), nil, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| runtime.Out(data, nil) | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| var BaseFormShareUpdate = common.Shortcut{ | ||
| Service: "base", | ||
| Command: "+form-share-update", | ||
| Description: "Update form share status and settings", | ||
| Risk: "write", | ||
| Scopes: []string{"base:form:update"}, | ||
| AuthTypes: authTypes(), | ||
| Flags: []common.Flag{ | ||
| baseTokenFlag(true), | ||
| {Name: "table-id", Desc: "table ID", Required: true}, | ||
| {Name: "form-id", Desc: "form ID", Required: true}, | ||
| {Name: "enabled", Type: "bool", Desc: "enable or disable form sharing"}, | ||
| {Name: "access-scope", Desc: "share access scope", Enum: shareAccessScopeEnums}, | ||
| {Name: "allow-anonymous", Type: "bool", Desc: "anonymize the submitter identity"}, | ||
| {Name: "require-login", Type: "bool", Desc: "require submitters to sign in before submitting"}, | ||
| }, | ||
| Tips: []string{ | ||
| "Boolean settings use PATCH semantics: pass --allow-anonymous=false or another boolean flag with =false to explicitly turn it off.", | ||
| "Using --allow-anonymous=true with --require-login=true requires sign-in but anonymizes the submitted identity.", | ||
| "Update exactly one field per invocation; run separate commands to change multiple share fields.", | ||
| }, | ||
| Validate: func(_ context.Context, runtime *common.RuntimeContext) error { | ||
| return validateFormShareUpdate(runtime) | ||
| }, | ||
| DryRun: func(_ context.Context, runtime *common.RuntimeContext) *common.DryRunAPI { | ||
| return common.NewDryRunAPI(). | ||
| PATCH("/open-apis/base/v3/bases/:base_token/tables/:table_id/forms/:form_id/share"). | ||
| Body(buildFormShareUpdateBody(runtime)). | ||
| Set("base_token", runtime.Str("base-token")). | ||
| Set("table_id", runtime.Str("table-id")). | ||
| Set("form_id", runtime.Str("form-id")) | ||
| }, | ||
| Execute: func(_ context.Context, runtime *common.RuntimeContext) error { | ||
| data, err := baseV3Call(runtime, "PATCH", baseV3Path( | ||
| "bases", runtime.Str("base-token"), "tables", runtime.Str("table-id"), "forms", runtime.Str("form-id"), "share", | ||
| ), nil, buildFormShareUpdateBody(runtime)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| runtime.Out(data, nil) | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| func validateFormShareUpdate(runtime *common.RuntimeContext) error { | ||
| return validateSingleShareUpdate(runtime, formShareUpdateFlagNames...) | ||
| } | ||
|
|
||
| func buildFormShareUpdateBody(runtime *common.RuntimeContext) map[string]interface{} { | ||
| body := map[string]interface{}{} | ||
| addCommonShareUpdateFields(runtime, body) | ||
|
|
||
| settings := map[string]interface{}{} | ||
| if runtime.Changed("allow-anonymous") { | ||
| settings["allow_anonymous"] = runtime.Bool("allow-anonymous") | ||
| } | ||
| if runtime.Changed("require-login") { | ||
| settings["require_login"] = runtime.Bool("require-login") | ||
| } | ||
|
|
||
| if len(settings) > 0 { | ||
| body["settings"] = settings | ||
| } | ||
| return body | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package base | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/larksuite/cli/errs" | ||
| "github.com/larksuite/cli/shortcuts/common" | ||
| ) | ||
|
|
||
| var shareAccessScopeEnums = []string{"invite", "tenant", "anyone"} | ||
|
|
||
| func validateSingleShareUpdate(runtime *common.RuntimeContext, flagNames ...string) error { | ||
| changedNames := make([]string, 0, len(flagNames)) | ||
| for _, name := range flagNames { | ||
| if runtime.Changed(name) { | ||
| changedNames = append(changedNames, name) | ||
| } | ||
| } | ||
| switch len(changedNames) { | ||
| case 1: | ||
| return nil | ||
| case 0: | ||
| return errs.NewValidationError(errs.SubtypeInvalidArgument, "exactly one share field must be provided"). | ||
| WithHint("use one of: %s", shareFlagNames(flagNames)) | ||
| default: | ||
| return baseFlagErrorf("share update accepts exactly one field; do not combine %s", shareFlagNames(changedNames)) | ||
| } | ||
| } | ||
|
|
||
| func shareFlagNames(flagNames []string) string { | ||
| names := make([]string, 0, len(flagNames)) | ||
| for _, name := range flagNames { | ||
| names = append(names, "--"+name) | ||
| } | ||
| return strings.Join(names, ", ") | ||
| } | ||
|
|
||
| func addCommonShareUpdateFields(runtime *common.RuntimeContext, body map[string]interface{}) { | ||
| if runtime.Changed("enabled") { | ||
| body["enabled"] = runtime.Bool("enabled") | ||
| } | ||
| if runtime.Changed("access-scope") { | ||
| body["access_scope"] = runtime.Str("access-scope") | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Make the
Tipstext match validation.The tip says that
--allow-anonymous=trueand--require-login=truecan be used together. The shared validator rejects two changed fields. Users who follow this tip receive a validation error.State that users must run separate update commands to change both settings.
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents