func grantAppAccess(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	appName := r.URL.Query().Get(":app")
	teamName := r.URL.Query().Get(":team")
	a, err := getAppFromContext(appName, r)
	if err != nil {
		return err
	}
	allowed := permission.Check(t, permission.PermAppUpdateGrant,
		contextsForApp(&a)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     appTarget(appName),
		Kind:       permission.PermAppUpdateGrant,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermAppReadEvents, contextsForApp(&a)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	team, err := servicemanager.Team.FindByName(teamName)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: "Team not found"}
	}
	err = a.Grant(team)
	if err == app.ErrAlreadyHaveAccess {
		return &errors.HTTP{Code: http.StatusConflict, Message: err.Error()}
	}
	return err
}
func grantAppAccess(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	appName := r.URL.Query().Get(":app")
	teamName := r.URL.Query().Get(":team")
	a, err := getAppFromContext(appName, r)
	if err != nil {
		return err
	}
	allowed := permission.Check(t, permission.PermAppUpdateGrant,
		contextsForApp(&a)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     appTarget(appName),
		Kind:       permission.PermAppUpdateGrant,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermAppReadEvents, contextsForApp(&a)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	team, err := servicemanager.Team.FindByName(teamName)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: "Team not found"}
	}
	err = a.Grant(team)
	if err == app.ErrAlreadyHaveAccess {
		return &errors.HTTP{Code: http.StatusConflict, Message: err.Error()}
	}
	return err
}
func grantAppAccess ( w http . ResponseWriter , r * http . Request , t auth . Token ) ( err error ) { appName := r . URL . Query ( ) . Get ( " " ) teamName := r . URL . Query ( ) . Get ( " " ) a , err := getAppFromContext ( appName , r ) if err != nil { return err } allowed := permission . Check ( t , permission . PermAppUpdateGrant , contextsForApp ( & a ) ... , ) if ! allowed { return permission . ErrUnauthorized } evt , err := event . New ( & event . Opts { Target : appTarget ( appName ) , Kind : permission . PermAppUpdateGrant , Owner : t , CustomData : event . FormToCustomData ( InputFields ( r ) ) , Allowed : event . Allowed ( permission . PermAppReadEvents , contextsForApp ( & a ) ... ) , } ) if err != nil { return err } defer func ( ) { evt . Done ( err ) } ( ) team , err := servicemanager . Team . FindByName ( teamName ) if err != nil { return & errors . HTTP { Code : http . StatusNotFound , Message : " " } } err = a . Grant ( team ) if err == app . ErrAlreadyHaveAccess { return & errors . HTTP { Code : http . StatusConflict , Message : err . Error ( ) } } return err }
// title: grant access to app
// path: /apps/{app}/teams/{team}
// method: PUT
// responses:
//   200: Access granted
//   401: Unauthorized
//   404: App or team not found
//   409: Grant already exists
title : grant access to app path : / apps / { app } / teams / { team } method : PUT responses : 200 : Access granted 401 : Unauthorized 404 : App or team not found 409 : Grant already exists