Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions app/cc_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,18 @@ func (app *App) PatchMember(ctx context.Context, domainId, queueId, id int64, pa
return oldMember, nil
}

func (app *App) RemoveMember(ctx context.Context, domainId, queueId, id int64) (*model.Member, model.AppError) {
func (app *App) RemoveMember(ctx context.Context, domainId, queueId, id int64, force bool) (*model.Member, model.AppError) {
member, err := app.GetMember(ctx, domainId, queueId, id)

if err != nil {
return nil, err
}

err = app.Store.Member().Delete(ctx, queueId, id)
if !force && member.Reserved {
return nil, model.NewBadRequestError("member.reserved", "Member is reserved")
}

err = app.Store.Member().Delete(ctx, queueId, id, force)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion grpc_api/cc_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,10 @@ func (api *member) DeleteMember(ctx context.Context, in *engine.DeleteMemberRequ
}
}

const force = false

var m *model.Member
m, err = api.app.RemoveMember(ctx, session.Domain(in.GetDomainId()), in.GetQueueId(), in.GetId())
m, err = api.app.RemoveMember(ctx, session.Domain(in.GetDomainId()), in.GetQueueId(), in.GetId(), force)
if err != nil {
return nil, err
}
Expand Down
11 changes: 7 additions & 4 deletions store/sqlstore/cc_member_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,18 @@ from m
return member, nil
}

// TODO add force
func (s SqlMemberStore) Delete(ctx context.Context, queueId, id int64) model.AppError {
func (s SqlMemberStore) Delete(ctx context.Context, queueId, id int64, force bool) model.AppError {
var cnt int64
res, err := s.GetMaster().WithContext(ctx).Exec(`delete
from call_center.cc_member c
where c.id = :Id
and c.queue_id = :QueueId
and not exists(select 1 from call_center.cc_member_attempt a where a.member_id = c.id and a.state != 'leaving' for update)`,
map[string]interface{}{"Id": id, "QueueId": queueId})
and not exists(select 1 from call_center.cc_member_attempt a where not :Force::bool and a.member_id = c.id and a.state != 'leaving' for update)`,
map[string]interface{}{
"Id": id,
"QueueId": queueId,
"Force": force,
})

if err != nil {
return model.NewCustomCodeError("store.sql_member.delete.app_error", fmt.Sprintf("Id=%v, %s", id, err.Error()), extractCodeFromErr(err))
Expand Down
2 changes: 1 addition & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ type MemberStore interface {
SearchMembers(ctx context.Context, domainId int64, search *model.SearchMemberRequest) ([]*model.Member, model.AppError)
Get(ctx context.Context, domainId, queueId, id int64) (*model.Member, model.AppError)
Update(ctx context.Context, domainId int64, member *model.Member) (*model.Member, model.AppError)
Delete(ctx context.Context, queueId, id int64) model.AppError
Delete(ctx context.Context, queueId, id int64, force bool) model.AppError
MultiDelete(ctx context.Context, domainId int64, del *model.MultiDeleteMembers, withoutMembers bool) ([]*model.Member, model.AppError)
ResetMembers(ctx context.Context, domainId int64, req *model.ResetMembers) (int64, model.AppError)

Expand Down