Moved add collaborator to command way of doing it

This commit is contained in:
Torkel Ödegaard
2014-12-19 10:45:22 +01:00
parent 36c46112df
commit ccba95542b
6 changed files with 87 additions and 66 deletions

View File

@@ -6,12 +6,10 @@ import (
)
var (
SaveAccount func(account *Account) error
GetAccountByLogin func(emailOrName string) (*Account, error)
GetAccount func(accountId int64) (*Account, error)
GetOtherAccountsFor func(accountId int64) ([]*OtherAccount, error)
GetCollaboratorsForAccount func(accountId int64) ([]*CollaboratorInfo, error)
AddCollaborator func(collaborator *Collaborator) error
SaveAccount func(account *Account) error
GetAccountByLogin func(emailOrName string) (*Account, error)
GetAccount func(accountId int64) (*Account, error)
GetOtherAccountsFor func(accountId int64) ([]*OtherAccount, error)
)
// Typed errors
@@ -30,7 +28,7 @@ type Account struct {
Id int64
Login string `xorm:"UNIQUE NOT NULL"`
Email string `xorm:"UNIQUE NOT NULL"`
Name string `xorm:"UNIQUE NOT NULL"`
Name string
FullName string
Password string
IsAdmin bool

View File

@@ -5,8 +5,8 @@ import (
)
const (
ROLE_READ_WRITE = "ReadWrite"
ROLE_READ = "Read"
ROLE_READ_WRITE RoleType = "ReadWrite"
ROLE_READ = "Read"
)
type RoleType string
@@ -16,15 +16,16 @@ type Collaborator struct {
AccountId int64 `xorm:"not null unique(uix_account_id_for_account_id)"` // The account that can use another account
Role RoleType `xorm:"not null"` // Permission type
ForAccountId int64 `xorm:"not null unique(uix_account_id_for_account_id)"` // The account being given access to
Created time.Time
Updated time.Time
Created time.Time
Updated time.Time
}
// read only projection
type CollaboratorInfo struct {
AccountId int64
Role string
Email string
type AddCollaboratorCommand struct {
Email string `json:"email" binding:"required"`
AccountId int64 `json:"-"`
ForAccountId int64 `json:"-"`
Role RoleType `json:"-"`
}
func NewCollaborator(accountId int64, forAccountId int64, role RoleType) *Collaborator {