Пример #1
0
func (c *AclCtrl) RelatedOne(w http.ResponseWriter, r *http.Request, params map[string]string) {
	pk, err := strconv.Atoi(params["pk"])
	if err != nil {
		c.render.JSONError(w, http.StatusBadRequest, apierrors.InvalidPathParams, err)
		return
	}

	params["id"] = params["fk"]

	related := params["related"]
	key := usecases.NewDirectoryKey(related)

	var handler usecases.HandlerFunc

	switch r.Method {
	case "GET":
		handler = c.routeDir.Get(key.For("FindByID")).EffectiveHandler
	case "DELETE":
		handler = c.routeDir.Get(key.For("DeleteByID")).EffectiveHandler
	}

	if handler == nil {
		c.render.JSON(w, http.StatusNotFound, nil)
		return
	}

	context.Set(r, "lastRessource", &interfaces.Ressource{Name: related, IDKey: "aclID", ID: pk})

	handler(w, r, params)
}
Пример #2
0
func setAccountRoutes(routeDir *usecases.RouteDirectory, controller *AccountCtrl) {
	key := usecases.NewDirectoryKey("accounts")

	routeDir.Add(key.For("Signin"), &usecases.Route{Method: "POST", Path: "/accounts/signin", Handler: controller.Signin, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("Signout"), &usecases.Route{Method: "POST", Path: "/accounts/signout", Handler: controller.Signout, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("Signup"), &usecases.Route{Method: "POST", Path: "/accounts/signup", Handler: controller.Signup, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("Current"), &usecases.Route{Method: "GET", Path: "/accounts/me", Handler: controller.Current, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("DeleteCurrent"), &usecases.Route{Method: "DELETE", Path: "/accounts/me", Handler: controller.DeleteCurrent, Visible: true, CheckPermissions: true})

	routeDir.Add(key.For("Create"), &usecases.Route{Method: "POST", Path: "/accounts", Handler: controller.Create, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("Find"), &usecases.Route{Method: "GET", Path: "/accounts", Handler: controller.Find, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("FindByID"), &usecases.Route{Method: "GET", Path: "/accounts/:id", Handler: controller.FindByID, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("Upsert"), &usecases.Route{Method: "PUT", Path: "/accounts", Handler: controller.Upsert, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("UpdateByID"), &usecases.Route{Method: "PUT", Path: "/accounts/:id", Handler: controller.UpdateByID, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("DeleteAll"), &usecases.Route{Method: "DELETE", Path: "/accounts", Handler: controller.DeleteAll, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("DeleteByID"), &usecases.Route{Method: "DELETE", Path: "/accounts/:id", Handler: controller.DeleteByID, Visible: true, CheckPermissions: true})

	routeDir.Add(key.For("UpdatePasswordRelated"), &usecases.Route{Method: "POST", Path: "/accounts/:pk/users/:fk/updatePassword", Handler: controller.UpdatePasswordRelated, Visible: true, CheckPermissions: false})

	routeDir.Add(key.For("CreateRelated"), &usecases.Route{Method: "POST", Path: "/accounts/:pk/:related", Handler: controller.CreateRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("FindRelated"), &usecases.Route{Method: "GET", Path: "/accounts/:pk/:related", Handler: controller.FindRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("FindByIDRelated"), &usecases.Route{Method: "GET", Path: "/accounts/:pk/:related/:fk", Handler: controller.FindByIDRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("UpsertRelated"), &usecases.Route{Method: "PUT", Path: "/accounts/:pk/:related", Handler: controller.UpsertRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("UpdateByIDRelated"), &usecases.Route{Method: "PUT", Path: "/accounts/:pk/:related/:fk", Handler: controller.UpdateByIDRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("DeleteAllRelated"), &usecases.Route{Method: "DELETE", Path: "/accounts/:pk/:related", Handler: controller.DeleteAllRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("DeleteByIDRelated"), &usecases.Route{Method: "DELETE", Path: "/accounts/:pk/:related/:fk", Handler: controller.DeleteByIDRelated, Visible: true, CheckPermissions: false})
}
Пример #3
0
func (c *AccountCtrl) RelatedOne(w http.ResponseWriter, r *http.Request, params map[string]string) {
	var (
		pk  int
		err error
	)

	if params["pk"] == "me" {
		sessionCtx := context.Get(r, "currentSession")
		if sessionCtx == nil {
			c.render.JSONError(w, http.StatusUnauthorized, apierrors.SessionNotFound, nil)
			return
		}

		pk = sessionCtx.(domain.Session).AccountID
	} else {
		pk, err = strconv.Atoi(params["pk"])
		if err != nil {
			c.render.JSONError(w, http.StatusBadRequest, apierrors.InvalidPathParams, err)
			return
		}
	}

	params["id"] = params["fk"]

	related := params["related"]
	key := usecases.NewDirectoryKey(related)

	var handler usecases.HandlerFunc

	switch r.Method {
	case "GET":
		handler = c.routeDir.Get(key.For("FindByID")).EffectiveHandler
	case "DELETE":
		handler = c.routeDir.Get(key.For("DeleteByID")).EffectiveHandler
	case "PUT":
		handler = c.routeDir.Get(key.For("UpdateByID")).EffectiveHandler
	}

	if handler == nil {
		c.render.JSON(w, http.StatusNotFound, nil)
		return
	}

	context.Set(r, "lastRessource", &interfaces.Ressource{Name: related, IDKey: "accountID", ID: pk})

	handler(w, r, params)
}
Пример #4
0
func setAclRoutes(routeDir *usecases.RouteDirectory, controller *AclCtrl) {
	key := usecases.NewDirectoryKey("acls")

	routeDir.Add(key.For("Create"), &usecases.Route{Method: "POST", Path: "/acls", Handler: controller.Create, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("Find"), &usecases.Route{Method: "GET", Path: "/acls", Handler: controller.Find, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("FindByID"), &usecases.Route{Method: "GET", Path: "/acls/:id", Handler: controller.FindByID, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("Upsert"), &usecases.Route{Method: "PUT", Path: "/acls", Handler: controller.Upsert, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("UpdateByID"), &usecases.Route{Method: "PUT", Path: "/acls/:id", Handler: controller.UpdateByID, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("DeleteAll"), &usecases.Route{Method: "DELETE", Path: "/acls", Handler: controller.DeleteAll, Visible: true, CheckPermissions: true})
	routeDir.Add(key.For("DeleteByID"), &usecases.Route{Method: "DELETE", Path: "/acls/:id", Handler: controller.DeleteByID, Visible: true, CheckPermissions: true})

	routeDir.Add(key.For("CreateRelated"), &usecases.Route{Method: "POST", Path: "/acls/:pk/:related", Handler: controller.CreateRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("FindRelated"), &usecases.Route{Method: "GET", Path: "/acls/:pk/:related", Handler: controller.FindRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("FindByIDRelated"), &usecases.Route{Method: "GET", Path: "/acls/:pk/:related/:fk", Handler: controller.FindByIDRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("UpsertRelated"), &usecases.Route{Method: "PUT", Path: "/acls/:pk/:related", Handler: controller.UpsertRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("UpdateByIDRelated"), &usecases.Route{Method: "PUT", Path: "/acls/:pk/:related/:fk", Handler: controller.UpdateByIDRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("DeleteAllRelated"), &usecases.Route{Method: "DELETE", Path: "/acls/:pk/:related", Handler: controller.DeleteAllRelated, Visible: true, CheckPermissions: false})
	routeDir.Add(key.For("DeleteByIDRelated"), &usecases.Route{Method: "DELETE", Path: "/acls/:pk/:related/:fk", Handler: controller.DeleteByIDRelated, Visible: true, CheckPermissions: false})
}
Пример #5
0
// @Title UpdatePasswordRelated
// @Description Update the related user password
// @Accept  json
// @Param   pk path int true "Account id"
// @Param   fk path int true "User id"
// @Param   PasswordForm body PasswordForm true "The old and the new password"
// @Success 200 {object} domain.User "Request was successful"
// @Router /accounts/{pk}/users/{fk}/updatePassword [post]
func (c *AccountCtrl) UpdatePasswordRelated(w http.ResponseWriter, r *http.Request, params map[string]string) {
	var (
		pk  int
		err error
	)

	if params["pk"] == "me" {
		sessionCtx := context.Get(r, "currentSession")
		if sessionCtx == nil {
			c.render.JSONError(w, http.StatusUnauthorized, apierrors.SessionNotFound, nil)
			return
		}

		pk = sessionCtx.(domain.Session).AccountID
	} else {
		pk, err = strconv.Atoi(params["pk"])
		if err != nil {
			c.render.JSONError(w, http.StatusBadRequest, apierrors.InvalidPathParams, err)
			return
		}
	}

	params["id"] = params["fk"]

	key := usecases.NewDirectoryKey("users")
	handler := c.routeDir.Get(key.For("UpdatePassword")).EffectiveHandler

	if handler == nil {
		c.render.JSON(w, http.StatusNotFound, nil)
		return
	}

	context.Set(r, "lastResource", &interfaces.Resource{Name: "users", IDKey: "accountID", ID: pk})

	handler(w, r, params)
}
Пример #6
0
func (s *Swagger) AddRoutes(routeDir *usecases.RouteDirectory) {
	dirKey := usecases.NewDirectoryKey("swagger")

	routeDir.Add(dirKey.For("UI"), &usecases.Route{Method: "GET", Path: "/explorer", Handler: s.UIHandler, Visible: true, CheckPermissions: false})
	routeDir.Add(dirKey.For("Resources"), &usecases.Route{Method: "GET", Path: "/explorer/*path", Handler: s.ResourcesHandler, Visible: true, CheckPermissions: false})
}