add organization member handler (#537)

This commit is contained in:
Michael Quigley 2024-12-09 14:32:43 -05:00
parent 6fb69c59d2
commit 37e945d603
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
12 changed files with 228 additions and 3 deletions

View File

@ -0,0 +1,47 @@
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 addOrganizationMemberHandler struct{}
func newAddOrganizationMemberHandler() *addOrganizationMemberHandler {
return &addOrganizationMemberHandler{}
}
func (h *addOrganizationMemberHandler) Handle(params admin.AddOrganizationMemberParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Error("invalid admin principal")
return admin.NewAddOrganizationMemberUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
return admin.NewAddOrganizationMemberInternalServerError()
}
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.AddAccountToOrganization(acct.Id, org.Id, trx); err != nil {
logrus.Errorf("error adding account '%v' to organization '%v': %v", acct.Id, org.Id, err)
return admin.NewAddOrganizationMemberInternalServerError()
}
return admin.NewAddOrganizationMemberCreated()
}

View File

@ -51,6 +51,7 @@ func Run(inCfg *config.Config) error {
api.AccountResetPasswordHandler = newResetPasswordHandler(cfg)
api.AccountResetPasswordRequestHandler = newResetPasswordRequestHandler()
api.AccountVerifyHandler = newVerifyHandler()
api.AdminAddOrganizationMemberHandler = newAddOrganizationMemberHandler()
api.AdminCreateAccountHandler = newCreateAccountHandler()
api.AdminCreateFrontendHandler = newCreateFrontendHandler()
api.AdminCreateIdentityHandler = newCreateIdentityHandler()

View File

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

View File

@ -932,6 +932,9 @@ func init() {
"properties": {
"email": {
"type": "string"
},
"token": {
"type": "string"
}
}
}
@ -944,6 +947,9 @@ func init() {
"401": {
"description": "unauthorized"
},
"404": {
"description": "not found"
},
"500": {
"description": "internal server error"
}
@ -2992,6 +2998,9 @@ func init() {
"properties": {
"email": {
"type": "string"
},
"token": {
"type": "string"
}
}
}
@ -3004,6 +3013,9 @@ func init() {
"401": {
"description": "unauthorized"
},
"404": {
"description": "not found"
},
"500": {
"description": "internal server error"
}

View File

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

View File

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

View File

@ -8,6 +8,7 @@ api/metadataApi.ts
api/shareApi.ts
model/accessRequest.ts
model/accessResponse.ts
model/addOrganizationMemberRequest.ts
model/authUser.ts
model/changePasswordRequest.ts
model/configuration.ts

View File

@ -15,6 +15,7 @@ import localVarRequest from 'request';
import http from 'http';
/* tslint:disable:no-unused-locals */
import { AddOrganizationMemberRequest } from '../model/addOrganizationMemberRequest';
import { CreateAccountRequest } from '../model/createAccountRequest';
import { CreateFrontendRequest } from '../model/createFrontendRequest';
import { CreateFrontendResponse } from '../model/createFrontendResponse';
@ -105,7 +106,7 @@ export class AdminApi {
*
* @param body
*/
public async addOrganizationMember (body?: GrantsRequest, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body?: any; }> {
public async addOrganizationMember (body?: AddOrganizationMemberRequest, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body?: any; }> {
const localVarPath = this.basePath + '/organization/add';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
@ -122,7 +123,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

@ -0,0 +1,37 @@
/**
* zrok
* zrok client access
*
* The version of the OpenAPI document: 0.3.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { RequestFile } from './models';
export class AddOrganizationMemberRequest {
'token'?: string;
'email'?: string;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "token",
"baseName": "token",
"type": "string"
},
{
"name": "email",
"baseName": "email",
"type": "string"
} ];
static getAttributeTypeMap() {
return AddOrganizationMemberRequest.attributeTypeMap;
}
}

View File

@ -2,6 +2,7 @@ import localVarRequest from 'request';
export * from './accessRequest';
export * from './accessResponse';
export * from './addOrganizationMemberRequest';
export * from './authUser';
export * from './changePasswordRequest';
export * from './configuration';
@ -60,6 +61,7 @@ export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
import { AccessRequest } from './accessRequest';
import { AccessResponse } from './accessResponse';
import { AddOrganizationMemberRequest } from './addOrganizationMemberRequest';
import { AuthUser } from './authUser';
import { ChangePasswordRequest } from './changePasswordRequest';
import { Configuration } from './configuration';
@ -126,6 +128,7 @@ let enumsMap: {[index: string]: any} = {
let typeMap: {[index: string]: any} = {
"AccessRequest": AccessRequest,
"AccessResponse": AccessResponse,
"AddOrganizationMemberRequest": AddOrganizationMemberRequest,
"AuthUser": AuthUser,
"ChangePasswordRequest": ChangePasswordRequest,
"Configuration": Configuration,

View File

@ -28,20 +28,46 @@ class OrganizationAddBody(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
"""OrganizationAddBody - 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 OrganizationAddBody. # noqa: E501
:return: The token of this OrganizationAddBody. # noqa: E501
:rtype: str
"""
return self._token
@token.setter
def token(self, token):
"""Sets the token of this OrganizationAddBody.
:param token: The token of this OrganizationAddBody. # noqa: E501
:type: str
"""
self._token = token
@property
def email(self):
"""Gets the email of this OrganizationAddBody. # noqa: E501

View File

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