Skip to content

Commit 885b178

Browse files
committed
lint clean
1 parent 7e3e03f commit 885b178

File tree

6 files changed

+40
-28
lines changed

6 files changed

+40
-28
lines changed

server/commandhandler.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/lukegb/mattermost-plugin-uffd/server/datastore"
99
"github.com/lukegb/mattermost-plugin-uffd/server/stringset"
1010
"github.com/lukegb/mattermost-plugin-uffd/server/syncengine"
11+
1112
"github.com/mattermost/mattermost/server/public/model"
1213
"github.com/mattermost/mattermost/server/public/plugin"
1314
"github.com/mattermost/mattermost/server/public/pluginapi"
@@ -134,13 +135,14 @@ func (h *CommandHandler) executeRename(ctx context.Context, c *plugin.Context, a
134135
ds := &datastore.MattermostDataStore{API: h.api}
135136

136137
foundTeam, err := teamFromChannelName(ctx, ds, newName)
137-
if err != nil {
138+
switch {
139+
case err != nil:
138140
return errResponsef("An error occurred while checking for the team the channel belongs to: %v", err)
139-
} else if foundTeam == nil {
141+
case foundTeam == nil:
140142
return errResponsef("Channel names need to be begin with a team name")
141-
} else if ch.Name == foundTeam.Name || ch.Name == foundTeam.Name+"-private" {
143+
case ch.Name == foundTeam.Name, ch.Name == foundTeam.Name+"-private":
142144
return errResponsef("You can't rename the team default public or private channels")
143-
} else if !h.authorizedForTeam(foundTeam, args.UserId) {
145+
case !h.authorizedForTeam(foundTeam, args.UserId):
144146
return errResponsef("You aren't a team lead of %s, so you can't rename channels to belong with that name.", foundTeam.Name)
145147
}
146148

@@ -208,11 +210,12 @@ func (h *CommandHandler) executeCreate(ctx context.Context, c *plugin.Context, a
208210
ds := &datastore.MattermostDataStore{API: h.api}
209211

210212
foundTeam, err := teamFromChannelName(ctx, ds, newName)
211-
if err != nil {
213+
switch {
214+
case err != nil:
212215
return errResponsef("An error occurred while checking for the team the channel belongs to: %v", err)
213-
} else if foundTeam == nil {
216+
case foundTeam == nil:
214217
return errResponsef("Channel names need to be begin with a team name")
215-
} else if !h.authorizedForTeam(foundTeam, args.UserId) {
218+
case !h.authorizedForTeam(foundTeam, args.UserId):
216219
return errResponsef("You aren't a team lead of %s, so you can't create channels that start with that name.", foundTeam.Name)
217220
}
218221

server/syncablesync/mattermost_channel.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type mattermostChannelHandler struct {
2020
type mattermostChannelAPI interface {
2121
datastore.MattermostPluginAPI
2222

23-
GetChannel(channelId string) (*model.Channel, *model.AppError)
23+
GetChannel(channelID string) (*model.Channel, *model.AppError)
2424
GetChannelMembers(channelID string, page, perPage int) (model.ChannelMembers, *model.AppError)
2525
AddUserToChannel(channelID, userID, onBehalfOfUser string) (*model.ChannelMember, *model.AppError)
2626
DeleteChannelMember(channelID, userID string) *model.AppError
@@ -124,7 +124,6 @@ func (h *mattermostChannelHandler) UpdateMembers(ctx context.Context, st Syncabl
124124
return fmt.Errorf("getting channel %s permission scheme: %w", st.ID, err)
125125
}
126126
for _, rm := range rms {
127-
128127
oldTM := rm.ServiceType.(*model.ChannelMember)
129128
roles := stringset.FromSlice(oldTM.GetRoles())
130129
isAdmin := roles.Contains(sch.DefaultChannelAdminRole)

server/syncablesync/mattermost_channel_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestChannelFetchRoster(t *testing.T) {
4747
func TestChannelAddMembers(t *testing.T) {
4848
m := &fakeMattermost{
4949
channels: map[string]*model.Channel{
50-
"channel:::test": &model.Channel{
50+
"channel:::test": {
5151
Id: "channel:::test",
5252
},
5353
},
@@ -123,7 +123,7 @@ func TestChannelDeleteMembers(t *testing.T) {
123123
func TestChannelUpdateMembers(t *testing.T) {
124124
m := &fakeMattermost{
125125
channels: map[string]*model.Channel{
126-
"channel:::test": &model.Channel{
126+
"channel:::test": {
127127
Id: "channel:::test",
128128
},
129129
},

server/syncablesync/mattermostservice.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ func (m *Mattermost) FetchGroupsAndSyncables(ctx context.Context) ([]Group, erro
171171
Name: ch.Name,
172172
MembershipUnmanaged: false,
173173
}
174-
m.GroupStore.SaveChannel(ctx, chInfo)
174+
if err := m.GroupStore.SaveChannel(ctx, chInfo); err != nil {
175+
l.WithError(err).WithField("channelInfo", chInfo).Error("failed to save additional channel info")
176+
}
175177
}
176178
channelInfo[ch.Id] = chInfo
177179
knownChannels.Add(ch.Name)
@@ -206,18 +208,19 @@ func (m *Mattermost) FetchGroupsAndSyncables(ctx context.Context) ([]Group, erro
206208
})
207209
if appErr != nil {
208210
return nil, fmt.Errorf("creating default public channel for team %v: %w", t.Name, appErr)
209-
} else {
210-
allChannels = append(allChannels, ch)
211211
}
212-
m.GroupStore.SaveChannel(ctx, &datastore.ChannelInfo{
212+
allChannels = append(allChannels, ch)
213+
if err := m.GroupStore.SaveChannel(ctx, &datastore.ChannelInfo{
213214
ID: ch.Id,
214215
Name: t.Name,
215216
MembershipUnmanaged: false,
216-
})
217+
}); err != nil {
218+
l.WithError(err).WithField("channel_id", ch.Id).WithField("channel_name", t.Name).Error("Failed to create default public channel metadata")
219+
}
217220
}
218221
privName := t.Name + "-private"
219222
if !knownChannels.Contains(privName) {
220-
// Create the default public channel for this team.
223+
// Create the default private channel for this team.
221224
ch, appErr := m.API.CreateChannel(&model.Channel{
222225
TeamId: theTeam.Id,
223226
Type: model.ChannelTypePrivate,
@@ -226,14 +229,15 @@ func (m *Mattermost) FetchGroupsAndSyncables(ctx context.Context) ([]Group, erro
226229
})
227230
if appErr != nil {
228231
return nil, fmt.Errorf("creating default private channel %v for team %v: %w", privName, t.Name, appErr)
229-
} else {
230-
allChannels = append(allChannels, ch)
231232
}
232-
m.GroupStore.SaveChannel(ctx, &datastore.ChannelInfo{
233+
allChannels = append(allChannels, ch)
234+
if err := m.GroupStore.SaveChannel(ctx, &datastore.ChannelInfo{
233235
ID: ch.Id,
234236
Name: privName,
235237
MembershipUnmanaged: false,
236-
})
238+
}); err != nil {
239+
l.WithError(err).WithField("channel_id", ch.Id).WithField("channel_name", t.Name).Error("Failed to create default private channel metadata")
240+
}
237241
}
238242
}
239243

@@ -361,7 +365,7 @@ func (m *Mattermost) ensureCredentials(ctx context.Context) error {
361365

362366
roles := u.GetRawRoles()
363367
if !u.IsInRole("system_admin") {
364-
roles = roles + " system_admin"
368+
roles += " system_admin"
365369
}
366370
sess := &model.Session{
367371
UserId: u.Id,

server/syncablesync/mattermostservice_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func (f *fakeMattermost) GetTeams() ([]*model.Team, *model.AppError) {
6666
}
6767

6868
// GetChannel implements mattermostAPI.
69-
func (f *fakeMattermost) GetChannel(channelId string) (*model.Channel, *model.AppError) {
70-
ch, ok := f.channels[channelId]
69+
func (f *fakeMattermost) GetChannel(channelID string) (*model.Channel, *model.AppError) {
70+
ch, ok := f.channels[channelID]
7171
if !ok {
7272
return nil, model.NewAppError("test", "test", nil, "no such channel", 404)
7373
}
@@ -291,8 +291,6 @@ func (f *fakeMattermost) GetAllChannels(ctx context.Context, page int, perPage i
291291

292292
var _ mattermostREST = ((*fakeMattermost)(nil))
293293

294-
func ptr[T any](v T) *T { return &v }
295-
296294
func TestFetchGroupsAndSyncables(t *testing.T) {
297295
mm := &fakeMattermost{
298296
teams: []*model.Team{{

server/syncablesync/syncablesync.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ func (e *Engine) FullSync(ctx context.Context) error {
168168
}
169169
}
170170
}
171-
l.Infof("computed diff (%d adds, %d deletes, %d updates)", len(membersToAdd), len(membersToDelete), len(membersToUpdate))
171+
if len(membersToAdd)+len(membersToDelete)+len(membersToUpdate) > 0 {
172+
l.Infof("computed diff (%d adds, %d deletes, %d updates)", len(membersToAdd), len(membersToDelete), len(membersToUpdate))
173+
} else {
174+
l.Debugf("no-op diff completed")
175+
}
172176

173177
var mergedErr error
174178
if len(membersToAdd) > 0 {
@@ -189,7 +193,11 @@ func (e *Engine) FullSync(ctx context.Context) error {
189193
if mergedErr != nil {
190194
return fmt.Errorf("performing updates for %#v: %w", syncableTarget, mergedErr)
191195
}
192-
l.Infof("applied diff (%d adds, %d deletes, %d updates)", len(membersToAdd), len(membersToDelete), len(membersToUpdate))
196+
if len(membersToAdd)+len(membersToDelete)+len(membersToUpdate) > 0 {
197+
l.Infof("applied diff (%d adds, %d deletes, %d updates)", len(membersToAdd), len(membersToDelete), len(membersToUpdate))
198+
} else {
199+
l.Debugf("no-op diff completed")
200+
}
193201
}
194202
return nil
195203
}

0 commit comments

Comments
 (0)