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
26 changes: 26 additions & 0 deletions app/cc/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"

"github.com/webitel/engine/gen/cc"
"github.com/webitel/engine/gen/engine"
"github.com/webitel/engine/model"
"github.com/webitel/engine/pkg/wbt"
)

Expand All @@ -26,6 +28,30 @@ func (api *agentApi) Online(domainId, agentId int64, onDemand bool) error {
return err
}

func (api *agentApi) OnlineWithStatus(ctx context.Context, r *model.AgentLoginRequest) error {
var onlineStatus *engine.Lookup
if r.OnlineStatus != nil {
onlineStatus = &engine.Lookup{
Id: int64(r.OnlineStatus.Id),
Name: r.OnlineStatus.Name,
}
}

if _, err := api.Api.Online(
ctx,
&cc.OnlineRequest{
AgentId: r.AgentID,
OnDemand: r.OnDemand,
DomainId: r.DomainID,
Status: onlineStatus,
},
); err != nil {
return err
}

return nil
}

func (api *agentApi) Offline(domainId, agentId int64) error {
_, err := api.Api.Offline(context.TODO(), &cc.OfflineRequest{
AgentId: agentId,
Expand Down
2 changes: 2 additions & 0 deletions app/cc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync"

"github.com/webitel/engine/gen/cc"
"github.com/webitel/engine/model"
"github.com/webitel/engine/pkg/wbt"
"github.com/webitel/wlog"
)
Expand All @@ -13,6 +14,7 @@ const ServiceName = "call_center"

type AgentApi interface {
Online(domainId, agentId int64, onDemand bool) error
OnlineWithStatus(ctx context.Context, r *model.AgentLoginRequest) error
Offline(domainId, agentId int64) error
Pause(domainId, agentId int64, payload, statusComment string, timeout int) error

Expand Down
8 changes: 8 additions & 0 deletions app/cc_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ func (a *App) AgentCC(ctx context.Context, domainId int64, userId int64) (*model
return a.Store.Agent().AgentCC(ctx, domainId, userId)
}

func (a *App) LoginAgentFromRequest(ctx context.Context, r *model.AgentLoginRequest) model.AppError {
if err := a.cc.Agent().OnlineWithStatus(ctx, r); err != nil {
return model.NewBadRequestError("app.agent.login.app_err", err.Error())
}

return nil
}

func (a *App) LoginAgent(domainId, agentId int64, onDemand bool) model.AppError {
err := a.cc.Agent().Online(domainId, agentId, onDemand)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions controller/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ func (c *Controller) GetAgentSession(ctx context.Context, session *auth_manager.
return c.app.GetAgentSession(ctx, session.Domain(domainId), userId)
}

func (c *Controller) LoginAgentFromRequest(ctx context.Context, session *auth_manager.Session, r *model.AgentLoginRequest) model.AppError {
if err := r.Validate(); err != nil {
return err
}

permission := session.GetPermission(model.PERMISSION_SCOPE_CC_AGENT)
if !permission.CanRead() {
return c.app.MakePermissionError(session, permission, auth_manager.PERMISSION_ACCESS_READ)
}

if session.UseRBAC(auth_manager.PERMISSION_ACCESS_READ, permission) {
if perm, err := c.app.AgentCheckAccess(ctx, session.Domain(r.DomainID), r.AgentID, session.GetAclRoles(), auth_manager.PERMISSION_ACCESS_READ); err != nil {
return err
} else if !perm {
return c.app.MakeResourcePermissionError(session, r.AgentID, permission, auth_manager.PERMISSION_ACCESS_READ)
}
}

return c.app.LoginAgentFromRequest(ctx, r)
}

// DEPRECATED
func (c *Controller) LoginAgent(ctx context.Context, session *auth_manager.Session, domainId, agentId int64, onDemand bool) model.AppError {
permission := session.GetPermission(model.PERMISSION_SCOPE_CC_AGENT)
if !permission.CanRead() {
Expand Down
286 changes: 150 additions & 136 deletions gen/cc/cc_agent.pb.go

Large diffs are not rendered by default.

Loading
Loading