func removeUser(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	email := r.URL.Query().Get("user")
	if email == "" {
		email = t.GetUserName()
	}
	allowed := permission.Check(t, permission.PermUserDelete,
		permission.Context(permTypes.CtxUser, email),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     userTarget(email),
		Kind:       permission.PermUserDelete,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermUserReadEvents, permission.Context(permTypes.CtxUser, email)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	u, err := auth.GetUserByEmail(email)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	appNames, err := deployableApps(u, make(map[string]*permission.Role))
	if err != nil {
		return err
	}
	manager := repository.Manager()
	for _, name := range appNames {
		manager.RevokeAccess(name, u.Email)
	}
	if err := manager.RemoveUser(u.Email); err != nil {
		log.Errorf("Failed to remove user from repository manager: %s", err)
	}
	return app.AuthScheme.Remove(u)
}
func removeUser(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	email := r.URL.Query().Get("user")
	if email == "" {
		email = t.GetUserName()
	}
	allowed := permission.Check(t, permission.PermUserDelete,
		permission.Context(permTypes.CtxUser, email),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     userTarget(email),
		Kind:       permission.PermUserDelete,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermUserReadEvents, permission.Context(permTypes.CtxUser, email)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	u, err := auth.GetUserByEmail(email)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	appNames, err := deployableApps(u, make(map[string]*permission.Role))
	if err != nil {
		return err
	}
	manager := repository.Manager()
	for _, name := range appNames {
		manager.RevokeAccess(name, u.Email)
	}
	if err := manager.RemoveUser(u.Email); err != nil {
		log.Errorf("Failed to remove user from repository manager: %s", err)
	}
	return app.AuthScheme.Remove(u)
}
func removeUser ( w http . ResponseWriter , r * http . Request , t auth . Token ) ( err error ) { email := r . URL . Query ( ) . Get ( " " ) if email == " " { email = t . GetUserName ( ) } allowed := permission . Check ( t , permission . PermUserDelete , permission . Context ( permTypes . CtxUser , email ) , ) if ! allowed { return permission . ErrUnauthorized } evt , err := event . New ( & event . Opts { Target : userTarget ( email ) , Kind : permission . PermUserDelete , Owner : t , CustomData : event . FormToCustomData ( InputFields ( r ) ) , Allowed : event . Allowed ( permission . PermUserReadEvents , permission . Context ( permTypes . CtxUser , email ) ) , } ) if err != nil { return err } defer func ( ) { evt . Done ( err ) } ( ) u , err := auth . GetUserByEmail ( email ) if err != nil { return & errors . HTTP { Code : http . StatusNotFound , Message : err . Error ( ) } } appNames , err := deployableApps ( u , make ( map [ string ] * permission . Role ) ) if err != nil { return err } manager := repository . Manager ( ) for _ , name := range appNames { manager . RevokeAccess ( name , u . Email ) } if err := manager . RemoveUser ( u . Email ) ; err != nil { log . Errorf ( " " , err ) } return app . AuthScheme . Remove ( u ) }
// title: remove user
// path: /users
// method: DELETE
// responses:
//   200: User removed
//   401: Unauthorized
//   404: Not found
title : remove user path : / users method : DELETE responses : 200 : User removed 401 : Unauthorized 404 : Not found