mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 00:57:44 +01:00
Merge pull request #2631 from ywk253100/170626_statistic
Refactor statistics API to return private/public count of projects and repositories
This commit is contained in:
commit
2ada2dbd16
@ -2005,14 +2005,14 @@ definitions:
|
||||
StatisticMap:
|
||||
type: object
|
||||
properties:
|
||||
my_project_count:
|
||||
private_project_count:
|
||||
type: integer
|
||||
format: int32
|
||||
description: The count of the projects which the user is a member of.
|
||||
my_repo_count:
|
||||
description: The count of the private projects which the user is a member of.
|
||||
private_repo_count:
|
||||
type: integer
|
||||
format: int32
|
||||
description: The count of the repositories belonging to the projects which the user is a member of.
|
||||
description: The count of the private repositories belonging to the projects which the user is a member of.
|
||||
public_project_count:
|
||||
type: integer
|
||||
format: int32
|
||||
|
@ -24,14 +24,14 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// MPC : count of my projects
|
||||
MPC = "my_project_count"
|
||||
// MRC : count of my repositories
|
||||
MRC = "my_repo_count"
|
||||
// PPC : count of public projects
|
||||
PPC = "public_project_count"
|
||||
// PRC : count of public repositories
|
||||
PRC = "public_repo_count"
|
||||
// PriPC : count of private projects
|
||||
PriPC = "private_project_count"
|
||||
// PriRC : count of private repositories
|
||||
PriRC = "private_repo_count"
|
||||
// PubPC : count of public projects
|
||||
PubPC = "public_project_count"
|
||||
// PubRC : count of public repositories
|
||||
PubRC = "public_repo_count"
|
||||
// TPC : total count of projects
|
||||
TPC = "total_project_count"
|
||||
// TRC : total count of repositories
|
||||
@ -57,17 +57,17 @@ func (s *StatisticAPI) Prepare() {
|
||||
// Get total projects and repos of the user
|
||||
func (s *StatisticAPI) Get() {
|
||||
statistic := map[string]int64{}
|
||||
projects, err := s.ProjectMgr.GetPublic()
|
||||
pubProjs, err := s.ProjectMgr.GetPublic()
|
||||
if err != nil {
|
||||
s.HandleInternalServerError(fmt.Sprintf(
|
||||
"failed to get public projects: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
statistic[PPC] = (int64)(len(projects))
|
||||
statistic[PubPC] = (int64)(len(pubProjs))
|
||||
|
||||
ids := []int64{}
|
||||
for _, p := range projects {
|
||||
for _, p := range pubProjs {
|
||||
ids = append(ids, p.ProjectID)
|
||||
}
|
||||
n, err := dao.GetTotalOfRepositoriesByProject(ids, "")
|
||||
@ -75,7 +75,7 @@ func (s *StatisticAPI) Get() {
|
||||
log.Errorf("failed to get total of public repositories: %v", err)
|
||||
s.CustomAbort(http.StatusInternalServerError, "")
|
||||
}
|
||||
statistic[PRC] = n
|
||||
statistic[PubRC] = n
|
||||
|
||||
if s.SecurityCtx.IsSysAdmin() {
|
||||
n, err := dao.GetTotalOfProjects(nil)
|
||||
@ -83,18 +83,20 @@ func (s *StatisticAPI) Get() {
|
||||
log.Errorf("failed to get total of projects: %v", err)
|
||||
s.CustomAbort(http.StatusInternalServerError, "")
|
||||
}
|
||||
statistic[MPC] = n
|
||||
statistic[TPC] = n
|
||||
statistic[PriPC] = n - statistic[PubPC]
|
||||
|
||||
n, err = dao.GetTotalOfRepositories("")
|
||||
if err != nil {
|
||||
log.Errorf("failed to get total of repositories: %v", err)
|
||||
s.CustomAbort(http.StatusInternalServerError, "")
|
||||
}
|
||||
statistic[MRC] = n
|
||||
statistic[TRC] = n
|
||||
statistic[PriRC] = n - statistic[PubRC]
|
||||
} else {
|
||||
value := false
|
||||
projects, err := s.ProjectMgr.GetAll(&models.ProjectQueryParam{
|
||||
Public: &value,
|
||||
Member: &models.MemberQuery{
|
||||
Name: s.username,
|
||||
},
|
||||
@ -104,7 +106,8 @@ func (s *StatisticAPI) Get() {
|
||||
"failed to get projects of user %s: %v", s.username, err))
|
||||
return
|
||||
}
|
||||
statistic[MPC] = (int64)(len(projects))
|
||||
|
||||
statistic[PriPC] = (int64)(len(projects))
|
||||
|
||||
ids := []int64{}
|
||||
for _, p := range projects {
|
||||
@ -118,7 +121,7 @@ func (s *StatisticAPI) Get() {
|
||||
s.username, err))
|
||||
return
|
||||
}
|
||||
statistic[MRC] = n
|
||||
statistic[PriRC] = n
|
||||
}
|
||||
|
||||
s.Data["json"] = statistic
|
||||
|
@ -30,7 +30,7 @@ func TestStatisticGet(t *testing.T) {
|
||||
|
||||
//prepare for test
|
||||
|
||||
var priMyProjectCount, priMyRepoCount int32
|
||||
var privateProjectCount, privateRepoCount int32
|
||||
var priPublicProjectCount, priPublicRepoCount int32
|
||||
var priTotalProjectCount, priTotalRepoCount int32
|
||||
|
||||
@ -53,8 +53,8 @@ func TestStatisticGet(t *testing.T) {
|
||||
} else {
|
||||
assert.Equal(httpStatusCode, int(200), "Case 2: Get status info with admin login. (200)")
|
||||
//fmt.Println("pri status data %+v", result)
|
||||
priMyProjectCount = result.MyProjectCount
|
||||
priMyRepoCount = result.MyRepoCount
|
||||
privateProjectCount = result.PrivateProjectCount
|
||||
privateRepoCount = result.PrivateRepoCount
|
||||
priPublicProjectCount = result.PublicProjectCount
|
||||
priPublicRepoCount = result.PublicRepoCount
|
||||
priTotalProjectCount = result.TotalProjectCount
|
||||
@ -74,8 +74,8 @@ func TestStatisticGet(t *testing.T) {
|
||||
t.Error("Error while get statistic information", err.Error())
|
||||
t.Log(err)
|
||||
} else {
|
||||
assert.Equal(priMyProjectCount+1, result.MyProjectCount, "MyProjectCount should be +1")
|
||||
assert.Equal(priMyRepoCount+1, result.MyRepoCount, "MyRepoCount should be +1")
|
||||
assert.Equal(privateProjectCount+1, result.PrivateProjectCount, "PrivateProjectCount should be +1")
|
||||
assert.Equal(privateRepoCount, result.PrivateRepoCount)
|
||||
assert.Equal(priPublicProjectCount, result.PublicProjectCount, "PublicProjectCount should be equal")
|
||||
assert.Equal(priPublicRepoCount+1, result.PublicRepoCount, "PublicRepoCount should be +1")
|
||||
assert.Equal(priTotalProjectCount+1, result.TotalProjectCount, "TotalProCount should be +1")
|
||||
|
@ -12,10 +12,10 @@
|
||||
</div>
|
||||
<div class="statistic-column-block" style="margin-left: 16px;">
|
||||
<div>
|
||||
<statistics [data]='originalCopy.my_project_count' [label]='"STATISTICS.INDEX_PRIVATE" | translate'></statistics>
|
||||
<statistics [data]='originalCopy.private_project_count' [label]='"STATISTICS.INDEX_PRIVATE" | translate'></statistics>
|
||||
</div>
|
||||
<div>
|
||||
<statistics [data]='originalCopy.my_repo_count' [label]='"STATISTICS.INDEX_PRIVATE" | translate'></statistics>
|
||||
<statistics [data]='originalCopy.private_repo_count' [label]='"STATISTICS.INDEX_PRIVATE" | translate'></statistics>
|
||||
</div>
|
||||
</div>
|
||||
<div class="statistic-column-block" style="margin-left: 28px;">
|
||||
|
@ -14,8 +14,8 @@
|
||||
export class Statistics {
|
||||
constructor() {}
|
||||
|
||||
my_project_count: number;
|
||||
my_repo_count: number;
|
||||
private_project_count: number;
|
||||
private_repo_count: number;
|
||||
public_project_count: number;
|
||||
public_repo_count: number;
|
||||
total_project_count: number;
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
/*
|
||||
* Harbor API
|
||||
*
|
||||
* These APIs provide services for manipulating Harbor project.
|
||||
*
|
||||
* OpenAPI spec version: 0.3.0
|
||||
*
|
||||
*
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -24,11 +24,11 @@ package apilib
|
||||
|
||||
type StatisticMap struct {
|
||||
|
||||
// The count of the projects which the user is a member of.
|
||||
MyProjectCount int32 `json:"my_project_count,omitempty"`
|
||||
// The count of the private projects which the user is a member of.
|
||||
PrivateProjectCount int32 `json:"private_project_count,omitempty"`
|
||||
|
||||
// The count of the repositories belonging to the projects which the user is a member of.
|
||||
MyRepoCount int32 `json:"my_repo_count,omitempty"`
|
||||
// The count of the private repositories belonging to the projects which the user is a member of.
|
||||
PrivateRepoCount int32 `json:"private_repo_count,omitempty"`
|
||||
|
||||
// The count of the public projects.
|
||||
PublicProjectCount int32 `json:"public_project_count,omitempty"`
|
||||
|
Loading…
Reference in New Issue
Block a user