Small link share fixes (#96)
This commit is contained in:
parent
158ad631e1
commit
fdd1624121
4 changed files with 28 additions and 10 deletions
|
@ -44,8 +44,6 @@ type LinkSharing struct {
|
|||
// The right this list is shared with. 0 = Read only, 1 = Read & Write, 2 = Admin. See the docs for more details.
|
||||
Right Right `xorm:"int(11) INDEX not null default 0" json:"right" valid:"length(0|2)" maximum:"2" default:"0"`
|
||||
|
||||
List *List `xorm:"-" json:"list" param:"fullist"`
|
||||
|
||||
// The kind of this link. 0 = undefined, 1 = without password, 2 = with password (currently not implemented).
|
||||
SharingType SharingType `xorm:"int(11) INDEX not null default 0" json:"sharing_type" valid:"length(0|2)" maximum:"2" default:"0"`
|
||||
|
||||
|
@ -102,6 +100,7 @@ func (share *LinkSharing) Create(a web.Auth) (err error) {
|
|||
share.SharedByID = a.GetID()
|
||||
share.Hash = utils.MakeRandomString(40)
|
||||
_, err = x.Insert(share)
|
||||
share.SharedBy, _ = a.(*User)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -158,6 +157,26 @@ func (share *LinkSharing) ReadAll(search string, a web.Auth, page int) (interfac
|
|||
Where("list_id = ? AND hash LIKE ?", share.ListID, "%"+search+"%").
|
||||
Limit(getLimitFromPageIndex(page)).
|
||||
Find(&shares)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Find all users and add them
|
||||
var userIDs []int64
|
||||
for _, s := range shares {
|
||||
userIDs = append(userIDs, s.SharedByID)
|
||||
}
|
||||
|
||||
users := make(map[int64]*User)
|
||||
err = x.In("id", userIDs).Find(&users)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, s := range shares {
|
||||
s.SharedBy = users[s.SharedByID]
|
||||
}
|
||||
|
||||
return shares, err
|
||||
}
|
||||
|
||||
|
@ -190,7 +209,6 @@ func GetLinkShareByHash(hash string) (share *LinkSharing, err error) {
|
|||
if !has {
|
||||
return share, ErrListShareDoesNotExist{Hash: hash}
|
||||
}
|
||||
share.List = &List{ID: share.ListID}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ func (share *LinkSharing) canDoLinkShare(a web.Auth) (bool, error) {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
l, err := GetListByShareHash(share.Hash)
|
||||
l, err := GetListSimplByTaskID(share.ListID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -88,12 +88,12 @@ func (l *List) ReadAll(search string, a web.Auth, page int) (interface{}, error)
|
|||
// Check if we're dealing with a share auth
|
||||
shareAuth, ok := a.(*LinkSharing)
|
||||
if ok {
|
||||
shareAuth.List = &List{ID: shareAuth.ListID}
|
||||
err := shareAuth.List.GetSimpleByID()
|
||||
list := &List{ID: shareAuth.ListID}
|
||||
err := list.GetSimpleByID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lists := []*List{shareAuth.List}
|
||||
lists := []*List{list}
|
||||
err = AddListDetails(lists)
|
||||
return lists, err
|
||||
}
|
||||
|
|
|
@ -156,12 +156,12 @@ func (t *Task) ReadAll(search string, a web.Auth, page int) (interface{}, error)
|
|||
|
||||
shareAuth, is := a.(*LinkSharing)
|
||||
if is {
|
||||
shareAuth.List = &List{ID: shareAuth.ListID}
|
||||
err := shareAuth.List.GetSimpleByID()
|
||||
list := &List{ID: shareAuth.ListID}
|
||||
err := list.GetSimpleByID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return getTasksForLists([]*List{shareAuth.List}, taskopts)
|
||||
return getTasksForLists([]*List{list}, taskopts)
|
||||
}
|
||||
|
||||
// Get all lists for the user
|
||||
|
|
Loading…
Reference in a new issue