Example #1
0
func (api *Api) hookSave(rw http.ResponseWriter, r *http.Request, user *account.User) {
	hook := account.Hook{}
	if err := json.NewDecoder(r.Body).Decode(&hook); err != nil {
		handleError(rw, errors.ErrBadRequest)
		return
	}

	team, err := findTeamAndCheckUser(hook.Team, user)
	if err != nil {
		handleError(rw, err)
		return
	}

	if err := hook.Save(*team); err != nil {
		handleError(rw, err)
		return
	}

	Ok(rw, hook)
}
Example #2
0
func (s *StorableSuite) TestFindHooksByEvent(c *C) {
	defer s.Storage.DeleteTeam(team)
	s.Storage.UpsertTeam(team)

	defer s.Storage.DeleteHook(hook)
	hook.Name = "service.create"
	hook.Events = []string{"service.create"}
	hook.Team = team.Alias
	s.Storage.UpsertHook(hook)

	whk := account.Hook{
		Name:   "service.update",
		Events: []string{"service.update"},
		Config: account.HookConfig{Address: "http://www.example.org"},
	}
	defer s.Storage.DeleteHook(whk)
	whk.Events = []string{"service.update"}
	whk.Team = team.Alias
	s.Storage.UpsertHook(whk)

	whs, err := s.Storage.FindHooksByEvent("service.create")
	c.Assert(whs, DeepEquals, []account.Hook{hook})
	c.Check(err, IsNil)
}