feat: org remove on admin api and org query with state (#4917)

* feat: org remove on admin api and org query with state

* docs: change description for admin api remove org

Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
Stefan Benz
2022-12-22 10:46:06 +00:00
committed by GitHub
parent a99da4f8e4
commit 7d9fc2c6e7
7 changed files with 130 additions and 0 deletions

View File

@@ -430,6 +430,19 @@ and adds the user to the orgs members as ORG_OWNER
POST: /orgs/_setup
### RemoveOrg
> **rpc** RemoveOrg([RemoveOrgRequest](#removeorgrequest))
[RemoveOrgResponse](#removeorgresponse)
Sets the state of the organisation and all its resource (Users, Projects, Grants to and from the org) to removed
Users of this organisation will not be able login
DELETE: /orgs/{org_id}
### GetIDPByID
> **rpc** GetIDPByID([GetIDPByIDRequest](#getidpbyidrequest))
@@ -3533,6 +3546,28 @@ This is an empty request
### RemoveOrgRequest
| Field | Type | Description | Validation |
| ----- | ---- | ----------- | ----------- |
| org_id | string | - | string.min_len: 1<br /> string.max_len: 200<br /> |
### RemoveOrgResponse
| Field | Type | Description | Validation |
| ----- | ---- | ----------- | ----------- |
| details | zitadel.v1.ObjectDetails | - | |
### RemoveSMSProviderRequest

View File

@@ -95,6 +95,18 @@ title: zitadel/org.proto
| ----- | ---- | ----------- | ----------- |
| [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) query.name_query | OrgNameQuery | - | |
| [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) query.domain_query | OrgDomainQuery | - | |
| [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) query.state_query | OrgStateQuery | - | |
### OrgStateQuery
| Field | Type | Description | Validation |
| ----- | ---- | ----------- | ----------- |
| state | OrgState | - | enum.defined_only: true<br /> |

View File

@@ -27,6 +27,16 @@ func (s *Server) SetDefaultOrg(ctx context.Context, req *admin_pb.SetDefaultOrgR
}, nil
}
func (s *Server) RemoveOrg(ctx context.Context, req *admin_pb.RemoveOrgRequest) (*admin_pb.RemoveOrgResponse, error) {
details, err := s.command.RemoveOrg(ctx, req.OrgId)
if err != nil {
return nil, err
}
return &admin_pb.RemoveOrgResponse{
Details: object.DomainToChangeDetailsPb(details),
}, nil
}
func (s *Server) GetDefaultOrg(ctx context.Context, _ *admin_pb.GetDefaultOrgRequest) (*admin_pb.GetDefaultOrgResponse, error) {
org, err := s.query.OrgByID(ctx, true, authz.GetInstance(ctx).DefaultOrganisationID())
return &admin_pb.GetDefaultOrgResponse{Org: org_grpc.OrgToPb(org)}, err

View File

@@ -25,6 +25,8 @@ func OrgQueryToModel(apiQuery *org_pb.OrgQuery) (query.SearchQuery, error) {
return query.NewOrgDomainSearchQuery(object.TextMethodToQuery(q.DomainQuery.Method), q.DomainQuery.Domain)
case *org_pb.OrgQuery_NameQuery:
return query.NewOrgNameSearchQuery(object.TextMethodToQuery(q.NameQuery.Method), q.NameQuery.Name)
case *org_pb.OrgQuery_StateQuery:
return query.NewOrgStateSearchQuery(int32(q.StateQuery.State))
default:
return nil, errors.ThrowInvalidArgument(nil, "ORG-vR9nC", "List.Query.Invalid")
}

View File

@@ -215,6 +215,10 @@ func NewOrgNameSearchQuery(method TextComparison, value string) (SearchQuery, er
return NewTextQuery(OrgColumnName, value, method)
}
func NewOrgStateSearchQuery(value int32) (SearchQuery, error) {
return NewNumberQuery(OrgColumnState, value, NumberEquals)
}
func NewOrgIDsSearchQuery(ids ...string) (SearchQuery, error) {
list := make([]interface{}, len(ids))
for i, value := range ids {

View File

@@ -613,6 +613,41 @@ service AdminService {
};
}
// Sets the state of the organisation and all its resource (Users, Projects, Grants to and from the org) to removed
// Users of this organisation will not be able login
rpc RemoveOrg(RemoveOrgRequest) returns (RemoveOrgResponse) {
option (google.api.http) = {
delete: "/orgs/{org_id}"
};
option (zitadel.v1.auth_option) = {
permission: "iam.write";
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "orgs";
tags: "global";
responses: {
key: "200";
value: {
description: "org removed successfully";
};
};
responses: {
key: "400";
value: {
description: "invalid org";
schema: {
json_schema: {
ref: "#/definitions/rpcStatus";
};
};
};
};
};
}
// Returns a identity provider configuration of the IAM instance
rpc GetIDPByID(GetIDPByIDRequest) returns (GetIDPByIDResponse) {
option (google.api.http) = {
@@ -3018,6 +3053,28 @@ message SetUpOrgResponse {
string user_id = 3;
}
message RemoveOrgRequest {
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = {
json_schema: {
required: ["org_id"]
};
};
string org_id = 1 [
(validate.rules).string = {min_len: 1, max_len: 200},
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
example: "\"69629023906488334\"";
min_length: 1;
max_length: 200;
}
];
}
message RemoveOrgResponse {
zitadel.v1.ObjectDetails details = 1;
}
message GetIDPByIDRequest {
string id = 1 [
(validate.rules).string = {min_len: 1, max_len: 200},

View File

@@ -80,6 +80,7 @@ message OrgQuery {
OrgNameQuery name_query = 1;
OrgDomainQuery domain_query = 2;
OrgStateQuery state_query = 3;
}
}
@@ -113,6 +114,15 @@ message OrgDomainQuery {
];
}
message OrgStateQuery {
OrgState state = 1 [
(validate.rules).enum.defined_only = true,
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
description: "current state of the organisation";
}
];
}
enum OrgFieldName {
ORG_FIELD_NAME_UNSPECIFIED = 0;
ORG_FIELD_NAME_NAME = 1;