Skip to content

Commit 43f9324

Browse files
authored
cli: validate account in workspace scope for write commands (#380)
1 parent 4f706b4 commit 43f9324

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

internal/cli/delete.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"github.com/spf13/cobra"
55

6+
a "github.com/anish749/pigeon/internal/account"
67
"github.com/anish749/pigeon/internal/commands"
78
)
89

@@ -67,6 +68,9 @@ func runDeleteSlack(cmd *cobra.Command, args []string) error {
6768
if err != nil {
6869
return err
6970
}
71+
if err := validateAccountInScope(a.New("slack", account)); err != nil {
72+
return err
73+
}
7074
return commands.RunDelete(commands.DeleteParams{
7175
Platform: "slack",
7276
Account: account,

internal/cli/react.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"github.com/spf13/cobra"
55

6+
a "github.com/anish749/pigeon/internal/account"
67
"github.com/anish749/pigeon/internal/commands"
78
)
89

@@ -100,6 +101,9 @@ func runReactSlack(cmd *cobra.Command, args []string) error {
100101
if err != nil {
101102
return err
102103
}
104+
if err := validateAccountInScope(a.New("slack", account)); err != nil {
105+
return err
106+
}
103107
return commands.RunReact(commands.ReactParams{
104108
Platform: "slack",
105109
Account: account,
@@ -132,6 +136,9 @@ func runReactWhatsapp(cmd *cobra.Command, args []string) error {
132136
if err != nil {
133137
return err
134138
}
139+
if err := validateAccountInScope(a.New("whatsapp", account)); err != nil {
140+
return err
141+
}
135142
return commands.RunReact(commands.ReactParams{
136143
Platform: "whatsapp",
137144
Account: account,

internal/cli/send.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/spf13/cobra"
99

10+
a "github.com/anish749/pigeon/internal/account"
1011
"github.com/anish749/pigeon/internal/commands"
1112
"github.com/anish749/pigeon/internal/store/modelv1"
1213
)
@@ -133,6 +134,10 @@ func runSendSlack(cmd *cobra.Command, args []string) error {
133134
return err
134135
}
135136

137+
if err := validateAccountInScope(a.New("slack", account)); err != nil {
138+
return err
139+
}
140+
136141
if postAt != "" {
137142
ts, err := parsePostAt(postAt)
138143
if err != nil {
@@ -174,6 +179,10 @@ func runSendWhatsapp(cmd *cobra.Command, args []string) error {
174179
return err
175180
}
176181

182+
if err := validateAccountInScope(a.New("whatsapp", account)); err != nil {
183+
return err
184+
}
185+
177186
return commands.RunSend(commands.SendParams{
178187
Platform: "whatsapp",
179188
Account: account,

0 commit comments

Comments
 (0)