Esempio n. 1
0
func (api *Api) serviceUpdate(rw http.ResponseWriter, r *http.Request, user *account.User) {
	service, err := account.FindServiceBySubdomain(mux.Vars(r)["subdomain"])
	if err != nil {
		handleError(rw, err)
		return
	}

	_, err = findTeamAndCheckUser(service.Team, user)
	if err != nil {
		handleError(rw, err)
		return
	}

	if err := json.NewDecoder(r.Body).Decode(&service); err != nil {
		handleError(rw, errors.ErrBadRequest)
		return
	}
	// It is not allowed to change the subdomain yet.
	service.Subdomain = mux.Vars(r)["subdomain"]

	err = service.Update()
	if err != nil {
		handleError(rw, err)
		return
	}

	go api.EventNotifier(newServiceEvent("service.update", *service))
	Ok(rw, service)
}
Esempio n. 2
0
func (api *Api) pluginUnsubsribe(rw http.ResponseWriter, r *http.Request, user *account.User) {
	service, err := account.FindServiceBySubdomain(mux.Vars(r)["subdomain"])
	if err != nil {
		handleError(rw, err)
		return
	}

	_, err = findTeamAndCheckUser(service.Team, user)
	if err != nil {
		handleError(rw, err)
		return
	}

	plugin, err := account.FindPluginByNameAndService(mux.Vars(r)["plugin_name"], *service)
	if err != nil {
		handleError(rw, err)
		return
	}

	if err = plugin.Delete(); err != nil {
		handleError(rw, err)
		return
	}

	Ok(rw, plugin)
}
Esempio n. 3
0
func (api *Api) pluginSubsribe(rw http.ResponseWriter, r *http.Request, user *account.User) {
	service, err := account.FindServiceBySubdomain(mux.Vars(r)["subdomain"])
	if err != nil {
		handleError(rw, err)
		return
	}

	_, err = findTeamAndCheckUser(service.Team, user)
	if err != nil {
		handleError(rw, err)
		return
	}

	plugin := account.Plugin{}
	if err := json.NewDecoder(r.Body).Decode(&plugin); err != nil {
		handleError(rw, errors.ErrBadRequest)
		return
	}

	err = plugin.Save(*service)
	if err != nil {
		handleError(rw, err)
		return
	}

	Ok(rw, plugin)
}
Esempio n. 4
0
func (s *S) TestFindServiceBySubdomain(c *C) {
	err := service.Create(owner, team)

	t, err := account.FindServiceBySubdomain(service.Subdomain)
	c.Check(t, Not(IsNil))
	c.Check(err, IsNil)
	defer service.Delete(owner)
}
Esempio n. 5
0
func (api *Api) serviceInfo(rw http.ResponseWriter, r *http.Request, user *account.User) {
	service, err := account.FindServiceBySubdomain(mux.Vars(r)["subdomain"])
	if err != nil {
		handleError(rw, err)
		return
	}

	_, err = findTeamAndCheckUser(service.Team, user)
	if err != nil {
		handleError(rw, err)
		return
	}

	Ok(rw, service)
}
Esempio n. 6
0
func (api *Api) serviceDelete(rw http.ResponseWriter, r *http.Request, user *account.User) {
	service, err := account.FindServiceBySubdomain(mux.Vars(r)["subdomain"])
	if err != nil {
		handleError(rw, err)
		return
	}

	if err = service.Delete(*user); err != nil {
		handleError(rw, err)
		return
	}

	go api.EventNotifier(newServiceEvent("service.delete", *service))
	Ok(rw, service)
}
Esempio n. 7
0
func (s *S) TestFindServiceBySubdomainNotFound(c *C) {
	t, err := account.FindServiceBySubdomain("not-found")
	c.Check(t, IsNil)
	_, ok := err.(errors.NotFoundError)
	c.Assert(ok, Equals, true)
}