Skip to content

Commit

Permalink
[MI-2781]:Fixed review comments for issue mattermost#902 and PR matte…
Browse files Browse the repository at this point in the history
…rmost#914 on jira plugin (#36)
  • Loading branch information
Kshitij-Katiyar authored Feb 17, 2023
1 parent 611a8ca commit 6fda5a2
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions server/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,29 +176,22 @@ func (p *Plugin) UninstallInstance(instanceID types.ID, instanceType InstanceTyp
if err != nil {
if strings.Contains(err.Error(), "not found") {
instances.Delete(instanceID)
updated = instances
if err = p.instanceStore.StoreInstances(instances); err != nil {
return err
}
if err = p.disconnectUsers(instance); err != nil {
return err
}
return nil
}
return nil

return err
}
if instanceType != instance.Common().Type {
return errors.Errorf("%s did not match instance %s type %s", instanceType, instanceID, instance.Common().Type)
}

err = p.userStore.MapUsers(func(user *User) error {
if !user.ConnectedInstances.Contains(instance.GetID()) {
return nil
}

_, err = p.disconnectUser(instance, user)
if err != nil {
p.infof("UninstallInstance: failed to disconnect user: %v", err)
}
return nil
})
if err != nil {
if err = p.disconnectUsers(instance); err != nil {
return err
}

Expand All @@ -222,6 +215,24 @@ func (p *Plugin) UninstallInstance(instanceID types.ID, instanceType InstanceTyp
return instance, nil
}

func (p *Plugin) disconnectUsers(instance Instance) error {
err := p.userStore.MapUsers(func(user *User) error {
if !user.ConnectedInstances.Contains(instance.GetID()) {
return nil
}

_, err := p.disconnectUser(instance, user)
if err != nil {
p.infof("UninstallInstance: failed to disconnect user: %v", err)
}
return nil
})
if err != nil {
return err
}
return nil
}

func (p *Plugin) wsInstancesChanged(instances *Instances) {
msg := map[string]interface{}{
"instances": instances.AsConfigMap(),
Expand Down

0 comments on commit 6fda5a2

Please sign in to comment.