mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01:00
add organization member handler (#537)
This commit is contained in:
parent
6fb69c59d2
commit
37e945d603
47
controller/addOrganizationMember.go
Normal file
47
controller/addOrganizationMember.go
Normal 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()
|
||||||
|
}
|
@ -51,6 +51,7 @@ func Run(inCfg *config.Config) error {
|
|||||||
api.AccountResetPasswordHandler = newResetPasswordHandler(cfg)
|
api.AccountResetPasswordHandler = newResetPasswordHandler(cfg)
|
||||||
api.AccountResetPasswordRequestHandler = newResetPasswordRequestHandler()
|
api.AccountResetPasswordRequestHandler = newResetPasswordRequestHandler()
|
||||||
api.AccountVerifyHandler = newVerifyHandler()
|
api.AccountVerifyHandler = newVerifyHandler()
|
||||||
|
api.AdminAddOrganizationMemberHandler = newAddOrganizationMemberHandler()
|
||||||
api.AdminCreateAccountHandler = newCreateAccountHandler()
|
api.AdminCreateAccountHandler = newCreateAccountHandler()
|
||||||
api.AdminCreateFrontendHandler = newCreateFrontendHandler()
|
api.AdminCreateFrontendHandler = newCreateFrontendHandler()
|
||||||
api.AdminCreateIdentityHandler = newCreateIdentityHandler()
|
api.AdminCreateIdentityHandler = newCreateIdentityHandler()
|
||||||
|
@ -34,6 +34,12 @@ func (o *AddOrganizationMemberReader) ReadResponse(response runtime.ClientRespon
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, result
|
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:
|
case 500:
|
||||||
result := NewAddOrganizationMemberInternalServerError()
|
result := NewAddOrganizationMemberInternalServerError()
|
||||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||||
@ -157,6 +163,62 @@ func (o *AddOrganizationMemberUnauthorized) readResponse(response runtime.Client
|
|||||||
return nil
|
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
|
// NewAddOrganizationMemberInternalServerError creates a AddOrganizationMemberInternalServerError with default headers values
|
||||||
func NewAddOrganizationMemberInternalServerError() *AddOrganizationMemberInternalServerError {
|
func NewAddOrganizationMemberInternalServerError() *AddOrganizationMemberInternalServerError {
|
||||||
return &AddOrganizationMemberInternalServerError{}
|
return &AddOrganizationMemberInternalServerError{}
|
||||||
@ -221,6 +283,9 @@ type AddOrganizationMemberBody struct {
|
|||||||
|
|
||||||
// email
|
// email
|
||||||
Email string `json:"email,omitempty"`
|
Email string `json:"email,omitempty"`
|
||||||
|
|
||||||
|
// token
|
||||||
|
Token string `json:"token,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates this add organization member body
|
// Validate validates this add organization member body
|
||||||
|
@ -932,6 +932,9 @@ func init() {
|
|||||||
"properties": {
|
"properties": {
|
||||||
"email": {
|
"email": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"token": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -944,6 +947,9 @@ func init() {
|
|||||||
"401": {
|
"401": {
|
||||||
"description": "unauthorized"
|
"description": "unauthorized"
|
||||||
},
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "not found"
|
||||||
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "internal server error"
|
"description": "internal server error"
|
||||||
}
|
}
|
||||||
@ -2992,6 +2998,9 @@ func init() {
|
|||||||
"properties": {
|
"properties": {
|
||||||
"email": {
|
"email": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"token": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3004,6 +3013,9 @@ func init() {
|
|||||||
"401": {
|
"401": {
|
||||||
"description": "unauthorized"
|
"description": "unauthorized"
|
||||||
},
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "not found"
|
||||||
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "internal server error"
|
"description": "internal server error"
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,9 @@ type AddOrganizationMemberBody struct {
|
|||||||
|
|
||||||
// email
|
// email
|
||||||
Email string `json:"email,omitempty"`
|
Email string `json:"email,omitempty"`
|
||||||
|
|
||||||
|
// token
|
||||||
|
Token string `json:"token,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates this add organization member body
|
// Validate validates this add organization member body
|
||||||
|
@ -61,6 +61,31 @@ func (o *AddOrganizationMemberUnauthorized) WriteResponse(rw http.ResponseWriter
|
|||||||
rw.WriteHeader(401)
|
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
|
// AddOrganizationMemberInternalServerErrorCode is the HTTP code returned for type AddOrganizationMemberInternalServerError
|
||||||
const AddOrganizationMemberInternalServerErrorCode int = 500
|
const AddOrganizationMemberInternalServerErrorCode int = 500
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ api/metadataApi.ts
|
|||||||
api/shareApi.ts
|
api/shareApi.ts
|
||||||
model/accessRequest.ts
|
model/accessRequest.ts
|
||||||
model/accessResponse.ts
|
model/accessResponse.ts
|
||||||
|
model/addOrganizationMemberRequest.ts
|
||||||
model/authUser.ts
|
model/authUser.ts
|
||||||
model/changePasswordRequest.ts
|
model/changePasswordRequest.ts
|
||||||
model/configuration.ts
|
model/configuration.ts
|
||||||
|
@ -15,6 +15,7 @@ import localVarRequest from 'request';
|
|||||||
import http from 'http';
|
import http from 'http';
|
||||||
|
|
||||||
/* tslint:disable:no-unused-locals */
|
/* tslint:disable:no-unused-locals */
|
||||||
|
import { AddOrganizationMemberRequest } from '../model/addOrganizationMemberRequest';
|
||||||
import { CreateAccountRequest } from '../model/createAccountRequest';
|
import { CreateAccountRequest } from '../model/createAccountRequest';
|
||||||
import { CreateFrontendRequest } from '../model/createFrontendRequest';
|
import { CreateFrontendRequest } from '../model/createFrontendRequest';
|
||||||
import { CreateFrontendResponse } from '../model/createFrontendResponse';
|
import { CreateFrontendResponse } from '../model/createFrontendResponse';
|
||||||
@ -105,7 +106,7 @@ export class AdminApi {
|
|||||||
*
|
*
|
||||||
* @param body
|
* @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';
|
const localVarPath = this.basePath + '/organization/add';
|
||||||
let localVarQueryParameters: any = {};
|
let localVarQueryParameters: any = {};
|
||||||
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
|
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
|
||||||
@ -122,7 +123,7 @@ export class AdminApi {
|
|||||||
uri: localVarPath,
|
uri: localVarPath,
|
||||||
useQuerystring: this._useQuerystring,
|
useQuerystring: this._useQuerystring,
|
||||||
json: true,
|
json: true,
|
||||||
body: ObjectSerializer.serialize(body, "GrantsRequest")
|
body: ObjectSerializer.serialize(body, "AddOrganizationMemberRequest")
|
||||||
};
|
};
|
||||||
|
|
||||||
let authenticationPromise = Promise.resolve();
|
let authenticationPromise = Promise.resolve();
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ import localVarRequest from 'request';
|
|||||||
|
|
||||||
export * from './accessRequest';
|
export * from './accessRequest';
|
||||||
export * from './accessResponse';
|
export * from './accessResponse';
|
||||||
|
export * from './addOrganizationMemberRequest';
|
||||||
export * from './authUser';
|
export * from './authUser';
|
||||||
export * from './changePasswordRequest';
|
export * from './changePasswordRequest';
|
||||||
export * from './configuration';
|
export * from './configuration';
|
||||||
@ -60,6 +61,7 @@ export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;
|
|||||||
|
|
||||||
import { AccessRequest } from './accessRequest';
|
import { AccessRequest } from './accessRequest';
|
||||||
import { AccessResponse } from './accessResponse';
|
import { AccessResponse } from './accessResponse';
|
||||||
|
import { AddOrganizationMemberRequest } from './addOrganizationMemberRequest';
|
||||||
import { AuthUser } from './authUser';
|
import { AuthUser } from './authUser';
|
||||||
import { ChangePasswordRequest } from './changePasswordRequest';
|
import { ChangePasswordRequest } from './changePasswordRequest';
|
||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
@ -126,6 +128,7 @@ let enumsMap: {[index: string]: any} = {
|
|||||||
let typeMap: {[index: string]: any} = {
|
let typeMap: {[index: string]: any} = {
|
||||||
"AccessRequest": AccessRequest,
|
"AccessRequest": AccessRequest,
|
||||||
"AccessResponse": AccessResponse,
|
"AccessResponse": AccessResponse,
|
||||||
|
"AddOrganizationMemberRequest": AddOrganizationMemberRequest,
|
||||||
"AuthUser": AuthUser,
|
"AuthUser": AuthUser,
|
||||||
"ChangePasswordRequest": ChangePasswordRequest,
|
"ChangePasswordRequest": ChangePasswordRequest,
|
||||||
"Configuration": Configuration,
|
"Configuration": Configuration,
|
||||||
|
@ -28,20 +28,46 @@ class OrganizationAddBody(object):
|
|||||||
and the value is json key in definition.
|
and the value is json key in definition.
|
||||||
"""
|
"""
|
||||||
swagger_types = {
|
swagger_types = {
|
||||||
|
'token': 'str',
|
||||||
'email': 'str'
|
'email': 'str'
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute_map = {
|
attribute_map = {
|
||||||
|
'token': 'token',
|
||||||
'email': 'email'
|
'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
|
"""OrganizationAddBody - a model defined in Swagger""" # noqa: E501
|
||||||
|
self._token = None
|
||||||
self._email = None
|
self._email = None
|
||||||
self.discriminator = None
|
self.discriminator = None
|
||||||
|
if token is not None:
|
||||||
|
self.token = token
|
||||||
if email is not None:
|
if email is not None:
|
||||||
self.email = email
|
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
|
@property
|
||||||
def email(self):
|
def email(self):
|
||||||
"""Gets the email of this OrganizationAddBody. # noqa: E501
|
"""Gets the email of this OrganizationAddBody. # noqa: E501
|
||||||
|
@ -442,6 +442,8 @@ paths:
|
|||||||
in: body
|
in: body
|
||||||
schema:
|
schema:
|
||||||
properties:
|
properties:
|
||||||
|
token:
|
||||||
|
type: string
|
||||||
email:
|
email:
|
||||||
type: string
|
type: string
|
||||||
responses:
|
responses:
|
||||||
@ -449,6 +451,8 @@ paths:
|
|||||||
description: member added
|
description: member added
|
||||||
401:
|
401:
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
|
404:
|
||||||
|
description: not found
|
||||||
500:
|
500:
|
||||||
description: internal server error
|
description: internal server error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user