Make sure all tables are properly pluralized
This commit is contained in:
parent
bc782e68ff
commit
73f2d4532d
29 changed files with 178 additions and 96 deletions
52
pkg/migration/20210328191017.go
Normal file
52
pkg/migration/20210328191017.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
// Vikunja is a to-do list application to facilitate your life.
|
||||||
|
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public Licensee as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public Licensee for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public Licensee
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"src.techknowlogick.com/xormigrate"
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
migrations = append(migrations, &xormigrate.Migration{
|
||||||
|
ID: "20210328191017",
|
||||||
|
Description: "Make sure all tables are correctly pluralized",
|
||||||
|
Migrate: func(tx *xorm.Engine) error {
|
||||||
|
// old name => new name
|
||||||
|
tables := map[string]string{
|
||||||
|
"label_task": "label_tasks",
|
||||||
|
"link_sharing": "link_shares",
|
||||||
|
"list": "lists",
|
||||||
|
"team_list": "team_lists",
|
||||||
|
"users_list": "users_lists",
|
||||||
|
"users_namespace": "users_namespaces",
|
||||||
|
}
|
||||||
|
|
||||||
|
for oldName, newName := range tables {
|
||||||
|
err := renameTable(tx, oldName, newName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Rollback: func(tx *xorm.Engine) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -158,6 +158,29 @@ func modifyColumn(x *xorm.Engine, tableName, col, newDefinition string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renameTable(x *xorm.Engine, oldName, newName string) error {
|
||||||
|
switch config.DatabaseType.GetString() {
|
||||||
|
case "sqlite":
|
||||||
|
_, err := x.Exec("ALTER TABLE `" + oldName + "` RENAME TO `" + newName + "`")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case "mysql":
|
||||||
|
_, err := x.Exec("RENAME TABLE `" + oldName + "` TO `" + newName + "`")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case "postgres":
|
||||||
|
_, err := x.Exec("ALTER TABLE `" + oldName + "` RENAME TO `" + newName + "`")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Fatal("Unknown db.")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func initSchema(tx *xorm.Engine) error {
|
func initSchema(tx *xorm.Engine) error {
|
||||||
schemeBeans := []interface{}{}
|
schemeBeans := []interface{}{}
|
||||||
schemeBeans = append(schemeBeans, models.GetTables()...)
|
schemeBeans = append(schemeBeans, models.GetTables()...)
|
||||||
|
|
|
@ -252,7 +252,7 @@ const ErrCodeListIsArchived = 3008
|
||||||
|
|
||||||
// HTTPError holds the http error description
|
// HTTPError holds the http error description
|
||||||
func (err ErrListIsArchived) HTTPError() web.HTTPError {
|
func (err ErrListIsArchived) HTTPError() web.HTTPError {
|
||||||
return web.HTTPError{HTTPCode: http.StatusPreconditionFailed, Code: ErrCodeListIsArchived, Message: "This lists is archived. Editing or creating new tasks is not possible."}
|
return web.HTTPError{HTTPCode: http.StatusPreconditionFailed, Code: ErrCodeListIsArchived, Message: "This list is archived. Editing or creating new tasks is not possible."}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================
|
// ================
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (l *Label) hasAccessToLabel(s *xorm.Session, a web.Auth) (has bool, maxRigh
|
||||||
return false, 0, err
|
return false, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cond := builder.In("label_task.task_id",
|
cond := builder.In("label_tasks.task_id",
|
||||||
builder.
|
builder.
|
||||||
Select("id").
|
Select("id").
|
||||||
From("tasks").
|
From("tasks").
|
||||||
|
@ -82,9 +82,9 @@ func (l *Label) hasAccessToLabel(s *xorm.Session, a web.Auth) (has bool, maxRigh
|
||||||
|
|
||||||
ll := &LabelTask{}
|
ll := &LabelTask{}
|
||||||
has, err = s.Table("labels").
|
has, err = s.Table("labels").
|
||||||
Select("label_task.*").
|
Select("label_tasks.*").
|
||||||
Join("LEFT", "label_task", "label_task.label_id = labels.id").
|
Join("LEFT", "label_tasks", "label_tasks.label_id = labels.id").
|
||||||
Where("label_task.label_id is not null OR labels.created_by_id = ?", u.ID).
|
Where("label_tasks.label_id is not null OR labels.created_by_id = ?", u.ID).
|
||||||
Or(cond).
|
Or(cond).
|
||||||
And("labels.id = ?", l.ID).
|
And("labels.id = ?", l.ID).
|
||||||
Exist(ll)
|
Exist(ll)
|
||||||
|
|
|
@ -44,7 +44,7 @@ type LabelTask struct {
|
||||||
|
|
||||||
// TableName makes a pretty table name
|
// TableName makes a pretty table name
|
||||||
func (LabelTask) TableName() string {
|
func (LabelTask) TableName() string {
|
||||||
return "label_task"
|
return "label_tasks"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes a label on a task
|
// Delete deletes a label on a task
|
||||||
|
@ -159,8 +159,8 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab
|
||||||
// multiple times when it is associated to more than one task.
|
// multiple times when it is associated to more than one task.
|
||||||
// Because of this whole thing, we need this extra switch here to only group by Task IDs if needed.
|
// Because of this whole thing, we need this extra switch here to only group by Task IDs if needed.
|
||||||
// Probably not the most ideal solution.
|
// Probably not the most ideal solution.
|
||||||
var groupBy = "labels.id,label_task.task_id"
|
var groupBy = "labels.id,label_tasks.task_id"
|
||||||
var selectStmt = "labels.*, label_task.task_id"
|
var selectStmt = "labels.*, label_tasks.task_id"
|
||||||
if opts.GroupByLabelIDsOnly {
|
if opts.GroupByLabelIDsOnly {
|
||||||
groupBy = "labels.id"
|
groupBy = "labels.id"
|
||||||
selectStmt = "labels.*"
|
selectStmt = "labels.*"
|
||||||
|
@ -168,12 +168,12 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab
|
||||||
|
|
||||||
// Get all labels associated with these tasks
|
// Get all labels associated with these tasks
|
||||||
var labels []*labelWithTaskID
|
var labels []*labelWithTaskID
|
||||||
cond := builder.And(builder.NotNull{"label_task.label_id"})
|
cond := builder.And(builder.NotNull{"label_tasks.label_id"})
|
||||||
if len(opts.TaskIDs) > 0 && opts.GetForUser == 0 {
|
if len(opts.TaskIDs) > 0 && opts.GetForUser == 0 {
|
||||||
cond = builder.And(builder.In("label_task.task_id", opts.TaskIDs), cond)
|
cond = builder.And(builder.In("label_tasks.task_id", opts.TaskIDs), cond)
|
||||||
}
|
}
|
||||||
if opts.GetForUser != 0 {
|
if opts.GetForUser != 0 {
|
||||||
cond = builder.And(builder.In("label_task.task_id",
|
cond = builder.And(builder.In("label_tasks.task_id",
|
||||||
builder.
|
builder.
|
||||||
Select("id").
|
Select("id").
|
||||||
From("tasks").
|
From("tasks").
|
||||||
|
@ -207,7 +207,7 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab
|
||||||
|
|
||||||
query := s.Table("labels").
|
query := s.Table("labels").
|
||||||
Select(selectStmt).
|
Select(selectStmt).
|
||||||
Join("LEFT", "label_task", "label_task.label_id = labels.id").
|
Join("LEFT", "label_tasks", "label_tasks.label_id = labels.id").
|
||||||
Where(cond).
|
Where(cond).
|
||||||
GroupBy(groupBy).
|
GroupBy(groupBy).
|
||||||
OrderBy("labels.id ASC")
|
OrderBy("labels.id ASC")
|
||||||
|
@ -249,7 +249,7 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab
|
||||||
// Get the total number of entries
|
// Get the total number of entries
|
||||||
totalEntries, err = s.Table("labels").
|
totalEntries, err = s.Table("labels").
|
||||||
Select("count(DISTINCT labels.id)").
|
Select("count(DISTINCT labels.id)").
|
||||||
Join("LEFT", "label_task", "label_task.label_id = labels.id").
|
Join("LEFT", "label_tasks", "label_tasks.label_id = labels.id").
|
||||||
Where(cond).
|
Where(cond).
|
||||||
And("labels.title LIKE ?", "%"+opts.Search+"%").
|
And("labels.title LIKE ?", "%"+opts.Search+"%").
|
||||||
Count(&Label{})
|
Count(&Label{})
|
||||||
|
|
|
@ -215,11 +215,11 @@ func TestLabelTask_Create(t *testing.T) {
|
||||||
CRUDable: tt.fields.CRUDable,
|
CRUDable: tt.fields.CRUDable,
|
||||||
Rights: tt.fields.Rights,
|
Rights: tt.fields.Rights,
|
||||||
}
|
}
|
||||||
allowed, _ := l.CanCreate(s, tt.args.a)
|
allowed, err := l.CanCreate(s, tt.args.a)
|
||||||
if !allowed && !tt.wantForbidden {
|
if !allowed && !tt.wantForbidden {
|
||||||
t.Errorf("LabelTask.CanCreate() forbidden, want %v", tt.wantForbidden)
|
t.Errorf("LabelTask.CanCreate() forbidden, want %v, err %v", tt.wantForbidden, err)
|
||||||
}
|
}
|
||||||
err := l.Create(s, tt.args.a)
|
err = l.Create(s, tt.args.a)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("LabelTask.Create() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("LabelTask.Create() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ func TestLabelTask_Create(t *testing.T) {
|
||||||
t.Errorf("LabelTask.Create() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name())
|
t.Errorf("LabelTask.Create() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name())
|
||||||
}
|
}
|
||||||
if !tt.wantErr {
|
if !tt.wantErr {
|
||||||
db.AssertExists(t, "label_task", map[string]interface{}{
|
db.AssertExists(t, "label_tasks", map[string]interface{}{
|
||||||
"id": l.ID,
|
"id": l.ID,
|
||||||
"task_id": l.TaskID,
|
"task_id": l.TaskID,
|
||||||
"label_id": l.LabelID,
|
"label_id": l.LabelID,
|
||||||
|
@ -326,7 +326,7 @@ func TestLabelTask_Delete(t *testing.T) {
|
||||||
t.Errorf("LabelTask.Delete() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name())
|
t.Errorf("LabelTask.Delete() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name())
|
||||||
}
|
}
|
||||||
if !tt.wantForbidden {
|
if !tt.wantForbidden {
|
||||||
db.AssertMissing(t, "label_task", map[string]interface{}{
|
db.AssertMissing(t, "label_tasks", map[string]interface{}{
|
||||||
"label_id": l.LabelID,
|
"label_id": l.LabelID,
|
||||||
"task_id": l.TaskID,
|
"task_id": l.TaskID,
|
||||||
})
|
})
|
||||||
|
|
|
@ -65,7 +65,7 @@ type LinkSharing struct {
|
||||||
|
|
||||||
// TableName holds the table name
|
// TableName holds the table name
|
||||||
func (LinkSharing) TableName() string {
|
func (LinkSharing) TableName() string {
|
||||||
return "link_sharing"
|
return "link_shares"
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetID returns the ID of the links sharing object
|
// GetID returns the ID of the links sharing object
|
||||||
|
|
|
@ -80,6 +80,11 @@ type List struct {
|
||||||
web.Rights `xorm:"-" json:"-"`
|
web.Rights `xorm:"-" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableName returns a better name for the lists table
|
||||||
|
func (l *List) TableName() string {
|
||||||
|
return "lists"
|
||||||
|
}
|
||||||
|
|
||||||
// ListBackgroundType holds a list background type
|
// ListBackgroundType holds a list background type
|
||||||
type ListBackgroundType struct {
|
type ListBackgroundType struct {
|
||||||
Type string
|
Type string
|
||||||
|
@ -292,9 +297,9 @@ func GetListSimplByTaskID(s *xorm.Session, taskID int64) (l *List, err error) {
|
||||||
// leading to not finding anything if the id is good, but for example the title is different.
|
// leading to not finding anything if the id is good, but for example the title is different.
|
||||||
var list List
|
var list List
|
||||||
exists, err := s.
|
exists, err := s.
|
||||||
Select("list.*").
|
Select("lists.*").
|
||||||
Table(List{}).
|
Table(List{}).
|
||||||
Join("INNER", "tasks", "list.id = tasks.list_id").
|
Join("INNER", "tasks", "lists.id = tasks.list_id").
|
||||||
Where("tasks.id = ?", taskID).
|
Where("tasks.id = ?", taskID).
|
||||||
Get(&list)
|
Get(&list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -336,14 +341,14 @@ func getUserListsStatement(userID int64) *builder.Builder {
|
||||||
|
|
||||||
return builder.Dialect(dialect).
|
return builder.Dialect(dialect).
|
||||||
Select("l.*").
|
Select("l.*").
|
||||||
From("list", "l").
|
From("lists", "l").
|
||||||
Join("INNER", "namespaces n", "l.namespace_id = n.id").
|
Join("INNER", "namespaces n", "l.namespace_id = n.id").
|
||||||
Join("LEFT", "team_namespaces tn", "tn.namespace_id = n.id").
|
Join("LEFT", "team_namespaces tn", "tn.namespace_id = n.id").
|
||||||
Join("LEFT", "team_members tm", "tm.team_id = tn.team_id").
|
Join("LEFT", "team_members tm", "tm.team_id = tn.team_id").
|
||||||
Join("LEFT", "team_list tl", "l.id = tl.list_id").
|
Join("LEFT", "team_lists tl", "l.id = tl.list_id").
|
||||||
Join("LEFT", "team_members tm2", "tm2.team_id = tl.team_id").
|
Join("LEFT", "team_members tm2", "tm2.team_id = tl.team_id").
|
||||||
Join("LEFT", "users_list ul", "ul.list_id = l.id").
|
Join("LEFT", "users_lists ul", "ul.list_id = l.id").
|
||||||
Join("LEFT", "users_namespace un", "un.namespace_id = l.namespace_id").
|
Join("LEFT", "users_namespaces un", "un.namespace_id = l.namespace_id").
|
||||||
Where(builder.Or(
|
Where(builder.Or(
|
||||||
builder.Eq{"tm.user_id": userID},
|
builder.Eq{"tm.user_id": userID},
|
||||||
builder.Eq{"tm2.user_id": userID},
|
builder.Eq{"tm2.user_id": userID},
|
||||||
|
@ -373,8 +378,9 @@ func getRawListsForUser(s *xorm.Session, opts *listOptions) (lists []*List, resu
|
||||||
limit, start := getLimitFromPageIndex(opts.page, opts.perPage)
|
limit, start := getLimitFromPageIndex(opts.page, opts.perPage)
|
||||||
|
|
||||||
var filterCond builder.Cond
|
var filterCond builder.Cond
|
||||||
vals := strings.Split(opts.search, ",")
|
|
||||||
ids := []int64{}
|
ids := []int64{}
|
||||||
|
if opts.search != "" {
|
||||||
|
vals := strings.Split(opts.search, ",")
|
||||||
for _, val := range vals {
|
for _, val := range vals {
|
||||||
v, err := strconv.ParseInt(val, 10, 64)
|
v, err := strconv.ParseInt(val, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -383,6 +389,7 @@ func getRawListsForUser(s *xorm.Session, opts *listOptions) (lists []*List, resu
|
||||||
}
|
}
|
||||||
ids = append(ids, v)
|
ids = append(ids, v)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(ids) > 0 {
|
if len(ids) > 0 {
|
||||||
filterCond = builder.In("l.id", ids)
|
filterCond = builder.In("l.id", ids)
|
||||||
|
@ -486,9 +493,9 @@ func (l *List) CheckIsArchived(s *xorm.Session) (err error) {
|
||||||
|
|
||||||
nl := &NamespaceList{}
|
nl := &NamespaceList{}
|
||||||
exists, err := s.
|
exists, err := s.
|
||||||
Table("list").
|
Table("lists").
|
||||||
Join("LEFT", "namespaces", "list.namespace_id = namespaces.id").
|
Join("LEFT", "namespaces", "lists.namespace_id = namespaces.id").
|
||||||
Where("list.id = ? AND (list.is_archived = true OR namespaces.is_archived = true)", l.ID).
|
Where("lists.id = ? AND (lists.is_archived = true OR namespaces.is_archived = true)", l.ID).
|
||||||
Get(nl)
|
Get(nl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -222,16 +222,16 @@ func (l *List) checkRight(s *xorm.Session, a web.Auth, rights ...Right) (bool, i
|
||||||
r := &allListRights{}
|
r := &allListRights{}
|
||||||
var maxRight = 0
|
var maxRight = 0
|
||||||
exists, err := s.
|
exists, err := s.
|
||||||
Table("list").
|
Table("lists").
|
||||||
Alias("l").
|
Alias("l").
|
||||||
// User stuff
|
// User stuff
|
||||||
Join("LEFT", []string{"users_namespace", "un"}, "un.namespace_id = l.namespace_id").
|
Join("LEFT", []string{"users_namespaces", "un"}, "un.namespace_id = l.namespace_id").
|
||||||
Join("LEFT", []string{"users_list", "ul"}, "ul.list_id = l.id").
|
Join("LEFT", []string{"users_lists", "ul"}, "ul.list_id = l.id").
|
||||||
Join("LEFT", []string{"namespaces", "n"}, "n.id = l.namespace_id").
|
Join("LEFT", []string{"namespaces", "n"}, "n.id = l.namespace_id").
|
||||||
// Team stuff
|
// Team stuff
|
||||||
Join("LEFT", []string{"team_namespaces", "tn"}, " l.namespace_id = tn.namespace_id").
|
Join("LEFT", []string{"team_namespaces", "tn"}, " l.namespace_id = tn.namespace_id").
|
||||||
Join("LEFT", []string{"team_members", "tm"}, "tm.team_id = tn.team_id").
|
Join("LEFT", []string{"team_members", "tm"}, "tm.team_id = tn.team_id").
|
||||||
Join("LEFT", []string{"team_list", "tl"}, "l.id = tl.list_id").
|
Join("LEFT", []string{"team_lists", "tl"}, "l.id = tl.list_id").
|
||||||
Join("LEFT", []string{"team_members", "tm2"}, "tm2.team_id = tl.team_id").
|
Join("LEFT", []string{"team_members", "tm2"}, "tm2.team_id = tl.team_id").
|
||||||
// The actual condition
|
// The actual condition
|
||||||
Where(builder.And(
|
Where(builder.And(
|
||||||
|
|
|
@ -47,7 +47,7 @@ type TeamList struct {
|
||||||
|
|
||||||
// TableName makes beautiful table names
|
// TableName makes beautiful table names
|
||||||
func (TeamList) TableName() string {
|
func (TeamList) TableName() string {
|
||||||
return "team_list"
|
return "team_lists"
|
||||||
}
|
}
|
||||||
|
|
||||||
// TeamWithRight represents a team, combined with rights.
|
// TeamWithRight represents a team, combined with rights.
|
||||||
|
@ -196,8 +196,8 @@ func (tl *TeamList) ReadAll(s *xorm.Session, a web.Auth, search string, page int
|
||||||
all := []*TeamWithRight{}
|
all := []*TeamWithRight{}
|
||||||
query := s.
|
query := s.
|
||||||
Table("teams").
|
Table("teams").
|
||||||
Join("INNER", "team_list", "team_id = teams.id").
|
Join("INNER", "team_lists", "team_id = teams.id").
|
||||||
Where("team_list.list_id = ?", tl.ListID).
|
Where("team_lists.list_id = ?", tl.ListID).
|
||||||
Where("teams.name LIKE ?", "%"+search+"%")
|
Where("teams.name LIKE ?", "%"+search+"%")
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
query = query.Limit(limit, start)
|
query = query.Limit(limit, start)
|
||||||
|
@ -219,8 +219,8 @@ func (tl *TeamList) ReadAll(s *xorm.Session, a web.Auth, search string, page int
|
||||||
|
|
||||||
totalItems, err = s.
|
totalItems, err = s.
|
||||||
Table("teams").
|
Table("teams").
|
||||||
Join("INNER", "team_list", "team_id = teams.id").
|
Join("INNER", "team_lists", "team_id = teams.id").
|
||||||
Where("team_list.list_id = ?", tl.ListID).
|
Where("team_lists.list_id = ?", tl.ListID).
|
||||||
Where("teams.name LIKE ?", "%"+search+"%").
|
Where("teams.name LIKE ?", "%"+search+"%").
|
||||||
Count(&TeamWithRight{})
|
Count(&TeamWithRight{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -99,7 +99,7 @@ func TestTeamList_Create(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = s.Commit()
|
err = s.Commit()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
db.AssertExists(t, "team_list", map[string]interface{}{
|
db.AssertExists(t, "team_lists", map[string]interface{}{
|
||||||
"team_id": 1,
|
"team_id": 1,
|
||||||
"list_id": 1,
|
"list_id": 1,
|
||||||
"right": RightAdmin,
|
"right": RightAdmin,
|
||||||
|
@ -171,7 +171,7 @@ func TestTeamList_Delete(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = s.Commit()
|
err = s.Commit()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
db.AssertMissing(t, "team_list", map[string]interface{}{
|
db.AssertMissing(t, "team_lists", map[string]interface{}{
|
||||||
"team_id": 1,
|
"team_id": 1,
|
||||||
"list_id": 3,
|
"list_id": 3,
|
||||||
})
|
})
|
||||||
|
@ -279,7 +279,7 @@ func TestTeamList_Update(t *testing.T) {
|
||||||
err = s.Commit()
|
err = s.Commit()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if !tt.wantErr {
|
if !tt.wantErr {
|
||||||
db.AssertExists(t, "team_list", map[string]interface{}{
|
db.AssertExists(t, "team_lists", map[string]interface{}{
|
||||||
"list_id": tt.fields.ListID,
|
"list_id": tt.fields.ListID,
|
||||||
"team_id": tt.fields.TeamID,
|
"team_id": tt.fields.TeamID,
|
||||||
"right": tt.fields.Right,
|
"right": tt.fields.Right,
|
||||||
|
|
|
@ -45,7 +45,7 @@ func TestList_CreateOrUpdate(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = s.Commit()
|
err = s.Commit()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
db.AssertExists(t, "list", map[string]interface{}{
|
db.AssertExists(t, "lists", map[string]interface{}{
|
||||||
"id": list.ID,
|
"id": list.ID,
|
||||||
"title": list.Title,
|
"title": list.Title,
|
||||||
"description": list.Description,
|
"description": list.Description,
|
||||||
|
@ -105,7 +105,7 @@ func TestList_CreateOrUpdate(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = s.Commit()
|
err = s.Commit()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
db.AssertExists(t, "list", map[string]interface{}{
|
db.AssertExists(t, "lists", map[string]interface{}{
|
||||||
"id": list.ID,
|
"id": list.ID,
|
||||||
"title": list.Title,
|
"title": list.Title,
|
||||||
"description": list.Description,
|
"description": list.Description,
|
||||||
|
@ -129,7 +129,7 @@ func TestList_CreateOrUpdate(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = s.Commit()
|
err = s.Commit()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
db.AssertExists(t, "list", map[string]interface{}{
|
db.AssertExists(t, "lists", map[string]interface{}{
|
||||||
"id": list.ID,
|
"id": list.ID,
|
||||||
"title": list.Title,
|
"title": list.Title,
|
||||||
"description": list.Description,
|
"description": list.Description,
|
||||||
|
@ -176,7 +176,7 @@ func TestList_Delete(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = s.Commit()
|
err = s.Commit()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
db.AssertMissing(t, "list", map[string]interface{}{
|
db.AssertMissing(t, "lists", map[string]interface{}{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ type ListUser struct {
|
||||||
|
|
||||||
// TableName is the table name for ListUser
|
// TableName is the table name for ListUser
|
||||||
func (ListUser) TableName() string {
|
func (ListUser) TableName() string {
|
||||||
return "users_list"
|
return "users_lists"
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserWithRight represents a user in combination with the right it can have on a list/namespace
|
// UserWithRight represents a user in combination with the right it can have on a list/namespace
|
||||||
|
@ -202,8 +202,8 @@ func (lu *ListUser) ReadAll(s *xorm.Session, a web.Auth, search string, page int
|
||||||
// Get all users
|
// Get all users
|
||||||
all := []*UserWithRight{}
|
all := []*UserWithRight{}
|
||||||
query := s.
|
query := s.
|
||||||
Join("INNER", "users_list", "user_id = users.id").
|
Join("INNER", "users_lists", "user_id = users.id").
|
||||||
Where("users_list.list_id = ?", lu.ListID).
|
Where("users_lists.list_id = ?", lu.ListID).
|
||||||
Where("users.username LIKE ?", "%"+search+"%")
|
Where("users.username LIKE ?", "%"+search+"%")
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
query = query.Limit(limit, start)
|
query = query.Limit(limit, start)
|
||||||
|
@ -219,8 +219,8 @@ func (lu *ListUser) ReadAll(s *xorm.Session, a web.Auth, search string, page int
|
||||||
}
|
}
|
||||||
|
|
||||||
numberOfTotalItems, err = s.
|
numberOfTotalItems, err = s.
|
||||||
Join("INNER", "users_list", "user_id = users.id").
|
Join("INNER", "users_lists", "user_id = users.id").
|
||||||
Where("users_list.list_id = ?", lu.ListID).
|
Where("users_lists.list_id = ?", lu.ListID).
|
||||||
Where("users.username LIKE ?", "%"+search+"%").
|
Where("users.username LIKE ?", "%"+search+"%").
|
||||||
Count(&UserWithRight{})
|
Count(&UserWithRight{})
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ func TestListUser_Create(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
if !tt.wantErr {
|
if !tt.wantErr {
|
||||||
db.AssertExists(t, "users_list", map[string]interface{}{
|
db.AssertExists(t, "users_lists", map[string]interface{}{
|
||||||
"user_id": ul.UserID,
|
"user_id": ul.UserID,
|
||||||
"list_id": tt.fields.ListID,
|
"list_id": tt.fields.ListID,
|
||||||
}, false)
|
}, false)
|
||||||
|
@ -323,7 +323,7 @@ func TestListUser_Update(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
if !tt.wantErr {
|
if !tt.wantErr {
|
||||||
db.AssertExists(t, "users_list", map[string]interface{}{
|
db.AssertExists(t, "users_lists", map[string]interface{}{
|
||||||
"list_id": tt.fields.ListID,
|
"list_id": tt.fields.ListID,
|
||||||
"user_id": lu.UserID,
|
"user_id": lu.UserID,
|
||||||
"right": tt.fields.Right,
|
"right": tt.fields.Right,
|
||||||
|
@ -405,7 +405,7 @@ func TestListUser_Delete(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
if !tt.wantErr {
|
if !tt.wantErr {
|
||||||
db.AssertMissing(t, "users_list", map[string]interface{}{
|
db.AssertMissing(t, "users_lists", map[string]interface{}{
|
||||||
"user_id": tt.fields.UserID,
|
"user_id": tt.fields.UserID,
|
||||||
"list_id": tt.fields.ListID,
|
"list_id": tt.fields.ListID,
|
||||||
})
|
})
|
||||||
|
|
|
@ -250,10 +250,10 @@ func getNamespacesWithLists(s *xorm.Session, namespaces *map[int64]*NamespaceWit
|
||||||
Table("namespaces").
|
Table("namespaces").
|
||||||
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_id").
|
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_id").
|
||||||
Join("LEFT", "team_members", "team_members.team_id = team_namespaces.team_id").
|
Join("LEFT", "team_members", "team_members.team_id = team_namespaces.team_id").
|
||||||
Join("LEFT", "users_namespace", "users_namespace.namespace_id = namespaces.id").
|
Join("LEFT", "users_namespaces", "users_namespaces.namespace_id = namespaces.id").
|
||||||
Where("team_members.user_id = ?", userID).
|
Where("team_members.user_id = ?", userID).
|
||||||
Or("namespaces.owner_id = ?", userID).
|
Or("namespaces.owner_id = ?", userID).
|
||||||
Or("users_namespace.user_id = ?", userID).
|
Or("users_namespaces.user_id = ?", userID).
|
||||||
GroupBy("namespaces.id").
|
GroupBy("namespaces.id").
|
||||||
Where(filterCond).
|
Where(filterCond).
|
||||||
Where(isArchivedCond)
|
Where(isArchivedCond)
|
||||||
|
@ -269,10 +269,10 @@ func getNamespacesWithLists(s *xorm.Session, namespaces *map[int64]*NamespaceWit
|
||||||
Table("namespaces").
|
Table("namespaces").
|
||||||
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_id").
|
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_id").
|
||||||
Join("LEFT", "team_members", "team_members.team_id = team_namespaces.team_id").
|
Join("LEFT", "team_members", "team_members.team_id = team_namespaces.team_id").
|
||||||
Join("LEFT", "users_namespace", "users_namespace.namespace_id = namespaces.id").
|
Join("LEFT", "users_namespaces", "users_namespaces.namespace_id = namespaces.id").
|
||||||
Where("team_members.user_id = ?", userID).
|
Where("team_members.user_id = ?", userID).
|
||||||
Or("namespaces.owner_id = ?", userID).
|
Or("namespaces.owner_id = ?", userID).
|
||||||
Or("users_namespace.user_id = ?", userID).
|
Or("users_namespaces.user_id = ?", userID).
|
||||||
And("namespaces.is_archived = false").
|
And("namespaces.is_archived = false").
|
||||||
GroupBy("namespaces.id").
|
GroupBy("namespaces.id").
|
||||||
Where(filterCond).
|
Where(filterCond).
|
||||||
|
@ -332,11 +332,11 @@ func getSharedListsInNamespace(s *xorm.Session, archived bool, doer *user.User)
|
||||||
// Get all lists individually shared with our user (not via a namespace)
|
// Get all lists individually shared with our user (not via a namespace)
|
||||||
individualLists := []*List{}
|
individualLists := []*List{}
|
||||||
iListQuery := s.Select("l.*").
|
iListQuery := s.Select("l.*").
|
||||||
Table("list").
|
Table("lists").
|
||||||
Alias("l").
|
Alias("l").
|
||||||
Join("LEFT", []string{"team_list", "tl"}, "l.id = tl.list_id").
|
Join("LEFT", []string{"team_lists", "tl"}, "l.id = tl.list_id").
|
||||||
Join("LEFT", []string{"team_members", "tm"}, "tm.team_id = tl.team_id").
|
Join("LEFT", []string{"team_members", "tm"}, "tm.team_id = tl.team_id").
|
||||||
Join("LEFT", []string{"users_list", "ul"}, "ul.list_id = l.id").
|
Join("LEFT", []string{"users_lists", "ul"}, "ul.list_id = l.id").
|
||||||
Where(builder.And(
|
Where(builder.And(
|
||||||
builder.Eq{"tm.user_id": doer.ID},
|
builder.Eq{"tm.user_id": doer.ID},
|
||||||
builder.Neq{"l.owner_id": doer.ID},
|
builder.Neq{"l.owner_id": doer.ID},
|
||||||
|
@ -390,8 +390,8 @@ func getFavoriteLists(s *xorm.Session, lists []*List, namespaceIDs []int64, doer
|
||||||
// Check if we have any favorites or favorited lists and remove the favorites namespace from the list if not
|
// Check if we have any favorites or favorited lists and remove the favorites namespace from the list if not
|
||||||
var favoriteCount int64
|
var favoriteCount int64
|
||||||
favoriteCount, err = s.
|
favoriteCount, err = s.
|
||||||
Join("INNER", "list", "tasks.list_id = list.id").
|
Join("INNER", "lists", "tasks.list_id = lists.id").
|
||||||
Join("INNER", "namespaces", "list.namespace_id = namespaces.id").
|
Join("INNER", "namespaces", "lists.namespace_id = namespaces.id").
|
||||||
Where(builder.And(builder.Eq{"tasks.is_favorite": true}, builder.In("namespaces.id", namespaceIDs))).
|
Where(builder.And(builder.Eq{"tasks.is_favorite": true}, builder.In("namespaces.id", namespaceIDs))).
|
||||||
Count(&Task{})
|
Count(&Task{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -83,7 +83,7 @@ func (n *Namespace) checkRight(s *xorm.Session, a web.Auth, rights ...Right) (bo
|
||||||
The following loop creates an sql condition like this one:
|
The following loop creates an sql condition like this one:
|
||||||
|
|
||||||
namespaces.owner_id = 1 OR
|
namespaces.owner_id = 1 OR
|
||||||
(users_namespace.user_id = 1 AND users_namespace.right = 1) OR
|
(users_namespaces.user_id = 1 AND users_namespaces.right = 1) OR
|
||||||
(team_members.user_id = 1 AND team_namespaces.right = 1) OR
|
(team_members.user_id = 1 AND team_namespaces.right = 1) OR
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ func (n *Namespace) checkRight(s *xorm.Session, a web.Auth, rights ...Right) (bo
|
||||||
// User conditions
|
// User conditions
|
||||||
// If the namespace was shared directly with the user and the user has the right
|
// If the namespace was shared directly with the user and the user has the right
|
||||||
conds = append(conds, builder.And(
|
conds = append(conds, builder.And(
|
||||||
builder.Eq{"users_namespace.user_id": a.GetID()},
|
builder.Eq{"users_namespaces.user_id": a.GetID()},
|
||||||
builder.Eq{"users_namespace.right": r},
|
builder.Eq{"users_namespaces.right": r},
|
||||||
))
|
))
|
||||||
|
|
||||||
// Team rights
|
// Team rights
|
||||||
|
@ -120,7 +120,7 @@ func (n *Namespace) checkRight(s *xorm.Session, a web.Auth, rights ...Right) (bo
|
||||||
Select("*").
|
Select("*").
|
||||||
Table("namespaces").
|
Table("namespaces").
|
||||||
// User stuff
|
// User stuff
|
||||||
Join("LEFT", "users_namespace", "users_namespace.namespace_id = namespaces.id").
|
Join("LEFT", "users_namespaces", "users_namespaces.namespace_id = namespaces.id").
|
||||||
// Teams stuff
|
// Teams stuff
|
||||||
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_id").
|
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_id").
|
||||||
Join("LEFT", "team_members", "team_members.team_id = team_namespaces.team_id").
|
Join("LEFT", "team_members", "team_members.team_id = team_namespaces.team_id").
|
||||||
|
|
|
@ -49,7 +49,7 @@ type NamespaceUser struct {
|
||||||
|
|
||||||
// TableName is the table name for NamespaceUser
|
// TableName is the table name for NamespaceUser
|
||||||
func (NamespaceUser) TableName() string {
|
func (NamespaceUser) TableName() string {
|
||||||
return "users_namespace"
|
return "users_namespaces"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new namespace <-> user relation
|
// Create creates a new namespace <-> user relation
|
||||||
|
@ -189,8 +189,8 @@ func (nu *NamespaceUser) ReadAll(s *xorm.Session, a web.Auth, search string, pag
|
||||||
limit, start := getLimitFromPageIndex(page, perPage)
|
limit, start := getLimitFromPageIndex(page, perPage)
|
||||||
|
|
||||||
query := s.
|
query := s.
|
||||||
Join("INNER", "users_namespace", "user_id = users.id").
|
Join("INNER", "users_namespaces", "user_id = users.id").
|
||||||
Where("users_namespace.namespace_id = ?", nu.NamespaceID).
|
Where("users_namespaces.namespace_id = ?", nu.NamespaceID).
|
||||||
Where("users.username LIKE ?", "%"+search+"%")
|
Where("users.username LIKE ?", "%"+search+"%")
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
query = query.Limit(limit, start)
|
query = query.Limit(limit, start)
|
||||||
|
@ -206,8 +206,8 @@ func (nu *NamespaceUser) ReadAll(s *xorm.Session, a web.Auth, search string, pag
|
||||||
}
|
}
|
||||||
|
|
||||||
numberOfTotalItems, err = s.
|
numberOfTotalItems, err = s.
|
||||||
Join("INNER", "users_namespace", "user_id = users.id").
|
Join("INNER", "users_namespaces", "user_id = users.id").
|
||||||
Where("users_namespace.namespace_id = ?", nu.NamespaceID).
|
Where("users_namespaces.namespace_id = ?", nu.NamespaceID).
|
||||||
Where("users.username LIKE ?", "%"+search+"%").
|
Where("users.username LIKE ?", "%"+search+"%").
|
||||||
Count(&UserWithRight{})
|
Count(&UserWithRight{})
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ func TestNamespaceUser_Create(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
if !tt.wantErr {
|
if !tt.wantErr {
|
||||||
db.AssertExists(t, "users_namespace", map[string]interface{}{
|
db.AssertExists(t, "users_namespaces", map[string]interface{}{
|
||||||
"user_id": tt.fields.UserID,
|
"user_id": tt.fields.UserID,
|
||||||
"namespace_id": tt.fields.NamespaceID,
|
"namespace_id": tt.fields.NamespaceID,
|
||||||
}, false)
|
}, false)
|
||||||
|
@ -326,7 +326,7 @@ func TestNamespaceUser_Update(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
if !tt.wantErr {
|
if !tt.wantErr {
|
||||||
db.AssertExists(t, "users_namespace", map[string]interface{}{
|
db.AssertExists(t, "users_namespaces", map[string]interface{}{
|
||||||
"user_id": tt.fields.UserID,
|
"user_id": tt.fields.UserID,
|
||||||
"namespace_id": tt.fields.NamespaceID,
|
"namespace_id": tt.fields.NamespaceID,
|
||||||
"right": tt.fields.Right,
|
"right": tt.fields.Right,
|
||||||
|
@ -407,7 +407,7 @@ func TestNamespaceUser_Delete(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
if !tt.wantErr {
|
if !tt.wantErr {
|
||||||
db.AssertMissing(t, "users_namespace", map[string]interface{}{
|
db.AssertMissing(t, "users_namespaces", map[string]interface{}{
|
||||||
"user_id": tt.fields.UserID,
|
"user_id": tt.fields.UserID,
|
||||||
"namespace_id": tt.fields.NamespaceID,
|
"namespace_id": tt.fields.NamespaceID,
|
||||||
})
|
})
|
||||||
|
|
|
@ -186,7 +186,7 @@ func getSubscriberCondForEntity(entityType SubscriptionEntityType, entityID int6
|
||||||
builder.And(
|
builder.And(
|
||||||
builder.Eq{"entity_id": builder.
|
builder.Eq{"entity_id": builder.
|
||||||
Select("namespace_id").
|
Select("namespace_id").
|
||||||
From("list").
|
From("lists").
|
||||||
Where(builder.Eq{"id": entityID}),
|
Where(builder.Eq{"id": entityID}),
|
||||||
},
|
},
|
||||||
builder.Eq{"entity_type": SubscriptionEntityNamespace},
|
builder.Eq{"entity_type": SubscriptionEntityNamespace},
|
||||||
|
@ -203,8 +203,8 @@ func getSubscriberCondForEntity(entityType SubscriptionEntityType, entityID int6
|
||||||
builder.And(
|
builder.And(
|
||||||
builder.Eq{"entity_id": builder.
|
builder.Eq{"entity_id": builder.
|
||||||
Select("namespace_id").
|
Select("namespace_id").
|
||||||
From("list").
|
From("lists").
|
||||||
Join("INNER", "tasks", "list.id = tasks.list_id").
|
Join("INNER", "tasks", "lists.id = tasks.list_id").
|
||||||
Where(builder.Eq{"tasks.id": entityID}),
|
Where(builder.Eq{"tasks.id": entityID}),
|
||||||
},
|
},
|
||||||
builder.Eq{"entity_type": SubscriptionEntityNamespace},
|
builder.Eq{"entity_type": SubscriptionEntityNamespace},
|
||||||
|
|
|
@ -397,7 +397,7 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(labelFilters) > 0 {
|
if len(labelFilters) > 0 {
|
||||||
filters = append(filters, getFilterCondForSeparateTable("label_task", opts.filterConcat, labelFilters))
|
filters = append(filters, getFilterCondForSeparateTable("label_tasks", opts.filterConcat, labelFilters))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(namespaceFilters) > 0 {
|
if len(namespaceFilters) > 0 {
|
||||||
|
@ -413,7 +413,7 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO
|
||||||
"list_id",
|
"list_id",
|
||||||
builder.
|
builder.
|
||||||
Select("id").
|
Select("id").
|
||||||
From("list").
|
From("lists").
|
||||||
Where(filtercond),
|
Where(filtercond),
|
||||||
)
|
)
|
||||||
filters = append(filters, cond)
|
filters = append(filters, cond)
|
||||||
|
|
|
@ -39,10 +39,10 @@ func SetupTests() {
|
||||||
|
|
||||||
err = db.InitTestFixtures(
|
err = db.InitTestFixtures(
|
||||||
"files",
|
"files",
|
||||||
"label_task",
|
"label_tasks",
|
||||||
"labels",
|
"labels",
|
||||||
"link_sharing",
|
"link_shares",
|
||||||
"list",
|
"lists",
|
||||||
"namespaces",
|
"namespaces",
|
||||||
"task_assignees",
|
"task_assignees",
|
||||||
"task_attachments",
|
"task_attachments",
|
||||||
|
@ -50,13 +50,13 @@ func SetupTests() {
|
||||||
"task_relations",
|
"task_relations",
|
||||||
"task_reminders",
|
"task_reminders",
|
||||||
"tasks",
|
"tasks",
|
||||||
"team_list",
|
"team_lists",
|
||||||
"team_members",
|
"team_members",
|
||||||
"team_namespaces",
|
"team_namespaces",
|
||||||
"teams",
|
"teams",
|
||||||
"users",
|
"users",
|
||||||
"users_list",
|
"users_lists",
|
||||||
"users_namespace",
|
"users_namespaces",
|
||||||
"buckets",
|
"buckets",
|
||||||
"saved_filters",
|
"saved_filters",
|
||||||
"subscriptions",
|
"subscriptions",
|
||||||
|
|
|
@ -44,16 +44,16 @@ func ListUsersFromList(s *xorm.Session, l *List, search string) (users []*user.U
|
||||||
n.owner_id as nOwner,
|
n.owner_id as nOwner,
|
||||||
tm.user_id as tnUID,
|
tm.user_id as tnUID,
|
||||||
tm2.user_id as tlUID`).
|
tm2.user_id as tlUID`).
|
||||||
Table("list").
|
Table("lists").
|
||||||
Alias("l").
|
Alias("l").
|
||||||
// User stuff
|
// User stuff
|
||||||
Join("LEFT", []string{"users_namespace", "un"}, "un.namespace_id = l.namespace_id").
|
Join("LEFT", []string{"users_namespaces", "un"}, "un.namespace_id = l.namespace_id").
|
||||||
Join("LEFT", []string{"users_list", "ul"}, "ul.list_id = l.id").
|
Join("LEFT", []string{"users_lists", "ul"}, "ul.list_id = l.id").
|
||||||
Join("LEFT", []string{"namespaces", "n"}, "n.id = l.namespace_id").
|
Join("LEFT", []string{"namespaces", "n"}, "n.id = l.namespace_id").
|
||||||
// Team stuff
|
// Team stuff
|
||||||
Join("LEFT", []string{"team_namespaces", "tn"}, " l.namespace_id = tn.namespace_id").
|
Join("LEFT", []string{"team_namespaces", "tn"}, " l.namespace_id = tn.namespace_id").
|
||||||
Join("LEFT", []string{"team_members", "tm"}, "tm.team_id = tn.team_id").
|
Join("LEFT", []string{"team_members", "tm"}, "tm.team_id = tn.team_id").
|
||||||
Join("LEFT", []string{"team_list", "tl"}, "l.id = tl.list_id").
|
Join("LEFT", []string{"team_lists", "tl"}, "l.id = tl.list_id").
|
||||||
Join("LEFT", []string{"team_members", "tm2"}, "tm2.team_id = tl.team_id").
|
Join("LEFT", []string{"team_members", "tm2"}, "tm2.team_id = tl.team_id").
|
||||||
// The actual condition
|
// The actual condition
|
||||||
Where(
|
Where(
|
||||||
|
|
|
@ -117,7 +117,7 @@ func TestInsertFromStructure(t *testing.T) {
|
||||||
"title": testStructure[0].Namespace.Title,
|
"title": testStructure[0].Namespace.Title,
|
||||||
"description": testStructure[0].Namespace.Description,
|
"description": testStructure[0].Namespace.Description,
|
||||||
}, false)
|
}, false)
|
||||||
db.AssertExists(t, "list", map[string]interface{}{
|
db.AssertExists(t, "lists", map[string]interface{}{
|
||||||
"title": testStructure[0].Lists[0].Title,
|
"title": testStructure[0].Lists[0].Title,
|
||||||
"description": testStructure[0].Lists[0].Description,
|
"description": testStructure[0].Lists[0].Description,
|
||||||
}, false)
|
}, false)
|
||||||
|
|
Loading…
Reference in a new issue