Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add project environement and user count organization list API #1244

Merged
merged 5 commits into from
Sep 18, 2024
Merged
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
9 changes: 9 additions & 0 deletions api-description/web-api.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,15 @@ definitions:
format: int64
systemAdmin:
type: boolean
projectCount:
type: integer
format: int32
environmentCount:
type: integer
format: int32
userCount:
type: integer
format: int32
environmentArchiveEnvironmentV2Command:
type: object
environmentArchiveEnvironmentV2Request:
Expand Down
6 changes: 3 additions & 3 deletions manifests/bucketeer/charts/web/values.yaml

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions pkg/environment/api/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ func (s *EnvironmentService) ListOrganizations(
}
whereParts := []mysql.WherePart{}
if req.Disabled != nil {
whereParts = append(whereParts, mysql.NewFilter("disabled", "=", req.Disabled.Value))
whereParts = append(whereParts, mysql.NewFilter("organization.disabled", "=", req.Disabled.Value))
}
if req.Archived != nil {
whereParts = append(whereParts, mysql.NewFilter("archived", "=", req.Archived.Value))
whereParts = append(whereParts, mysql.NewFilter("organization.archived", "=", req.Archived.Value))
}
if req.SearchKeyword != "" {
whereParts = append(
whereParts,
mysql.NewSearchQuery(
[]string{"id", "name", "url_code"},
[]string{"organization.id", "organization.name", "organization.url_code"},
req.SearchKeyword,
),
)
Expand Down Expand Up @@ -192,15 +192,15 @@ func (s *EnvironmentService) newOrganizationListOrders(
switch orderBy {
case environmentproto.ListOrganizationsRequest_DEFAULT,
environmentproto.ListOrganizationsRequest_NAME:
column = "name"
column = "organization.name"
case environmentproto.ListOrganizationsRequest_URL_CODE:
column = "url_code"
column = "organization.url_code"
case environmentproto.ListOrganizationsRequest_ID:
column = "id"
column = "organization.id"
case environmentproto.ListOrganizationsRequest_CREATED_AT:
column = "created_at"
column = "organization.created_at"
case environmentproto.ListOrganizationsRequest_UPDATED_AT:
column = "updated_at"
column = "organization.updated_at"
default:
dt, err := statusInvalidOrderBy.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Expand Down
3 changes: 3 additions & 0 deletions pkg/environment/storage/v2/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ func (s *organizationStorage) ListOrganizations(
&organization.SystemAdmin,
&organization.CreatedAt,
&organization.UpdatedAt,
&organization.ProjectCount,
&organization.EnvironmentCount,
&organization.UserCount,
)
if err != nil {
return nil, 0, 0, err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
SELECT
id,
name,
url_code,
description,
disabled,
archived,
trial,
system_admin,
created_at,
updated_at
organization.id,
organization.name,
organization.url_code,
organization.description,
organization.disabled,
organization.archived,
organization.trial,
organization.system_admin,
organization.created_at,
organization.updated_at,
COUNT(DISTINCT project.id) AS projects,
COUNT(DISTINCT environment_v2.id) AS environments,
COUNT(DISTINCT account_v2.email) AS users
FROM
organization
%s %s %s
LEFT JOIN project ON organization.id = project.organization_id
LEFT JOIN environment_v2 ON organization.id = environment_v2.organization_id
LEFT JOIN account_v2 ON organization.id = account_v2.organization_id
%s
GROUP BY
organization.id,
organization.name,
organization.url_code,
organization.description,
organization.disabled,
organization.archived,
organization.trial,
organization.system_admin,
organization.created_at,
organization.updated_at
%s
%s
Binary file modified proto/account/proto_descriptor.pb
Binary file not shown.
Binary file modified proto/auditlog/proto_descriptor.pb
Binary file not shown.
63 changes: 47 additions & 16 deletions proto/environment/organization.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions proto/environment/organization.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ message Organization {
int64 created_at = 8;
int64 updated_at = 9;
bool system_admin = 10;
int32 project_count = 11;
int32 environment_count = 12;
int32 user_count = 13;
}
Binary file modified proto/environment/proto_descriptor.pb
Binary file not shown.
15 changes: 15 additions & 0 deletions proto/proto.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7521,6 +7521,21 @@
"id": 10,
"name": "system_admin",
"type": "bool"
},
{
"id": 11,
"name": "project_count",
"type": "int32"
},
{
"id": 12,
"name": "environment_count",
"type": "int32"
},
{
"id": 13,
"name": "user_count",
"type": "int32"
}
]
}
Expand Down
12 changes: 12 additions & 0 deletions ui/web-v2/src/proto/environment/organization_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export class Organization extends jspb.Message {
getSystemAdmin(): boolean;
setSystemAdmin(value: boolean): void;

getProjectCount(): number;
setProjectCount(value: number): void;

getEnvironmentCount(): number;
setEnvironmentCount(value: number): void;

getUserCount(): number;
setUserCount(value: number): void;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): Organization.AsObject;
static toObject(
Expand Down Expand Up @@ -67,5 +76,8 @@ export namespace Organization {
createdAt: number;
updatedAt: number;
systemAdmin: boolean;
projectCount: number;
environmentCount: number;
userCount: number;
};
}
88 changes: 87 additions & 1 deletion ui/web-v2/src/proto/environment/organization_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ if (jspb.Message.GENERATE_TO_OBJECT) {
trial: jspb.Message.getBooleanFieldWithDefault(msg, 7, false),
createdAt: jspb.Message.getFieldWithDefault(msg, 8, 0),
updatedAt: jspb.Message.getFieldWithDefault(msg, 9, 0),
systemAdmin: jspb.Message.getBooleanFieldWithDefault(msg, 10, false)
systemAdmin: jspb.Message.getBooleanFieldWithDefault(msg, 10, false),
projectCount: jspb.Message.getFieldWithDefault(msg, 11, 0),
environmentCount: jspb.Message.getFieldWithDefault(msg, 12, 0),
userCount: jspb.Message.getFieldWithDefault(msg, 13, 0)
};

if (includeInstance) {
Expand Down Expand Up @@ -172,6 +175,18 @@ proto.bucketeer.environment.Organization.deserializeBinaryFromReader =
var value = /** @type {boolean} */ (reader.readBool());
msg.setSystemAdmin(value);
break;
case 11:
var value = /** @type {number} */ (reader.readInt32());
msg.setProjectCount(value);
break;
case 12:
var value = /** @type {number} */ (reader.readInt32());
msg.setEnvironmentCount(value);
break;
case 13:
var value = /** @type {number} */ (reader.readInt32());
msg.setUserCount(value);
break;
default:
reader.skipField();
break;
Expand Down Expand Up @@ -246,6 +261,18 @@ proto.bucketeer.environment.Organization.serializeBinaryToWriter = function (
if (f) {
writer.writeBool(10, f);
}
f = message.getProjectCount();
if (f !== 0) {
writer.writeInt32(11, f);
}
f = message.getEnvironmentCount();
if (f !== 0) {
writer.writeInt32(12, f);
}
f = message.getUserCount();
if (f !== 0) {
writer.writeInt32(13, f);
}
};

/**
Expand Down Expand Up @@ -434,4 +461,63 @@ proto.bucketeer.environment.Organization.prototype.setSystemAdmin = function (
return jspb.Message.setProto3BooleanField(this, 10, value);
};

/**
* optional int32 project_count = 11;
* @return {number}
*/
proto.bucketeer.environment.Organization.prototype.getProjectCount =
function () {
return /** @type {number} */ (
jspb.Message.getFieldWithDefault(this, 11, 0)
);
};

/**
* @param {number} value
* @return {!proto.bucketeer.environment.Organization} returns this
*/
proto.bucketeer.environment.Organization.prototype.setProjectCount = function (
value
) {
return jspb.Message.setProto3IntField(this, 11, value);
};

/**
* optional int32 environment_count = 12;
* @return {number}
*/
proto.bucketeer.environment.Organization.prototype.getEnvironmentCount =
function () {
return /** @type {number} */ (
jspb.Message.getFieldWithDefault(this, 12, 0)
);
};

/**
* @param {number} value
* @return {!proto.bucketeer.environment.Organization} returns this
*/
proto.bucketeer.environment.Organization.prototype.setEnvironmentCount =
function (value) {
return jspb.Message.setProto3IntField(this, 12, value);
};

/**
* optional int32 user_count = 13;
* @return {number}
*/
proto.bucketeer.environment.Organization.prototype.getUserCount = function () {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 13, 0));
};

/**
* @param {number} value
* @return {!proto.bucketeer.environment.Organization} returns this
*/
proto.bucketeer.environment.Organization.prototype.setUserCount = function (
value
) {
return jspb.Message.setProto3IntField(this, 13, value);
};

goog.object.extend(exports, proto.bucketeer.environment);
Loading