Skip to content

Commit

Permalink
Fix run channel attachment promotion (#1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
crspeller committed Mar 28, 2024
1 parent 146f803 commit 939af55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions server/api_runs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ func TestCreateRunInExistingChannel(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, run)
assert.Equal(t, e.BasicPublicChannel.Id, run.ChannelID)

// Verify user was not promoted to admin
member, _, err := e.ServerAdminClient.GetChannelMember(e.BasicPublicChannel.Id, e.RegularUser.Id, "")
require.NoError(t, err)
assert.NotContains(t, member.Roles, model.ChannelAdminRoleId)

})

t.Run("no access to the linked channel", func(t *testing.T) {
Expand Down
20 changes: 12 additions & 8 deletions server/app/playbook_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (s *PlaybookRunServiceImpl) CreatePlaybookRun(playbookRun *PlaybookRun, pb

var err error
var channel *model.Channel
createdChannel := false

if playbookRun.ChannelID == "" {
header := "This channel was created as part of a playbook run. To view more information, select the shield icon then select *Tasks* or *Overview*."
Expand All @@ -252,6 +253,7 @@ func (s *PlaybookRunServiceImpl) CreatePlaybookRun(playbookRun *PlaybookRun, pb
}

playbookRun.ChannelID = channel.Id
createdChannel = true
} else {
channel, err = s.pluginAPI.Channel.Get(playbookRun.ChannelID)
if err != nil {
Expand Down Expand Up @@ -323,7 +325,7 @@ func (s *PlaybookRunServiceImpl) CreatePlaybookRun(playbookRun *PlaybookRun, pb
s.telemetry.CreatePlaybookRun(playbookRun, userID, public)
s.metricsService.IncrementRunsCreatedCount(1)

err = s.addPlaybookRunInitialMemberships(playbookRun, channel)
err = s.addPlaybookRunInitialMemberships(playbookRun, channel, createdChannel)
if err != nil {
return nil, errors.Wrap(err, "failed to setup core memberships at run/channel")
}
Expand Down Expand Up @@ -2401,7 +2403,7 @@ func (s *PlaybookRunServiceImpl) createPlaybookRunChannel(playbookRun *PlaybookR
}

// addPlaybookRunInitialMemberships creates the memberships in run and channels for the most core users: playbooksbot, reporter and owner
func (s *PlaybookRunServiceImpl) addPlaybookRunInitialMemberships(playbookRun *PlaybookRun, channel *model.Channel) error {
func (s *PlaybookRunServiceImpl) addPlaybookRunInitialMemberships(playbookRun *PlaybookRun, channel *model.Channel, createdChannel bool) error {
if _, err := s.pluginAPI.Team.CreateMember(channel.TeamId, s.configService.GetConfiguration().BotUserID); err != nil {
return errors.Wrapf(err, "failed to add bot to the team")
}
Expand All @@ -2421,12 +2423,14 @@ func (s *PlaybookRunServiceImpl) addPlaybookRunInitialMemberships(playbookRun *P
}
}

_, userRoleID, adminRoleID := s.GetSchemeRolesForChannel(channel)
if _, err := s.pluginAPI.Channel.UpdateChannelMemberRoles(channel.Id, playbookRun.OwnerUserID, fmt.Sprintf("%s %s", userRoleID, adminRoleID)); err != nil {
logrus.WithError(err).WithFields(logrus.Fields{
"channel_id": channel.Id,
"owner_user_id": playbookRun.OwnerUserID,
}).Warn("failed to promote owner to admin")
if createdChannel {
_, userRoleID, adminRoleID := s.GetSchemeRolesForChannel(channel)
if _, err := s.pluginAPI.Channel.UpdateChannelMemberRoles(channel.Id, playbookRun.OwnerUserID, fmt.Sprintf("%s %s", userRoleID, adminRoleID)); err != nil {
logrus.WithError(err).WithFields(logrus.Fields{
"channel_id": channel.Id,
"owner_user_id": playbookRun.OwnerUserID,
}).Warn("failed to promote owner to admin")
}
}

// run related
Expand Down

0 comments on commit 939af55

Please sign in to comment.