remove organization member handler (#537)

This commit is contained in:
Michael Quigley 2024-12-09 14:38:30 -05:00
parent 37e945d603
commit 0e30407bbd
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
11 changed files with 200 additions and 7 deletions

View File

@ -39,7 +39,12 @@ func (h *addOrganizationMemberHandler) Handle(params admin.AddOrganizationMember
}
if err := str.AddAccountToOrganization(acct.Id, org.Id, trx); err != nil {
logrus.Errorf("error adding account '%v' to organization '%v': %v", acct.Id, org.Id, err)
logrus.Errorf("error adding account '%v' to organization '%v': %v", acct.Email, org.Token, err)
return admin.NewAddOrganizationMemberInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
return admin.NewAddOrganizationMemberInternalServerError()
}

View File

@ -62,6 +62,7 @@ func Run(inCfg *config.Config) error {
api.AdminInviteTokenGenerateHandler = newInviteTokenGenerateHandler()
api.AdminListFrontendsHandler = newListFrontendsHandler()
api.AdminListOrganizationMembersHandler = newListOrganizationMembersHandler()
api.AdminRemoveOrganizationMemberHandler = newRemoveOrganizationMemberHandler()
api.AdminUpdateFrontendHandler = newUpdateFrontendHandler()
api.EnvironmentEnableHandler = newEnableHandler()
api.EnvironmentDisableHandler = newDisableHandler()

View File

@ -0,0 +1,52 @@
package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type removeOrganizationMemberHandler struct{}
func newRemoveOrganizationMemberHandler() *removeOrganizationMemberHandler {
return &removeOrganizationMemberHandler{}
}
func (h *removeOrganizationMemberHandler) Handle(params admin.RemoveOrganizationMemberParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Error("invalid admin principal")
return admin.NewRemoveOrganizationMemberUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
return admin.NewRemoveOrganizationMemberInternalServerError()
}
defer func() { _ = trx.Rollback() }()
acct, err := str.FindAccountWithEmail(params.Body.Email, trx)
if err != nil {
logrus.Errorf("error finding account with email address '%v': %v", params.Body.Email, err)
return admin.NewAddOrganizationMemberNotFound()
}
org, err := str.FindOrganizationByToken(params.Body.Token, trx)
if err != nil {
logrus.Errorf("error finding organization '%v': %v", params.Body.Token, err)
return admin.NewAddOrganizationMemberNotFound()
}
if err := str.RemoveAccountFromOrganization(acct.Id, org.Id, trx); err != nil {
logrus.Errorf("error removing account '%v' from organization '%v': %v", acct.Email, org.Token, err)
return admin.NewRemoveOrganizationMemberInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
return admin.NewRemoveOrganizationMemberInternalServerError()
}
return admin.NewRemoveOrganizationMemberOK()
}

View File

@ -34,6 +34,12 @@ func (o *RemoveOrganizationMemberReader) ReadResponse(response runtime.ClientRes
return nil, err
}
return nil, result
case 404:
result := NewRemoveOrganizationMemberNotFound()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
case 500:
result := NewRemoveOrganizationMemberInternalServerError()
if err := result.readResponse(response, consumer, o.formats); err != nil {
@ -157,6 +163,62 @@ func (o *RemoveOrganizationMemberUnauthorized) readResponse(response runtime.Cli
return nil
}
// NewRemoveOrganizationMemberNotFound creates a RemoveOrganizationMemberNotFound with default headers values
func NewRemoveOrganizationMemberNotFound() *RemoveOrganizationMemberNotFound {
return &RemoveOrganizationMemberNotFound{}
}
/*
RemoveOrganizationMemberNotFound describes a response with status code 404, with default header values.
not found
*/
type RemoveOrganizationMemberNotFound struct {
}
// IsSuccess returns true when this remove organization member not found response has a 2xx status code
func (o *RemoveOrganizationMemberNotFound) IsSuccess() bool {
return false
}
// IsRedirect returns true when this remove organization member not found response has a 3xx status code
func (o *RemoveOrganizationMemberNotFound) IsRedirect() bool {
return false
}
// IsClientError returns true when this remove organization member not found response has a 4xx status code
func (o *RemoveOrganizationMemberNotFound) IsClientError() bool {
return true
}
// IsServerError returns true when this remove organization member not found response has a 5xx status code
func (o *RemoveOrganizationMemberNotFound) IsServerError() bool {
return false
}
// IsCode returns true when this remove organization member not found response a status code equal to that given
func (o *RemoveOrganizationMemberNotFound) IsCode(code int) bool {
return code == 404
}
// Code gets the status code for the remove organization member not found response
func (o *RemoveOrganizationMemberNotFound) Code() int {
return 404
}
func (o *RemoveOrganizationMemberNotFound) Error() string {
return fmt.Sprintf("[POST /organization/remove][%d] removeOrganizationMemberNotFound ", 404)
}
func (o *RemoveOrganizationMemberNotFound) String() string {
return fmt.Sprintf("[POST /organization/remove][%d] removeOrganizationMemberNotFound ", 404)
}
func (o *RemoveOrganizationMemberNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
return nil
}
// NewRemoveOrganizationMemberInternalServerError creates a RemoveOrganizationMemberInternalServerError with default headers values
func NewRemoveOrganizationMemberInternalServerError() *RemoveOrganizationMemberInternalServerError {
return &RemoveOrganizationMemberInternalServerError{}
@ -221,6 +283,9 @@ type RemoveOrganizationMemberBody struct {
// email
Email string `json:"email,omitempty"`
// token
Token string `json:"token,omitempty"`
}
// Validate validates this remove organization member body

View File

@ -1029,6 +1029,9 @@ func init() {
"properties": {
"email": {
"type": "string"
},
"token": {
"type": "string"
}
}
}
@ -1041,6 +1044,9 @@ func init() {
"401": {
"description": "unauthorized"
},
"404": {
"description": "not found"
},
"500": {
"description": "internal server error"
}
@ -3091,6 +3097,9 @@ func init() {
"properties": {
"email": {
"type": "string"
},
"token": {
"type": "string"
}
}
}
@ -3103,6 +3112,9 @@ func init() {
"401": {
"description": "unauthorized"
},
"404": {
"description": "not found"
},
"500": {
"description": "internal server error"
}

View File

@ -80,6 +80,9 @@ type RemoveOrganizationMemberBody struct {
// email
Email string `json:"email,omitempty"`
// token
Token string `json:"token,omitempty"`
}
// Validate validates this remove organization member body

View File

@ -61,6 +61,31 @@ func (o *RemoveOrganizationMemberUnauthorized) WriteResponse(rw http.ResponseWri
rw.WriteHeader(401)
}
// RemoveOrganizationMemberNotFoundCode is the HTTP code returned for type RemoveOrganizationMemberNotFound
const RemoveOrganizationMemberNotFoundCode int = 404
/*
RemoveOrganizationMemberNotFound not found
swagger:response removeOrganizationMemberNotFound
*/
type RemoveOrganizationMemberNotFound struct {
}
// NewRemoveOrganizationMemberNotFound creates RemoveOrganizationMemberNotFound with default headers values
func NewRemoveOrganizationMemberNotFound() *RemoveOrganizationMemberNotFound {
return &RemoveOrganizationMemberNotFound{}
}
// WriteResponse to the client
func (o *RemoveOrganizationMemberNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(404)
}
// RemoveOrganizationMemberInternalServerErrorCode is the HTTP code returned for type RemoveOrganizationMemberInternalServerError
const RemoveOrganizationMemberInternalServerErrorCode int = 500

View File

@ -790,7 +790,7 @@ export class AdminApi {
*
* @param body
*/
public async removeOrganizationMember (body?: GrantsRequest, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body?: any; }> {
public async removeOrganizationMember (body?: AddOrganizationMemberRequest, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body?: any; }> {
const localVarPath = this.basePath + '/organization/remove';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
@ -807,7 +807,7 @@ export class AdminApi {
uri: localVarPath,
useQuerystring: this._useQuerystring,
json: true,
body: ObjectSerializer.serialize(body, "GrantsRequest")
body: ObjectSerializer.serialize(body, "AddOrganizationMemberRequest")
};
let authenticationPromise = Promise.resolve();

View File

@ -28,7 +28,7 @@ class InlineResponse2001(object):
and the value is json key in definition.
"""
swagger_types = {
'members': 'list[OrganizationRemoveBody]'
'members': 'list[GrantsBody]'
}
attribute_map = {
@ -48,7 +48,7 @@ class InlineResponse2001(object):
:return: The members of this InlineResponse2001. # noqa: E501
:rtype: list[OrganizationRemoveBody]
:rtype: list[GrantsBody]
"""
return self._members
@ -58,7 +58,7 @@ class InlineResponse2001(object):
:param members: The members of this InlineResponse2001. # noqa: E501
:type: list[OrganizationRemoveBody]
:type: list[GrantsBody]
"""
self._members = members

View File

@ -28,20 +28,46 @@ class OrganizationRemoveBody(object):
and the value is json key in definition.
"""
swagger_types = {
'token': 'str',
'email': 'str'
}
attribute_map = {
'token': 'token',
'email': 'email'
}
def __init__(self, email=None): # noqa: E501
def __init__(self, token=None, email=None): # noqa: E501
"""OrganizationRemoveBody - a model defined in Swagger""" # noqa: E501
self._token = None
self._email = None
self.discriminator = None
if token is not None:
self.token = token
if email is not None:
self.email = email
@property
def token(self):
"""Gets the token of this OrganizationRemoveBody. # noqa: E501
:return: The token of this OrganizationRemoveBody. # noqa: E501
:rtype: str
"""
return self._token
@token.setter
def token(self, token):
"""Sets the token of this OrganizationRemoveBody.
:param token: The token of this OrganizationRemoveBody. # noqa: E501
:type: str
"""
self._token = token
@property
def email(self):
"""Gets the email of this OrganizationRemoveBody. # noqa: E501

View File

@ -500,6 +500,8 @@ paths:
in: body
schema:
properties:
token:
type: string
email:
type: string
responses:
@ -507,6 +509,8 @@ paths:
description: member removed
401:
description: unauthorized
404:
description: not found
500:
description: internal server error