Add collaborator now handles role, added macaron-contrib/binding for binding and validation

This commit is contained in:
Torkel Ödegaard
2015-01-16 11:54:19 +01:00
parent cd5843e977
commit f858f6b621
11 changed files with 81 additions and 75 deletions

View File

@@ -134,11 +134,15 @@ func GetAccountByToken(query *m.GetAccountByTokenQuery) error {
}
func GetAccountByLogin(query *m.GetAccountByLoginQuery) error {
if query.LoginOrEmail == "" {
return m.ErrAccountNotFound
}
account := new(m.Account)
if strings.Contains(query.Login, "@") {
account = &m.Account{Email: query.Login}
if strings.Contains(query.LoginOrEmail, "@") {
account = &m.Account{Email: query.LoginOrEmail}
} else {
account = &m.Account{Login: strings.ToLower(query.Login)}
account = &m.Account{Login: strings.ToLower(query.LoginOrEmail)}
}
has, err := x.Get(account)

View File

@@ -46,7 +46,7 @@ func TestAccountDataAccess(t *testing.T) {
cmd := m.AddCollaboratorCommand{
AccountId: ac1.Id,
CollaboratorId: ac2.Id,
Role: m.ROLE_READ_WRITE,
Role: m.ROLE_VIEWER,
}
err := AddCollaborator(&cmd)

View File

@@ -45,7 +45,7 @@ func init() {
}
func EnsureAdminUser() {
adminQuery := m.GetAccountByLoginQuery{Login: setting.AdminUser}
adminQuery := m.GetAccountByLoginQuery{LoginOrEmail: setting.AdminUser}
if err := bus.Dispatch(&adminQuery); err == m.ErrAccountNotFound {
cmd := m.CreateAccountCommand{}