// Create creates a new user account. // // It requires to inform the fields: Name, Email and Password. // It is not allowed to create two users with the same email address. // It returns an error if the user creation fails. func (user *User) Create() error { if user.Name == "" || user.Email == "" || user.Password == "" { return errors.NewValidationError(errors.ErrUserMissingRequiredFields) } user.hashPassword() if user.Exists() { return errors.NewValidationError(errors.ErrUserDuplicateEntry) } return store.UpsertUser(*user) }
func (app *App) valid() error { if app.Name == "" { return errors.NewValidationError(errors.ErrAppMissingRequiredFields) } return nil }
func (app *App) Create(owner User, team Team) error { app.Owner = owner.Email app.Team = team.Alias if err := app.valid(); err != nil { Logger.Info("Failed to create an app with invalid data: %+v.", app) return err } if app.ClientId == "" { app.ClientId = goutils.GenerateSlug(app.Name) } else { app.ClientId = goutils.GenerateSlug(app.ClientId) } if app.ClientSecret == "" { app.ClientSecret = util.GenerateRandomStr(32) } if app.Exists() { Logger.Info("Failed to create an app with duplicate data: %+v.", app) return errors.NewValidationError(errors.ErrAppDuplicateEntry) } err := store.UpsertApp(*app) Logger.Info("app.Create: %+v. Err: %s.", app, err) return err }
func (pc *Plugin) valid() error { if pc.Name == "" || pc.Service == "" { return errors.NewValidationError(errors.ErrPluginMissingRequiredFields) } return nil }
// Remove a user from the team. // // Do nothing if the user is not in the team. // Return an error if trying to remove the owner. It's not allowed to do that. func (team *Team) RemoveUsers(emails []string) error { var ( errOwner errors.ValidationError removedUsers bool user *User err interface{} ) for _, email := range emails { if team.Owner == email { errOwner = errors.NewValidationError(errors.ErrRemoveOwnerFromTeam) err = &errOwner Logger.Warn("Could not remove the from %s from the team: %s.", team.Owner, team.Alias) continue } user = &User{Email: email} if !user.Exists() { Logger.Info("Failed to remove the user '%s' from team '%s' (User not found).", user.Email, team.Alias) continue } if i, err := team.ContainsUser(user); err == nil { hi := len(team.Users) - 1 if hi > i { team.Users[i] = team.Users[hi] } team.Users = team.Users[:hi] removedUsers = true } } if removedUsers { err := store.UpsertTeam(*team) Logger.Info("team.RemoveUsers: %+v. Err: %s.", team, err) return err } if err != nil { return errOwner } return nil }
func (service *Service) Create(owner User, team Team) error { service.Owner = owner.Email service.Subdomain = strings.ToLower(service.Subdomain) service.Team = team.Alias if err := service.valid(); err != nil { Logger.Info("Failed to create a service with invalid data: %+v.", service) return err } if service.Exists() { Logger.Info("Failed to create a service with duplicate data: %+v.", service) return errors.NewValidationError(errors.ErrServiceDuplicateEntry) } err := store.UpsertService(*service) if err == nil { go publishService(service) } Logger.Info("service.Create: %+v. Err: %s.", service, err) return err }
// Create a team. // // It requires to inform the owner and a name. // If the `alias` is not informed, it will be generate based on the team name. func (team *Team) Create(owner User) error { if err := team.valid(); err != nil { Logger.Info("Failed to create a team with invalid data: %+v.", team) return err } team.Users = append(team.Users, owner.Email) team.Owner = owner.Email if team.Alias == "" { team.Alias = utils.GenerateSlug(team.Name) } else { team.Alias = utils.GenerateSlug(team.Alias) } if team.Exists() { Logger.Info("Failed to create a team with duplicate data: %+v.", team) return errors.NewValidationError(errors.ErrTeamDuplicateEntry) } err := store.UpsertTeam(*team) Logger.Info("team.Create: %+v. Err: %s.", team, err) return err }
func (service *Service) valid() error { if service.Subdomain == "" || service.Endpoint == "" || service.Team == "" { return errors.NewValidationError(errors.ErrServiceMissingRequiredFields) } return nil }
func (w *Hook) valid() error { if w.Name == "" && w.Team == "" && len(w.Events) == 0 { return errors.NewValidationError(errors.ErrHookMissingRequiredFields) } return nil }
func (team *Team) valid() error { if team.Name == "" { return errors.NewValidationError(errors.ErrTeamMissingRequiredFields) } return nil }