Lots of progress on account management
This commit is contained in:
+30
-3
@@ -8,10 +8,17 @@ import (
|
||||
type CollaboratorLink struct {
|
||||
AccountId int
|
||||
Role string
|
||||
Email string
|
||||
ModifiedOn time.Time
|
||||
CreatedOn time.Time
|
||||
}
|
||||
|
||||
type OtherAccount struct {
|
||||
Id int `gorethink:"id"`
|
||||
Name string
|
||||
Role string
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
Id int `gorethink:"id"`
|
||||
Version int
|
||||
@@ -27,15 +34,16 @@ type Account struct {
|
||||
LastLoginOn time.Time
|
||||
}
|
||||
|
||||
func (account *Account) AddCollaborator(accountId int) error {
|
||||
func (account *Account) AddCollaborator(newCollaborator *Account) error {
|
||||
for _, collaborator := range account.Collaborators {
|
||||
if collaborator.AccountId == accountId {
|
||||
if collaborator.AccountId == newCollaborator.Id {
|
||||
return errors.New("Collaborator already exists")
|
||||
}
|
||||
}
|
||||
|
||||
account.Collaborators = append(account.Collaborators, CollaboratorLink{
|
||||
AccountId: accountId,
|
||||
AccountId: newCollaborator.Id,
|
||||
Email: newCollaborator.Email,
|
||||
Role: "admin",
|
||||
CreatedOn: time.Now(),
|
||||
ModifiedOn: time.Now(),
|
||||
@@ -43,3 +51,22 @@ func (account *Account) AddCollaborator(accountId int) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (account *Account) RemoveCollaborator(accountId int) {
|
||||
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 int) bool {
|
||||
for _, collaborator := range account.Collaborators {
|
||||
if collaborator.AccountId == accountId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user