-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2706 from actiontech/issue-2675-3
feat: implement of system module red dots
- Loading branch information
Showing
9 changed files
with
227 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package v1 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/actiontech/sqle/sqle/model" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
type RedDotModule interface { | ||
Name() string | ||
HasRedDot(ctx echo.Context) (bool, error) | ||
} | ||
|
||
type RedDot struct { | ||
ModuleName string | ||
HasRedDot bool | ||
} | ||
|
||
var redDotList []RedDotModule | ||
|
||
func RegisterRedDotModules(redDotModule ...RedDotModule) { | ||
redDotList = append(redDotList, redDotModule...) | ||
} | ||
|
||
func GetSystemModuleRedDotsList(ctx echo.Context) ([]*RedDot, error) { | ||
redDots := make([]*RedDot, len(redDotList)) | ||
for i, rd := range redDotList { | ||
hasRedDot, err := rd.HasRedDot(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
redDots[i] = &RedDot{ | ||
ModuleName: rd.Name(), | ||
HasRedDot: hasRedDot, | ||
} | ||
} | ||
return redDots, nil | ||
} | ||
|
||
var statusOfGlobalWorkflowToBeFiltered []string = []string{ | ||
model.WorkflowStatusWaitForExecution, | ||
model.WorkflowStatusExecFailed, | ||
model.WorkflowStatusWaitForAudit, | ||
model.WorkflowStatusReject, | ||
} | ||
|
||
// 查询待关注工单,是否有未处理的工单 | ||
func HasOthersWorkflowToHandle(ctx context.Context, user *model.User, userVisibility GlobalDashBoardVisibility) (has bool, err error) { | ||
filter, err := constructGlobalWorkflowBasicFilter(ctx, user, userVisibility, &globalWorkflowBasicFilter{ | ||
FilterStatusList: statusOfGlobalWorkflowToBeFiltered, | ||
}) | ||
if err != nil { | ||
return false, err | ||
} | ||
s := model.GetStorage() | ||
total, err := s.GetGlobalWorkflowTotalNum(filter) | ||
if err != nil { | ||
return false, err | ||
} | ||
if total > 0 { | ||
return true, nil | ||
} | ||
return false, nil | ||
} | ||
|
||
// 查询创建的工单,是否有未处理的工单 | ||
func HasMyWorkflowToHandle(ctx context.Context, user *model.User, userVisibility GlobalDashBoardVisibility) (has bool, err error) { | ||
filter, err := constructGlobalWorkflowBasicFilter(ctx, user, userVisibility, &globalWorkflowBasicFilter{ | ||
FilterStatusList: statusOfGlobalWorkflowToBeFiltered, | ||
FilterCreateUserId: user.GetIDStr(), | ||
}) | ||
if err != nil { | ||
return false, err | ||
} | ||
s := model.GetStorage() | ||
total, err := s.GetGlobalWorkflowTotalNum(filter) | ||
if err != nil { | ||
return false, err | ||
} | ||
if total > 0 { | ||
return true, nil | ||
} | ||
return false, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//go:build !enterprise | ||
// +build !enterprise | ||
|
||
package v1 | ||
|
||
import ( | ||
"github.com/actiontech/dms/pkg/dms-common/dmsobject" | ||
"github.com/actiontech/sqle/sqle/api/controller" | ||
dms "github.com/actiontech/sqle/sqle/dms" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func init() { | ||
RegisterRedDotModules(GlobalDashBoardModule{}) | ||
} | ||
|
||
type GlobalDashBoardModule struct{} | ||
|
||
func (m GlobalDashBoardModule) Name() string { | ||
return "global_dashboard" | ||
} | ||
|
||
func (m GlobalDashBoardModule) HasRedDot(ctx echo.Context) (bool, error) { | ||
user, err := controller.GetCurrentUser(ctx, dms.GetUser) | ||
if err != nil { | ||
return false, err | ||
} | ||
permissions, isAdmin, err := dmsobject.GetUserOpPermission(ctx.Request().Context(), "", user.GetIDStr(), dms.GetDMSServerAddress()) | ||
if err != nil { | ||
return false, err | ||
} | ||
// 将用户权限信息,转化为全局待处理清单统一的用户可见性 | ||
userVisibility := getGlobalDashBoardVisibilityOfUser(isAdmin, permissions) | ||
has, err := HasOthersWorkflowToHandle(ctx.Request().Context(), user, userVisibility) | ||
if err != nil { | ||
return false, err | ||
} | ||
if has { | ||
return true, nil | ||
} | ||
|
||
has, err = HasMyWorkflowToHandle(ctx.Request().Context(), user, userVisibility) | ||
if err != nil { | ||
return false, err | ||
} | ||
return has, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters