Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MI-2781]:Fixed review comments for issue #902 and PR #914 on jira plugin #36

Merged
merged 1 commit into from
Feb 17, 2023
Merged
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
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