get devops count by username
Signed-off-by: runzexia <runzexia@yunify.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
package v1alpha1
|
package v1alpha1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"kubesphere.io/kubesphere/pkg/apis/network/v1alpha1/numorstring"
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"kubesphere.io/kubesphere/pkg/apis/network/v1alpha1/numorstring"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Rule encapsulates a set of match criteria and an action. Both selector-based security Policy
|
// A Rule encapsulates a set of match criteria and an action. Both selector-based security Policy
|
||||||
|
|||||||
@@ -134,6 +134,14 @@ func addWebService(c *restful.Container) error {
|
|||||||
Returns(http.StatusOK, ok, models.PageableResponse{}).
|
Returns(http.StatusOK, ok, models.PageableResponse{}).
|
||||||
Doc("List the devops projects for the workspace member").
|
Doc("List the devops projects for the workspace member").
|
||||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.TenantResourcesTag}))
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.TenantResourcesTag}))
|
||||||
|
ws.Route(ws.GET("/devopscount").
|
||||||
|
To(tenant.GetDevOpsProjectsCount).
|
||||||
|
Param(ws.PathParameter("member", "workspace member's username")).
|
||||||
|
Returns(http.StatusOK, ok, struct {
|
||||||
|
Count uint32 `json:"count"`
|
||||||
|
}{}).
|
||||||
|
Doc("Get the devops projects count for the member").
|
||||||
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.TenantResourcesTag}))
|
||||||
ws.Route(ws.POST("/workspaces/{workspace}/devops").
|
ws.Route(ws.POST("/workspaces/{workspace}/devops").
|
||||||
To(tenant.CreateDevopsProject).
|
To(tenant.CreateDevopsProject).
|
||||||
Param(ws.PathParameter("workspace", "workspace name")).
|
Param(ws.PathParameter("workspace", "workspace name")).
|
||||||
|
|||||||
@@ -244,6 +244,19 @@ func ListDevopsProjects(req *restful.Request, resp *restful.Response) {
|
|||||||
resp.WriteAsJson(result)
|
resp.WriteAsJson(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDevOpsProjectsCount(req *restful.Request, resp *restful.Response) {
|
||||||
|
username := req.HeaderParameter(constants.UserNameHeader)
|
||||||
|
|
||||||
|
result, err := tenant.GetDevOpsProjectsCount(username)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("%+v", err)
|
||||||
|
errors.ParseSvcErr(err, resp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.WriteAsJson(struct {
|
||||||
|
Count uint32 `json:"count"`
|
||||||
|
}{Count: result})
|
||||||
|
}
|
||||||
func DeleteDevopsProject(req *restful.Request, resp *restful.Response) {
|
func DeleteDevopsProject(req *restful.Request, resp *restful.Response) {
|
||||||
projectId := req.PathParameter("devops")
|
projectId := req.PathParameter("devops")
|
||||||
workspaceName := req.PathParameter("workspace")
|
workspaceName := req.PathParameter("workspace")
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/emicklei/go-restful"
|
"github.com/emicklei/go-restful"
|
||||||
"github.com/gocraft/dbr"
|
"github.com/gocraft/dbr"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
"k8s.io/klog"
|
||||||
"kubesphere.io/kubesphere/pkg/db"
|
"kubesphere.io/kubesphere/pkg/db"
|
||||||
"kubesphere.io/kubesphere/pkg/gojenkins"
|
"kubesphere.io/kubesphere/pkg/gojenkins"
|
||||||
"kubesphere.io/kubesphere/pkg/gojenkins/utils"
|
"kubesphere.io/kubesphere/pkg/gojenkins/utils"
|
||||||
@@ -105,6 +106,36 @@ func ListDevopsProjects(workspace, username string, conditions *params.Condition
|
|||||||
return &models.PageableResponse{Items: result, TotalCount: int(count)}, nil
|
return &models.PageableResponse{Items: result, TotalCount: int(count)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDevOpsProjectsCount(username string) (uint32, error) {
|
||||||
|
dbconn := devops_mysql.OpenDatabase()
|
||||||
|
|
||||||
|
query := dbconn.Select(devops.GetColumnsFromStructWithPrefix(devops.DevOpsProjectTableName, devops.DevOpsProject{})...).
|
||||||
|
From(devops.DevOpsProjectTableName)
|
||||||
|
var sqconditions []dbr.Builder
|
||||||
|
|
||||||
|
switch username {
|
||||||
|
case devops.KS_ADMIN:
|
||||||
|
default:
|
||||||
|
onCondition := fmt.Sprintf("%s = %s", devops.DevOpsProjectMembershipProjectIdColumn, devops.DevOpsProjectIdColumn)
|
||||||
|
query.Join(devops.DevOpsProjectMembershipTableName, onCondition)
|
||||||
|
sqconditions = append(sqconditions, db.Eq(devops.DevOpsProjectMembershipUsernameColumn, username))
|
||||||
|
sqconditions = append(sqconditions, db.Eq(
|
||||||
|
devops.DevOpsProjectMembershipTableName+"."+devops.StatusColumn, devops.StatusActive))
|
||||||
|
}
|
||||||
|
|
||||||
|
sqconditions = append(sqconditions, db.Eq(
|
||||||
|
devops.DevOpsProjectTableName+"."+devops.StatusColumn, devops.StatusActive))
|
||||||
|
if len(sqconditions) > 0 {
|
||||||
|
query.Where(db.And(sqconditions...))
|
||||||
|
}
|
||||||
|
count, err := query.Count()
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("%+v", err)
|
||||||
|
return 0, restful.NewError(http.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
func DeleteDevOpsProject(projectId, username string) error {
|
func DeleteDevOpsProject(projectId, username string) error {
|
||||||
err := devops.CheckProjectUserInRole(username, projectId, []string{devops.ProjectOwner})
|
err := devops.CheckProjectUserInRole(username, projectId, []string{devops.ProjectOwner})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user