func grantAccessToTeam(appName, teamName string, u *auth.User) error { t := new(auth.Team) app, err := getApp(appName, u) if err != nil { return err } conn, err := db.Conn() if err != nil { return err } defer conn.Close() err = conn.Teams().Find(bson.M{"_id": teamName}).One(t) if err != nil { return &errors.Http{Code: http.StatusNotFound, Message: "Team not found"} } err = app.Grant(t) if err != nil { return &errors.Http{Code: http.StatusConflict, Message: err.Error()} } err = conn.Apps().Update(bson.M{"name": app.Name}, app) if err != nil { return err } gUrl := repository.GitServerUri() gClient := gandalf.Client{Endpoint: gUrl} if err := gClient.GrantAccess([]string{app.Name}, t.Users); err != nil { return fmt.Errorf("Failed to grant access in the git server: %s.", err) } return nil }
func grantAccessToTeam(appName, teamName string, u *auth.User) error { t := new(auth.Team) app, err := getAppOrError(appName, u) if err != nil { return err } err = db.Session.Teams().Find(bson.M{"_id": teamName}).One(t) if err != nil { return &errors.Http{Code: http.StatusNotFound, Message: "Team not found"} } err = app.Grant(t) if err != nil { return &errors.Http{Code: http.StatusConflict, Message: err.Error()} } err = db.Session.Apps().Update(bson.M{"name": app.Name}, app) if err != nil { return err } gUrl := repository.GitServerUri() return (&gandalf.Client{Endpoint: gUrl}).GrantAccess([]string{app.Name}, t.Users) }
func grantAppAccess(w http.ResponseWriter, r *http.Request, t *auth.Token) error { u, err := t.User() if err != nil { return err } appName := r.URL.Query().Get(":app") teamName := r.URL.Query().Get(":team") rec.Log(u.Email, "grant-app-access", "app="+appName, "team="+teamName) team := new(auth.Team) app, err := getApp(appName, u) if err != nil { return err } conn, err := db.Conn() if err != nil { return err } defer conn.Close() err = conn.Teams().Find(bson.M{"_id": teamName}).One(team) if err != nil { return &errors.HTTP{Code: http.StatusNotFound, Message: "Team not found"} } err = app.Grant(team) if err != nil { return &errors.HTTP{Code: http.StatusConflict, Message: err.Error()} } err = conn.Apps().Update(bson.M{"name": app.Name}, app) if err != nil { return err } gURL := repository.ServerURL() gClient := gandalf.Client{Endpoint: gURL} if err := gClient.GrantAccess([]string{app.Name}, team.Users); err != nil { return fmt.Errorf("Failed to grant access in the git server: %s.", err) } return nil }