Skip to content

Commit

Permalink
Let subscription name usage in commands be case insensitive (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmister authored May 4, 2020
1 parent 0e08868 commit 72cb812
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions server/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func deleteSubscription(context *model.CommandArgs, args ...string) *model.Comma
postCommandResponse(context, specifyAlias)
return &model.CommandResponse{}
}
alias := args[0]
if err := service.DeleteSubscription(context.ChannelId, args[0]); err != nil {
alias := strings.Join(args, " ")
if err := service.DeleteSubscription(context.ChannelId, alias); err != nil {
postCommandResponse(context, err.Error())
return &model.CommandResponse{}
}
Expand Down
12 changes: 12 additions & 0 deletions server/serializer/channel_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"strings"
)

const (
Expand Down Expand Up @@ -155,3 +156,14 @@ func FormattedSubscriptionList(channelSubscriptions StringSubscription) string {
}
return list
}

func (s StringSubscription) GetInsensitiveCase(key string) (Subscription, bool) {
key = strings.ToLower(key)
for k, v := range s {
k = strings.ToLower(k)
if key == k {
return v, true
}
}
return nil, false
}
2 changes: 1 addition & 1 deletion server/service/delete_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func DeleteSubscription(channelID, alias string) error {
return fmt.Errorf(generalDeleteError, alias)
}
if channelSubscriptions, valid := subs.ByChannelID[channelID]; valid {
if subscription, ok := channelSubscriptions[alias]; ok {
if subscription, ok := channelSubscriptions.GetInsensitiveCase(alias); ok {
aErr := store.AtomicModify(store.GetSubscriptionKey(), func(initialBytes []byte) ([]byte, error) {
subscriptions, err := serializer.SubscriptionsFromJSON(initialBytes)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/service/get_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func GetChannelSubscription(channelID, alias string) (serializer.Subscription, i
if gErr != nil {
return nil, http.StatusInternalServerError, errors.New(generalError)
}
subscription, found := channelSubscriptions[alias]
subscription, found := channelSubscriptions.GetInsensitiveCase(alias)
if !found {
return nil, http.StatusBadRequest, fmt.Errorf(subscriptionNotFound, alias)
}
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default class Hooks {
if (args.length < 3) { // eslint-disable-line
this.store.dispatch(sendEphemeralPost(Constants.SPECIFY_ALIAS, contextArgs.channel_id, userID));
} else {
this.store.dispatch(getChannelSubscription(contextArgs.channel_id, args[2], userID));
const alias = args.slice(2).join(' ');
this.store.dispatch(getChannelSubscription(contextArgs.channel_id, alias, userID));
}
return Promise.resolve({});
}
Expand Down

0 comments on commit 72cb812

Please sign in to comment.