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
|
||||
}
|
||||
|
||||
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 {
|
||||
schemeBeans := []interface{}{}
|
||||
schemeBeans = append(schemeBeans, models.GetTables()...)
|
||||
|
|
|
@ -252,7 +252,7 @@ const ErrCodeListIsArchived = 3008
|
|||
|
||||
// HTTPError holds the http error description
|
||||
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
|
||||
}
|
||||
|
||||
cond := builder.In("label_task.task_id",
|
||||
cond := builder.In("label_tasks.task_id",
|
||||
builder.
|
||||
Select("id").
|
||||
From("tasks").
|
||||
|
@ -82,9 +82,9 @@ func (l *Label) hasAccessToLabel(s *xorm.Session, a web.Auth) (has bool, maxRigh
|
|||
|
||||
ll := &LabelTask{}
|
||||
has, err = s.Table("labels").
|
||||
Select("label_task.*").
|
||||
Join("LEFT", "label_task", "label_task.label_id = labels.id").
|
||||
Where("label_task.label_id is not null OR labels.created_by_id = ?", u.ID).
|
||||
Select("label_tasks.*").
|
||||
Join("LEFT", "label_tasks", "label_tasks.label_id = labels.id").
|
||||
Where("label_tasks.label_id is not null OR labels.created_by_id = ?", u.ID).
|
||||
Or(cond).
|
||||
And("labels.id = ?", l.ID).
|
||||
Exist(ll)
|
||||
|
|
|
@ -44,7 +44,7 @@ type LabelTask struct {
|
|||
|
||||
// TableName makes a pretty table name
|
||||
func (LabelTask) TableName() string {
|
||||
return "label_task"
|
||||
return "label_tasks"
|
||||
}
|
||||
|
||||
// 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.
|
||||
// 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.
|
||||
var groupBy = "labels.id,label_task.task_id"
|
||||
var selectStmt = "labels.*, label_task.task_id"
|
||||
var groupBy = "labels.id,label_tasks.task_id"
|
||||
var selectStmt = "labels.*, label_tasks.task_id"
|
||||
if opts.GroupByLabelIDsOnly {
|
||||
groupBy = "labels.id"
|
||||
selectStmt = "labels.*"
|
||||
|
@ -168,12 +168,12 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab
|
|||
|
||||
// Get all labels associated with these tasks
|
||||
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 {
|
||||
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 {
|
||||
cond = builder.And(builder.In("label_task.task_id",
|
||||
cond = builder.And(builder.In("label_tasks.task_id",
|
||||
builder.
|
||||
Select("id").
|
||||
From("tasks").
|
||||
|
@ -207,7 +207,7 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab
|
|||
|
||||
query := s.Table("labels").
|
||||
Select(selectStmt).
|
||||
Join("LEFT", "label_task", "label_task.label_id = labels.id").
|
||||
Join("LEFT", "label_tasks", "label_tasks.label_id = labels.id").
|
||||
Where(cond).
|
||||
GroupBy(groupBy).
|
||||
OrderBy("labels.id ASC")
|
||||
|
@ -249,7 +249,7 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab
|
|||
// Get the total number of entries
|
||||
totalEntries, err = s.Table("labels").
|
||||
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).
|
||||
And("labels.title LIKE ?", "%"+opts.Search+"%").
|
||||
Count(&Label{})
|
||||
|
|
|
@ -215,11 +215,11 @@ func TestLabelTask_Create(t *testing.T) {
|
|||
CRUDable: tt.fields.CRUDable,
|
||||
Rights: tt.fields.Rights,
|
||||
}
|
||||
allowed, _ := l.CanCreate(s, tt.args.a)
|
||||
allowed, err := l.CanCreate(s, tt.args.a)
|
||||
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 {
|
||||
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())
|
||||
}
|
||||
if !tt.wantErr {
|
||||
db.AssertExists(t, "label_task", map[string]interface{}{
|
||||
db.AssertExists(t, "label_tasks", map[string]interface{}{
|
||||
"id": l.ID,
|
||||
"task_id": l.TaskID,
|
||||
"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())
|
||||
}
|
||||
if !tt.wantForbidden {
|
||||
db.AssertMissing(t, "label_task", map[string]interface{}{
|
||||
db.AssertMissing(t, "label_tasks", map[string]interface{}{
|
||||
"label_id": l.LabelID,
|
||||
"task_id": l.TaskID,
|
||||
})
|
||||
|
|
|
@ -65,7 +65,7 @@ type LinkSharing struct {
|
|||
|
||||
// TableName holds the table name
|
||||
func (LinkSharing) TableName() string {
|
||||
return "link_sharing"
|
||||
return "link_shares"
|
||||
}
|
||||
|
||||
// GetID returns the ID of the links sharing object
|
||||
|
|
|
@ -80,6 +80,11 @@ type List struct {
|
|||
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
|
||||
type ListBackgroundType struct {
|
||||
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.
|
||||
var list List
|
||||
exists, err := s.
|
||||
Select("list.*").
|
||||
Select("lists.*").
|
||||
Table(List{}).
|
||||
Join("INNER", "tasks", "list.id = tasks.list_id").
|
||||
Join("INNER", "tasks", "lists.id = tasks.list_id").
|
||||
Where("tasks.id = ?", taskID).
|
||||
Get(&list)
|
||||
if err != nil {
|
||||
|
@ -336,14 +341,14 @@ func getUserListsStatement(userID int64) *builder.Builder {
|
|||
|
||||
return builder.Dialect(dialect).
|
||||
Select("l.*").
|
||||
From("list", "l").
|
||||
From("lists", "l").
|
||||
Join("INNER", "namespaces n", "l.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_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", "users_list ul", "ul.list_id = l.id").
|
||||
Join("LEFT", "users_namespace un", "un.namespace_id = l.namespace_id").
|
||||
Join("LEFT", "users_lists ul", "ul.list_id = l.id").
|
||||
Join("LEFT", "users_namespaces un", "un.namespace_id = l.namespace_id").
|
||||
Where(builder.Or(
|
||||
builder.Eq{"tm.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)
|
||||
|
||||
var filterCond builder.Cond
|
||||
vals := strings.Split(opts.search, ",")
|
||||
ids := []int64{}
|
||||
if opts.search != "" {
|
||||
vals := strings.Split(opts.search, ",")
|
||||
for _, val := range vals {
|
||||
v, err := strconv.ParseInt(val, 10, 64)
|
||||
if err != nil {
|
||||
|
@ -383,6 +389,7 @@ func getRawListsForUser(s *xorm.Session, opts *listOptions) (lists []*List, resu
|
|||
}
|
||||
ids = append(ids, v)
|
||||
}
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
filterCond = builder.In("l.id", ids)
|
||||
|
@ -486,9 +493,9 @@ func (l *List) CheckIsArchived(s *xorm.Session) (err error) {
|
|||
|
||||
nl := &NamespaceList{}
|
||||
exists, err := s.
|
||||
Table("list").
|
||||
Join("LEFT", "namespaces", "list.namespace_id = namespaces.id").
|
||||
Where("list.id = ? AND (list.is_archived = true OR namespaces.is_archived = true)", l.ID).
|
||||
Table("lists").
|
||||
Join("LEFT", "namespaces", "lists.namespace_id = namespaces.id").
|
||||
Where("lists.id = ? AND (lists.is_archived = true OR namespaces.is_archived = true)", l.ID).
|
||||
Get(nl)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -222,16 +222,16 @@ func (l *List) checkRight(s *xorm.Session, a web.Auth, rights ...Right) (bool, i
|
|||
r := &allListRights{}
|
||||
var maxRight = 0
|
||||
exists, err := s.
|
||||
Table("list").
|
||||
Table("lists").
|
||||
Alias("l").
|
||||
// User stuff
|
||||
Join("LEFT", []string{"users_namespace", "un"}, "un.namespace_id = l.namespace_id").
|
||||
Join("LEFT", []string{"users_list", "ul"}, "ul.list_id = l.id").
|
||||
Join("LEFT", []string{"users_namespaces", "un"}, "un.namespace_id = l.namespace_id").
|
||||
Join("LEFT", []string{"users_lists", "ul"}, "ul.list_id = l.id").
|
||||
Join("LEFT", []string{"namespaces", "n"}, "n.id = l.namespace_id").
|
||||
// Team stuff
|
||||
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_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").
|
||||
// The actual condition
|
||||
Where(builder.And(
|
||||
|
|
|
@ -47,7 +47,7 @@ type TeamList struct {
|
|||
|
||||
// TableName makes beautiful table names
|
||||
func (TeamList) TableName() string {
|
||||
return "team_list"
|
||||
return "team_lists"
|
||||
}
|
||||
|
||||
// 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{}
|
||||
query := s.
|
||||
Table("teams").
|
||||
Join("INNER", "team_list", "team_id = teams.id").
|
||||
Where("team_list.list_id = ?", tl.ListID).
|
||||
Join("INNER", "team_lists", "team_id = teams.id").
|
||||
Where("team_lists.list_id = ?", tl.ListID).
|
||||
Where("teams.name LIKE ?", "%"+search+"%")
|
||||
if limit > 0 {
|
||||
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.
|
||||
Table("teams").
|
||||
Join("INNER", "team_list", "team_id = teams.id").
|
||||
Where("team_list.list_id = ?", tl.ListID).
|
||||
Join("INNER", "team_lists", "team_id = teams.id").
|
||||
Where("team_lists.list_id = ?", tl.ListID).
|
||||
Where("teams.name LIKE ?", "%"+search+"%").
|
||||
Count(&TeamWithRight{})
|
||||
if err != nil {
|
||||
|
|
|
@ -99,7 +99,7 @@ func TestTeamList_Create(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertExists(t, "team_list", map[string]interface{}{
|
||||
db.AssertExists(t, "team_lists", map[string]interface{}{
|
||||
"team_id": 1,
|
||||
"list_id": 1,
|
||||
"right": RightAdmin,
|
||||
|
@ -171,7 +171,7 @@ func TestTeamList_Delete(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertMissing(t, "team_list", map[string]interface{}{
|
||||
db.AssertMissing(t, "team_lists", map[string]interface{}{
|
||||
"team_id": 1,
|
||||
"list_id": 3,
|
||||
})
|
||||
|
@ -279,7 +279,7 @@ func TestTeamList_Update(t *testing.T) {
|
|||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
if !tt.wantErr {
|
||||
db.AssertExists(t, "team_list", map[string]interface{}{
|
||||
db.AssertExists(t, "team_lists", map[string]interface{}{
|
||||
"list_id": tt.fields.ListID,
|
||||
"team_id": tt.fields.TeamID,
|
||||
"right": tt.fields.Right,
|
||||
|
|
|
@ -45,7 +45,7 @@ func TestList_CreateOrUpdate(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertExists(t, "list", map[string]interface{}{
|
||||
db.AssertExists(t, "lists", map[string]interface{}{
|
||||
"id": list.ID,
|
||||
"title": list.Title,
|
||||
"description": list.Description,
|
||||
|
@ -105,7 +105,7 @@ func TestList_CreateOrUpdate(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertExists(t, "list", map[string]interface{}{
|
||||
db.AssertExists(t, "lists", map[string]interface{}{
|
||||
"id": list.ID,
|
||||
"title": list.Title,
|
||||
"description": list.Description,
|
||||
|
@ -129,7 +129,7 @@ func TestList_CreateOrUpdate(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertExists(t, "list", map[string]interface{}{
|
||||
db.AssertExists(t, "lists", map[string]interface{}{
|
||||
"id": list.ID,
|
||||
"title": list.Title,
|
||||
"description": list.Description,
|
||||
|
@ -176,7 +176,7 @@ func TestList_Delete(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
db.AssertMissing(t, "list", map[string]interface{}{
|
||||
db.AssertMissing(t, "lists", map[string]interface{}{
|
||||
"id": 1,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ type ListUser struct {
|
|||
|
||||
// TableName is the table name for ListUser
|
||||
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
|
||||
|
@ -202,8 +202,8 @@ func (lu *ListUser) ReadAll(s *xorm.Session, a web.Auth, search string, page int
|
|||
// Get all users
|
||||
all := []*UserWithRight{}
|
||||
query := s.
|
||||
Join("INNER", "users_list", "user_id = users.id").
|
||||
Where("users_list.list_id = ?", lu.ListID).
|
||||
Join("INNER", "users_lists", "user_id = users.id").
|
||||
Where("users_lists.list_id = ?", lu.ListID).
|
||||
Where("users.username LIKE ?", "%"+search+"%")
|
||||
if limit > 0 {
|
||||
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.
|
||||
Join("INNER", "users_list", "user_id = users.id").
|
||||
Where("users_list.list_id = ?", lu.ListID).
|
||||
Join("INNER", "users_lists", "user_id = users.id").
|
||||
Where("users_lists.list_id = ?", lu.ListID).
|
||||
Where("users.username LIKE ?", "%"+search+"%").
|
||||
Count(&UserWithRight{})
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ func TestListUser_Create(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
if !tt.wantErr {
|
||||
db.AssertExists(t, "users_list", map[string]interface{}{
|
||||
db.AssertExists(t, "users_lists", map[string]interface{}{
|
||||
"user_id": ul.UserID,
|
||||
"list_id": tt.fields.ListID,
|
||||
}, false)
|
||||
|
@ -323,7 +323,7 @@ func TestListUser_Update(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
if !tt.wantErr {
|
||||
db.AssertExists(t, "users_list", map[string]interface{}{
|
||||
db.AssertExists(t, "users_lists", map[string]interface{}{
|
||||
"list_id": tt.fields.ListID,
|
||||
"user_id": lu.UserID,
|
||||
"right": tt.fields.Right,
|
||||
|
@ -405,7 +405,7 @@ func TestListUser_Delete(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
if !tt.wantErr {
|
||||
db.AssertMissing(t, "users_list", map[string]interface{}{
|
||||
db.AssertMissing(t, "users_lists", map[string]interface{}{
|
||||
"user_id": tt.fields.UserID,
|
||||
"list_id": tt.fields.ListID,
|
||||
})
|
||||
|
|
|
@ -250,10 +250,10 @@ func getNamespacesWithLists(s *xorm.Session, namespaces *map[int64]*NamespaceWit
|
|||
Table("namespaces").
|
||||
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_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).
|
||||
Or("namespaces.owner_id = ?", userID).
|
||||
Or("users_namespace.user_id = ?", userID).
|
||||
Or("users_namespaces.user_id = ?", userID).
|
||||
GroupBy("namespaces.id").
|
||||
Where(filterCond).
|
||||
Where(isArchivedCond)
|
||||
|
@ -269,10 +269,10 @@ func getNamespacesWithLists(s *xorm.Session, namespaces *map[int64]*NamespaceWit
|
|||
Table("namespaces").
|
||||
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_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).
|
||||
Or("namespaces.owner_id = ?", userID).
|
||||
Or("users_namespace.user_id = ?", userID).
|
||||
Or("users_namespaces.user_id = ?", userID).
|
||||
And("namespaces.is_archived = false").
|
||||
GroupBy("namespaces.id").
|
||||
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)
|
||||
individualLists := []*List{}
|
||||
iListQuery := s.Select("l.*").
|
||||
Table("list").
|
||||
Table("lists").
|
||||
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{"users_list", "ul"}, "ul.list_id = l.id").
|
||||
Join("LEFT", []string{"users_lists", "ul"}, "ul.list_id = l.id").
|
||||
Where(builder.And(
|
||||
builder.Eq{"tm.user_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
|
||||
var favoriteCount int64
|
||||
favoriteCount, err = s.
|
||||
Join("INNER", "list", "tasks.list_id = list.id").
|
||||
Join("INNER", "namespaces", "list.namespace_id = namespaces.id").
|
||||
Join("INNER", "lists", "tasks.list_id = lists.id").
|
||||
Join("INNER", "namespaces", "lists.namespace_id = namespaces.id").
|
||||
Where(builder.And(builder.Eq{"tasks.is_favorite": true}, builder.In("namespaces.id", namespaceIDs))).
|
||||
Count(&Task{})
|
||||
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:
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
@ -97,8 +97,8 @@ func (n *Namespace) checkRight(s *xorm.Session, a web.Auth, rights ...Right) (bo
|
|||
// User conditions
|
||||
// If the namespace was shared directly with the user and the user has the right
|
||||
conds = append(conds, builder.And(
|
||||
builder.Eq{"users_namespace.user_id": a.GetID()},
|
||||
builder.Eq{"users_namespace.right": r},
|
||||
builder.Eq{"users_namespaces.user_id": a.GetID()},
|
||||
builder.Eq{"users_namespaces.right": r},
|
||||
))
|
||||
|
||||
// Team rights
|
||||
|
@ -120,7 +120,7 @@ func (n *Namespace) checkRight(s *xorm.Session, a web.Auth, rights ...Right) (bo
|
|||
Select("*").
|
||||
Table("namespaces").
|
||||
// User stuff
|
||||
Join("LEFT", "users_namespace", "users_namespace.namespace_id = namespaces.id").
|
||||
Join("LEFT", "users_namespaces", "users_namespaces.namespace_id = namespaces.id").
|
||||
// Teams stuff
|
||||
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_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
|
||||
func (NamespaceUser) TableName() string {
|
||||
return "users_namespace"
|
||||
return "users_namespaces"
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
query := s.
|
||||
Join("INNER", "users_namespace", "user_id = users.id").
|
||||
Where("users_namespace.namespace_id = ?", nu.NamespaceID).
|
||||
Join("INNER", "users_namespaces", "user_id = users.id").
|
||||
Where("users_namespaces.namespace_id = ?", nu.NamespaceID).
|
||||
Where("users.username LIKE ?", "%"+search+"%")
|
||||
if limit > 0 {
|
||||
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.
|
||||
Join("INNER", "users_namespace", "user_id = users.id").
|
||||
Where("users_namespace.namespace_id = ?", nu.NamespaceID).
|
||||
Join("INNER", "users_namespaces", "user_id = users.id").
|
||||
Where("users_namespaces.namespace_id = ?", nu.NamespaceID).
|
||||
Where("users.username LIKE ?", "%"+search+"%").
|
||||
Count(&UserWithRight{})
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ func TestNamespaceUser_Create(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
if !tt.wantErr {
|
||||
db.AssertExists(t, "users_namespace", map[string]interface{}{
|
||||
db.AssertExists(t, "users_namespaces", map[string]interface{}{
|
||||
"user_id": tt.fields.UserID,
|
||||
"namespace_id": tt.fields.NamespaceID,
|
||||
}, false)
|
||||
|
@ -326,7 +326,7 @@ func TestNamespaceUser_Update(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
if !tt.wantErr {
|
||||
db.AssertExists(t, "users_namespace", map[string]interface{}{
|
||||
db.AssertExists(t, "users_namespaces", map[string]interface{}{
|
||||
"user_id": tt.fields.UserID,
|
||||
"namespace_id": tt.fields.NamespaceID,
|
||||
"right": tt.fields.Right,
|
||||
|
@ -407,7 +407,7 @@ func TestNamespaceUser_Delete(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
if !tt.wantErr {
|
||||
db.AssertMissing(t, "users_namespace", map[string]interface{}{
|
||||
db.AssertMissing(t, "users_namespaces", map[string]interface{}{
|
||||
"user_id": tt.fields.UserID,
|
||||
"namespace_id": tt.fields.NamespaceID,
|
||||
})
|
||||
|
|
|
@ -186,7 +186,7 @@ func getSubscriberCondForEntity(entityType SubscriptionEntityType, entityID int6
|
|||
builder.And(
|
||||
builder.Eq{"entity_id": builder.
|
||||
Select("namespace_id").
|
||||
From("list").
|
||||
From("lists").
|
||||
Where(builder.Eq{"id": entityID}),
|
||||
},
|
||||
builder.Eq{"entity_type": SubscriptionEntityNamespace},
|
||||
|
@ -203,8 +203,8 @@ func getSubscriberCondForEntity(entityType SubscriptionEntityType, entityID int6
|
|||
builder.And(
|
||||
builder.Eq{"entity_id": builder.
|
||||
Select("namespace_id").
|
||||
From("list").
|
||||
Join("INNER", "tasks", "list.id = tasks.list_id").
|
||||
From("lists").
|
||||
Join("INNER", "tasks", "lists.id = tasks.list_id").
|
||||
Where(builder.Eq{"tasks.id": entityID}),
|
||||
},
|
||||
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 {
|
||||
filters = append(filters, getFilterCondForSeparateTable("label_task", opts.filterConcat, labelFilters))
|
||||
filters = append(filters, getFilterCondForSeparateTable("label_tasks", opts.filterConcat, labelFilters))
|
||||
}
|
||||
|
||||
if len(namespaceFilters) > 0 {
|
||||
|
@ -413,7 +413,7 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO
|
|||
"list_id",
|
||||
builder.
|
||||
Select("id").
|
||||
From("list").
|
||||
From("lists").
|
||||
Where(filtercond),
|
||||
)
|
||||
filters = append(filters, cond)
|
||||
|
|
|
@ -39,10 +39,10 @@ func SetupTests() {
|
|||
|
||||
err = db.InitTestFixtures(
|
||||
"files",
|
||||
"label_task",
|
||||
"label_tasks",
|
||||
"labels",
|
||||
"link_sharing",
|
||||
"list",
|
||||
"link_shares",
|
||||
"lists",
|
||||
"namespaces",
|
||||
"task_assignees",
|
||||
"task_attachments",
|
||||
|
@ -50,13 +50,13 @@ func SetupTests() {
|
|||
"task_relations",
|
||||
"task_reminders",
|
||||
"tasks",
|
||||
"team_list",
|
||||
"team_lists",
|
||||
"team_members",
|
||||
"team_namespaces",
|
||||
"teams",
|
||||
"users",
|
||||
"users_list",
|
||||
"users_namespace",
|
||||
"users_lists",
|
||||
"users_namespaces",
|
||||
"buckets",
|
||||
"saved_filters",
|
||||
"subscriptions",
|
||||
|
|
|
@ -44,16 +44,16 @@ func ListUsersFromList(s *xorm.Session, l *List, search string) (users []*user.U
|
|||
n.owner_id as nOwner,
|
||||
tm.user_id as tnUID,
|
||||
tm2.user_id as tlUID`).
|
||||
Table("list").
|
||||
Table("lists").
|
||||
Alias("l").
|
||||
// User stuff
|
||||
Join("LEFT", []string{"users_namespace", "un"}, "un.namespace_id = l.namespace_id").
|
||||
Join("LEFT", []string{"users_list", "ul"}, "ul.list_id = l.id").
|
||||
Join("LEFT", []string{"users_namespaces", "un"}, "un.namespace_id = l.namespace_id").
|
||||
Join("LEFT", []string{"users_lists", "ul"}, "ul.list_id = l.id").
|
||||
Join("LEFT", []string{"namespaces", "n"}, "n.id = l.namespace_id").
|
||||
// Team stuff
|
||||
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_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").
|
||||
// The actual condition
|
||||
Where(
|
||||
|
|
|
@ -117,7 +117,7 @@ func TestInsertFromStructure(t *testing.T) {
|
|||
"title": testStructure[0].Namespace.Title,
|
||||
"description": testStructure[0].Namespace.Description,
|
||||
}, false)
|
||||
db.AssertExists(t, "list", map[string]interface{}{
|
||||
db.AssertExists(t, "lists", map[string]interface{}{
|
||||
"title": testStructure[0].Lists[0].Title,
|
||||
"description": testStructure[0].Lists[0].Description,
|
||||
}, false)
|
||||
|
|
Loading…
Reference in a new issue