feat(caldav): Import Labels from caldav categories
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
3f7409aa56
commit
1b3aa1b5a4
|
@ -176,7 +176,7 @@ func (l *Label) ReadAll(s *xorm.Session, a web.Auth, search string, page int, pe
|
|||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /labels/{id} [get]
|
||||
func (l *Label) ReadOne(s *xorm.Session, a web.Auth) (err error) {
|
||||
label, err := getLabelSimple(s, l)
|
||||
label, err := getLabelByIDSimple(s, l.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -192,10 +192,10 @@ func (l *Label) ReadOne(s *xorm.Session, a web.Auth) (err error) {
|
|||
}
|
||||
|
||||
func getLabelByIDSimple(s *xorm.Session, labelID int64) (*Label, error) {
|
||||
return getLabelSimple(s, &Label{ID: labelID})
|
||||
return GetLabelSimple(s, &Label{ID: labelID})
|
||||
}
|
||||
|
||||
func getLabelSimple(s *xorm.Session, l *Label) (*Label, error) {
|
||||
func GetLabelSimple(s *xorm.Session, l *Label) (*Label, error) {
|
||||
exists, err := s.Get(l)
|
||||
if err != nil {
|
||||
return l, err
|
||||
|
|
|
@ -198,21 +198,6 @@ func TestLabel_ReadOne(t *testing.T) {
|
|||
},
|
||||
auth: &user.User{ID: 1},
|
||||
},
|
||||
{
|
||||
name: "Get label by Title",
|
||||
fields: fields{
|
||||
Title: "Label #2",
|
||||
},
|
||||
want: &Label{
|
||||
ID: 2,
|
||||
Title: "Label #2",
|
||||
CreatedByID: 1,
|
||||
CreatedBy: user1,
|
||||
Created: testCreatedTime,
|
||||
Updated: testUpdatedTime,
|
||||
},
|
||||
auth: &user.User{ID: 1},
|
||||
},
|
||||
{
|
||||
name: "Get nonexistant label",
|
||||
fields: fields{
|
||||
|
@ -274,11 +259,9 @@ func TestLabel_ReadOne(t *testing.T) {
|
|||
|
||||
s := db.NewSession()
|
||||
|
||||
if l.ID != 0 {
|
||||
allowed, _, _ := l.CanRead(s, tt.auth)
|
||||
if !allowed && !tt.wantForbidden {
|
||||
t.Errorf("Label.CanRead() forbidden, want %v", tt.wantForbidden)
|
||||
}
|
||||
allowed, _, _ := l.CanRead(s, tt.auth)
|
||||
if !allowed && !tt.wantForbidden {
|
||||
t.Errorf("Label.CanRead() forbidden, want %v", tt.wantForbidden)
|
||||
}
|
||||
err := l.ReadOne(s, tt.auth)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
|
|
@ -390,16 +390,18 @@ func (vcls *VikunjaCaldavListStorage) DeleteResource(rpath string) error {
|
|||
func persistLabels(s *xorm.Session, a web.Auth, task *models.Task, labels []*models.Label) (err error) {
|
||||
// Find or create Labels by title
|
||||
for _, label := range labels {
|
||||
err = label.ReadOne(s, a)
|
||||
l, err := models.GetLabelSimple(s, &models.Label{Title: label.Title})
|
||||
if err != nil {
|
||||
if models.IsErrLabelDoesNotExist(err) {
|
||||
err = label.Create(s, a)
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
*label = *l
|
||||
}
|
||||
}
|
||||
// Insert LabelTask relation
|
||||
|
|
Loading…
Reference in New Issue