From 53b00d80d66dade810b54fc31c0ad7a1d5164028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 16 Dec 2014 09:06:49 +0100 Subject: [PATCH] Fixed GetOtherAccountsFor query --- pkg/models/account.go | 50 +----------------------- pkg/stores/sqlstore/sqlstore_accounts.go | 3 +- 2 files changed, 4 insertions(+), 49 deletions(-) diff --git a/pkg/models/account.go b/pkg/models/account.go index 75a743f587d..6689d147a49 100644 --- a/pkg/models/account.go +++ b/pkg/models/account.go @@ -19,14 +19,6 @@ var ( ErrAccountNotFound = errors.New("Account not found") ) -type CollaboratorLink struct { - AccountId int64 - Role string - Email string - ModifiedOn time.Time - CreatedOn time.Time -} - type OtherAccount struct { Id int64 Email string @@ -45,44 +37,6 @@ type Account struct { Company string NextDashboardId int UsingAccountId int64 - Collaborators []CollaboratorLink `xorm:"-"` - Created time.Time `xorm:"CREATED"` - Updated time.Time `xorm:"UPDATED"` -} - -func (account *Account) AddCollaborator(newCollaborator *Account) error { - for _, collaborator := range account.Collaborators { - if collaborator.AccountId == newCollaborator.Id { - return errors.New("Collaborator already exists") - } - } - - account.Collaborators = append(account.Collaborators, CollaboratorLink{ - AccountId: newCollaborator.Id, - Email: newCollaborator.Email, - Role: "admin", - CreatedOn: time.Now(), - ModifiedOn: time.Now(), - }) - - return nil -} - -func (account *Account) RemoveCollaborator(accountId int64) { - list := account.Collaborators - for i, collaborator := range list { - if collaborator.AccountId == accountId { - account.Collaborators = append(list[:i], list[i+1:]...) - break - } - } -} - -func (account *Account) HasCollaborator(accountId int64) bool { - for _, collaborator := range account.Collaborators { - if collaborator.AccountId == accountId { - return true - } - } - return false + Created time.Time `xorm:"CREATED"` + Updated time.Time `xorm:"UPDATED"` } diff --git a/pkg/stores/sqlstore/sqlstore_accounts.go b/pkg/stores/sqlstore/sqlstore_accounts.go index 572fe67105b..729b3412b86 100644 --- a/pkg/stores/sqlstore/sqlstore_accounts.go +++ b/pkg/stores/sqlstore/sqlstore_accounts.go @@ -96,8 +96,9 @@ func AddCollaborator(collaborator *models.Collaborator) error { func GetOtherAccountsFor(accountId int64) ([]*models.OtherAccount, error) { collaborators := make([]*models.OtherAccount, 0) sess := x.Table("collaborator") - sess.Join("INNER", "account", "account.id=collaborator.account_Id") + sess.Join("INNER", "account", "collaborator.for_account_id=account.id") sess.Where("account_id=?", accountId) + sess.Cols("collaborator.id", "collaborator.role", "account.email") err := sess.Find(&collaborators) return collaborators, err }