Update xorm to use the new import path (#133)
Fix ineffassign Fix getting all labels including the ones not associated to a task Signed-off-by: kolaente <k@knt.li> Fix logging sql queries Signed-off-by: kolaente <k@knt.li> Start fixing getting all labels Update xormigrate Update xorm to use the new import path Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/133
This commit is contained in:
@ -19,7 +19,7 @@ package models
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
"code.vikunja.io/web"
|
||||
"github.com/go-xorm/builder"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// CanUpdate checks if a user can update a label
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"code.vikunja.io/api/pkg/timeutil"
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
"code.vikunja.io/web"
|
||||
"github.com/go-xorm/builder"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// LabelTask represents a relation between a label and a task
|
||||
@ -149,15 +149,6 @@ type LabelByTaskIDsOptions struct {
|
||||
// Helper function to get all labels for a set of tasks
|
||||
// Used when getting all labels for one task as well when getting all lables
|
||||
func getLabelsByTaskIDs(opts *LabelByTaskIDsOptions) (ls []*labelWithTaskID, resultCount int, totalEntries int64, err error) {
|
||||
// Include unused labels. Needed to be able to show a list of all unused labels a user
|
||||
// has access to.
|
||||
var uidOrNil interface{}
|
||||
var requestOrNil interface{}
|
||||
if opts.GetUnusedLabels {
|
||||
uidOrNil = opts.User.ID
|
||||
requestOrNil = "label_task.label_id != null OR labels.created_by_id = ?"
|
||||
}
|
||||
|
||||
// We still need the task ID when we want to get all labels for a task, but because of this, we get the same label
|
||||
// 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.
|
||||
@ -169,11 +160,15 @@ func getLabelsByTaskIDs(opts *LabelByTaskIDsOptions) (ls []*labelWithTaskID, res
|
||||
|
||||
// Get all labels associated with these tasks
|
||||
var labels []*labelWithTaskID
|
||||
cond := builder.And(builder.In("label_task.task_id", opts.TaskIDs), builder.NotNull{"label_task.label_id"})
|
||||
if opts.GetUnusedLabels {
|
||||
cond = builder.Or(cond, builder.Eq{"labels.created_by_id": opts.User.ID})
|
||||
}
|
||||
|
||||
err = x.Table("labels").
|
||||
Select("labels.*, label_task.task_id").
|
||||
Join("LEFT", "label_task", "label_task.label_id = labels.id").
|
||||
Where(requestOrNil, uidOrNil).
|
||||
Or(builder.In("label_task.task_id", opts.TaskIDs)).
|
||||
Where(cond).
|
||||
And("labels.title LIKE ?", "%"+opts.Search+"%").
|
||||
GroupBy(groupBy).
|
||||
Limit(getLimitFromPageIndex(opts.Page, opts.PerPage)).
|
||||
@ -204,10 +199,13 @@ func getLabelsByTaskIDs(opts *LabelByTaskIDsOptions) (ls []*labelWithTaskID, res
|
||||
}
|
||||
|
||||
// Get the total number of entries
|
||||
condCount := builder.And(builder.In("label_task.task_id", opts.TaskIDs), builder.NotNull{"label_task.label_id"})
|
||||
if opts.GetUnusedLabels {
|
||||
condCount = builder.Or(cond, builder.Eq{"labels.created_by_id": opts.User.ID})
|
||||
}
|
||||
totalEntries, err = x.Table("labels").
|
||||
Join("LEFT", "label_task", "label_task.label_id = labels.id").
|
||||
Where(requestOrNil, uidOrNil).
|
||||
Or(builder.In("label_task.task_id", opts.TaskIDs)).
|
||||
Where(condCount).
|
||||
And("labels.title LIKE ?", "%"+opts.Search+"%").
|
||||
GroupBy(groupBy).
|
||||
Count(&Label{})
|
||||
|
@ -17,6 +17,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/timeutil"
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
"gopkg.in/d4l3k/messagediff.v1"
|
||||
@ -119,6 +120,7 @@ func TestLabel_ReadAll(t *testing.T) {
|
||||
CRUDable: tt.fields.CRUDable,
|
||||
Rights: tt.fields.Rights,
|
||||
}
|
||||
db.LoadAndAssertFixtures(t)
|
||||
gotLs, _, _, err := l.ReadAll(tt.args.a, tt.args.search, tt.args.page, 0)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Label.ReadAll() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
@ -19,7 +19,7 @@ package models
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
"code.vikunja.io/web"
|
||||
"github.com/go-xorm/builder"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// CanWrite return whether the user can write on that list or not
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
_ "github.com/go-sql-driver/mysql" // Because.
|
||||
"github.com/go-xorm/xorm"
|
||||
"xorm.io/xorm"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3" // Because.
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/web"
|
||||
"github.com/go-xorm/builder"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// CanWrite checks if a user has write access to a namespace
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"code.vikunja.io/api/pkg/timeutil"
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
"code.vikunja.io/web"
|
||||
"github.com/go-xorm/builder"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// Team holds a team object
|
||||
|
@ -19,7 +19,7 @@ package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
"github.com/go-xorm/builder"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// ListUIDs hold all kinds of user IDs from accounts who have somehow access to a list
|
||||
|
Reference in New Issue
Block a user