Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ linters:
- all
- '-QF1001' # disable rule 'Apply De Morgan’s law'
- '-QF1012' # disable rule 'Use fmt.Fprintf instead of x.Write(fmt.Sprintf(...))'
- '-QF1003' # disable rule 'Convert if/else-if chain to tagged switch'
# https://golangci-lint.run/usage/linters/#staticcheck
# https://staticcheck.dev/docs/configuration/options/#initialisms
initialisms:
Expand Down
46 changes: 27 additions & 19 deletions cmd/triggers/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,18 @@ func manageNamedEntities(cmd *cobra.Command, clients *shared.ClientFactory, toke
}

if accessNamedEntities > 0 {
if accessAction == "grant" {
switch accessAction {
case "grant":
accessFlags.grant = true
if !cmdutil.IsFlagChanged(cmd, "include-app-collaborators") && currentAccessType != types.PermissionNamedEntities {
includeAppCollaborators, err = prompts.AddAppCollaboratorsToNamedEntitiesPrompt(ctx, clients.IO)
if err != nil {
return err
}
}
} else if accessAction == "revoke" {
case "revoke":
accessFlags.revoke = true
} else {
default:
return nil
}
} else {
Expand Down Expand Up @@ -563,13 +564,14 @@ func printAccess(cmd *cobra.Command, clients *shared.ClientFactory, token string
return err
}

if accessType == types.PermissionEveryone {
switch accessType {
case types.PermissionEveryone:
var everyoneAccessTypeDescription = types.GetAccessTypeDescriptionForEveryone(app)
clients.IO.PrintInfo(ctx, false, "\nTrigger '%s' can be found and run by %s", accessFlags.triggerID, everyoneAccessTypeDescription)
} else if accessType == types.PermissionAppCollaborators {
case types.PermissionAppCollaborators:
clients.IO.PrintInfo(ctx, false, "\nTrigger '%s' can be found and run by %s:", accessFlags.triggerID, style.Pluralize("app collaborator", "app collaborators", len(userAccessList)))
err = printAppCollaboratorsHelper(cmd, clients, token, userAccessList)
} else if accessType == types.PermissionNamedEntities {
case types.PermissionNamedEntities:
err = printNamedEntitiesHelper(cmd, clients, token, userAccessList, "list")
}
clients.IO.PrintTrace(ctx, slacktrace.TriggersAccessSuccess)
Expand All @@ -581,16 +583,17 @@ func printCurrentAuthorizedEntities(cmd *cobra.Command, clients *shared.ClientFa
ctx := cmd.Context()

cmd.Println()
if currentAccessType == types.PermissionEveryone {
switch currentAccessType {
case types.PermissionEveryone:
var everyoneAccessTypeDescription = types.GetAccessTypeDescriptionForEveryone(app)
clients.IO.PrintInfo(ctx, false, "Trigger '%s' can be found and run by %s\n", accessFlags.triggerID, everyoneAccessTypeDescription)
} else if currentAccessType == (types.PermissionAppCollaborators) {
case types.PermissionAppCollaborators:
clients.IO.PrintInfo(ctx, false, "Access is currently granted to %s:", style.Pluralize("app collaborator", "app collaborators", len(currentAccessList)))
err := printAppCollaboratorsHelper(cmd, clients, token, currentAccessList)
if err != nil {
return err
}
} else {
case types.PermissionNamedEntities:
err := printNamedEntitiesHelper(cmd, clients, token, currentAccessList, "manage")
if err != nil {
return err
Expand Down Expand Up @@ -622,9 +625,10 @@ func printNamedEntitiesHelper(cmd *cobra.Command, clients *shared.ClientFactory,
ctx := cmd.Context()

if len(entitiesAccessList) <= 0 {
if action == "manage" {
switch action {
case "manage":
clients.IO.PrintInfo(ctx, false, "Access is currently granted:")
} else if action == "list" {
case "list":
clients.IO.PrintInfo(ctx, false, "\nTrigger '%s' can be found and run by:", accessFlags.triggerID)
}
clients.IO.PrintInfo(ctx, false, "nobody")
Expand All @@ -635,9 +639,10 @@ func printNamedEntitiesHelper(cmd *cobra.Command, clients *shared.ClientFactory,

if len(namedEntitiesAccessMap["users"]) > 0 {
var userLabel = style.Pluralize("this user", "these users", len(namedEntitiesAccessMap["users"]))
if action == "manage" {
switch action {
case "manage":
clients.IO.PrintInfo(ctx, false, "\nAccess is currently granted to %s:", userLabel)
} else if action == "list" {
case "list":
clients.IO.PrintInfo(ctx, false, "\nTrigger '%s' can be found and run by %s:", accessFlags.triggerID, userLabel)
}
for _, entity := range namedEntitiesAccessMap["users"] {
Expand All @@ -650,9 +655,10 @@ func printNamedEntitiesHelper(cmd *cobra.Command, clients *shared.ClientFactory,
}
if len(namedEntitiesAccessMap["channels"]) > 0 {
var channelLabel = style.Pluralize("this channel", "these channels", len(namedEntitiesAccessMap["channels"]))
if action == "manage" {
switch action {
case "manage":
clients.IO.PrintInfo(ctx, false, "\nAccess is currently granted to all members of %s:", channelLabel)
} else if action == "list" {
case "list":
clients.IO.PrintInfo(ctx, false, "\nTrigger '%s' can be found and run by all members of %s:", accessFlags.triggerID, channelLabel)
}
for _, entity := range namedEntitiesAccessMap["channels"] {
Expand All @@ -665,9 +671,10 @@ func printNamedEntitiesHelper(cmd *cobra.Command, clients *shared.ClientFactory,
}
if len(namedEntitiesAccessMap["teams"]) > 0 {
var teamLabel = style.Pluralize("this workspace", "these workspaces", len(namedEntitiesAccessMap["teams"]))
if action == "manage" {
switch action {
case "manage":
clients.IO.PrintInfo(ctx, false, "\nAccess is currently granted to all members of %s:", teamLabel)
} else if action == "list" {
case "list":
clients.IO.PrintInfo(ctx, false, "\nTrigger '%s' can be found and run by all members of %s:", accessFlags.triggerID, teamLabel)
}
for _, entity := range namedEntitiesAccessMap["teams"] {
Expand All @@ -680,9 +687,10 @@ func printNamedEntitiesHelper(cmd *cobra.Command, clients *shared.ClientFactory,
}
if len(namedEntitiesAccessMap["organizations"]) > 0 {
var orgLabel = style.Pluralize("this organization", "these organizations", len(namedEntitiesAccessMap["organizations"]))
if action == "manage" {
switch action {
case "manage":
clients.IO.PrintInfo(ctx, false, "\nAccess is currently granted to all members of %s:", orgLabel)
} else if action == "list" {
case "list":
clients.IO.PrintInfo(ctx, false, "\nTrigger '%s' can be found and run by all members of %s:", accessFlags.triggerID, orgLabel)
}
for _, entity := range namedEntitiesAccessMap["organizations"] {
Expand Down
7 changes: 4 additions & 3 deletions cmd/triggers/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ func sprintTrigger(ctx context.Context, t types.DeployedTrigger, clients *shared
"nobody",
))
} else {
if accessType == types.PermissionEveryone {
switch accessType {
case types.PermissionEveryone:
var everyoneAccessTypeDescription = types.GetAccessTypeDescriptionForEveryone(app)
triggerText = append(triggerText, fmt.Sprintf(
style.Indent(style.Secondary("Can be found and used by:\n %s")),
style.Indent(style.Secondary(everyoneAccessTypeDescription)),
))
} else if accessType == types.PermissionAppCollaborators {
case types.PermissionAppCollaborators:
triggerText = append(triggerText, fmt.Sprint(
style.Indent(style.Secondary("Can be found and used by:")),
))
Expand All @@ -162,7 +163,7 @@ func sprintTrigger(ctx context.Context, t types.DeployedTrigger, clients *shared
userInfo.RealName, style.Secondary("@"+userInfo.Profile.DisplayName), style.Secondary(userInfo.ID),
))
}
} else if accessType == types.PermissionNamedEntities {
case types.PermissionNamedEntities:
triggerText = append(triggerText, fmt.Sprint(
style.Indent(style.Secondary("Can be found and used by:")),
))
Expand Down
27 changes: 15 additions & 12 deletions internal/api/triggerpermissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ func (c *Client) TriggerPermissionsSet(ctx context.Context, token, triggerID, en
values.Add("trigger_id", triggerID)
values.Add("permission_type", string(permissionType))
if permissionType == types.PermissionNamedEntities && len(entities) > 0 {
if entityType == "users" {
switch entityType {
case "users":
values.Add("user_ids", entities)
} else if entityType == "channels" {
case "channels":
values.Add("channel_ids", entities)
} else if entityType == "workspaces" {
case "workspaces":
values.Add("team_ids", entities)
} else if entityType == "organizations" {
case "organizations":
values.Add("org_ids", entities)
}
}
Expand Down Expand Up @@ -167,13 +168,14 @@ func (c *Client) TriggerPermissionsAddEntities(ctx context.Context, token, trigg
var values = url.Values{}
values.Add("token", token)
values.Add("trigger_id", triggerID)
if entityType == "users" {
switch entityType {
case "users":
values.Add("user_ids", entities)
} else if entityType == "channels" {
case "channels":
values.Add("channel_ids", entities)
} else if entityType == "workspaces" {
case "workspaces":
values.Add("team_ids", entities)
} else if entityType == "organizations" {
case "organizations":
values.Add("org_ids", entities)
}

Expand Down Expand Up @@ -214,13 +216,14 @@ func (c *Client) TriggerPermissionsRemoveEntities(ctx context.Context, token, tr
var values = url.Values{}
values.Add("token", token)
values.Add("trigger_id", triggerID)
if entityType == "users" {
switch entityType {
case "users":
values.Add("user_ids", entities)
} else if entityType == "channels" {
case "channels":
values.Add("channel_ids", entities)
} else if entityType == "workspaces" {
case "workspaces":
values.Add("team_ids", entities)
} else if entityType == "organizations" {
case "organizations":
values.Add("org_ids", entities)
}

Expand Down
5 changes: 3 additions & 2 deletions internal/goutils/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func ExtractFirstJSONFromString(s string) string {

var stack = []rune{}
for i := start; i < len(s); i++ {
if s[i] == '{' {
switch s[i] {
case '{':
stack = append(stack, rune(s[i]))
} else if s[i] == '}' {
case '}':
stack = stack[:len(stack)-1] // pop last item
end = i // we found a potential ending bracket
}
Expand Down
7 changes: 4 additions & 3 deletions internal/pkg/apps/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,14 @@ func printNonSuccessInstallState(ctx context.Context, clients *shared.ClientFact
primary string
secondary string
)
if installState == types.InstallRequestPending {
switch installState {
case types.InstallRequestPending:
primary = "Your request to install the app is pending"
secondary = fmt.Sprintf("You will receive a Slackbot message after an admin has reviewed your request\nOnce your request is approved, complete installation by re-running %s", style.Commandf(clients.Config.Command, true))
} else if installState == types.InstallRequestCancelled {
case types.InstallRequestCancelled:
primary = "Your request to install the app has been cancelled"
secondary = ""
} else if installState == types.InstallRequestNotSent {
case types.InstallRequestNotSent:
primary = "You've declined to send a request to an admin"
secondary = "Please submit a request to install or update your app"
}
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/platform/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,16 @@ func triggerExecutedToString(activity api.Activity) (result string) {
msgs := []string{}

// Additional consideration for errors
if activity.Level == types.INFO {
switch activity.Level {
case types.INFO:
trigger, ok := activity.Payload["trigger"].(map[string]interface{})
if ok {
caser := cases.Title(language.English)
msgs = append(msgs, fmt.Sprintf("%s trigger successfully started execution of function '%s'", caser.String(trigger["type"].(string)), activity.Payload["function_name"]))
} else {
msgs = append(msgs, fmt.Sprintf("Trigger successfully started execution of function '%s'", activity.Payload["function_name"]))
}
} else if activity.Level == types.ERROR {
case types.ERROR:
msgs = append(msgs, fmt.Sprintf("Trigger for workflow '%s' failed: %s", activity.Payload["function_name"], activity.Payload["reason"]))
// Default format for the errors message is the raw, json-encoded string
var payloadErrors = []string{fmt.Sprintf("• %s", activity.Payload["errors"])}
Expand Down
5 changes: 3 additions & 2 deletions internal/prompts/trigger_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func TriggerChooseNamedEntityPrompt(ctx context.Context, clients *shared.ClientF
"cancel",
}

if accessAction == "grant" {
switch accessAction {
case "grant":
actions = []string{
"add_user",
"add_channel",
Expand All @@ -90,7 +91,7 @@ func TriggerChooseNamedEntityPrompt(ctx context.Context, clients *shared.ClientF
"grant an organization access",
"cancel",
}
} else if accessAction == "revoke" {
case "revoke":
actions = []string{
"remove_user",
"remove_channel",
Expand Down
Loading