Compare commits

...

3 Commits

Author SHA1 Message Date
kolaente 003cf85d05
Add basic crud rights
Signed-off-by: kolaente <k@knt.li>
2020-02-16 22:38:22 +01:00
kolaente d3a5e62cdc
Implement basic crudable functions for task comments
Signed-off-by: kolaente <k@knt.li>
2020-02-16 22:35:14 +01:00
kolaente 4995270ee1
Start adding task comments
Signed-off-by: kolaente <k@knt.li>
2020-02-16 22:25:41 +01:00
3 changed files with 120 additions and 1 deletions

View File

@ -0,0 +1,40 @@
// Copyright 2020 Vikunja and contriubtors. All rights reserved.
//
// This file is part of Vikunja.
//
// Vikunja is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vikunja 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vikunja. If not, see <https://www.gnu.org/licenses/>.
package models
import "code.vikunja.io/web"
func (tc *TaskComment) CanWrite(a web.Auth) (bool, error) {
t := Task{ID: tc.ID}
return t.CanWrite(a)
}
func (tc *TaskComment) CanDelete(a web.Auth) (bool, error) {
t := Task{ID: tc.ID}
return t.CanWrite(a)
}
func (tc *TaskComment) CanUpdate(a web.Auth) (bool, error) {
t := Task{ID: tc.ID}
return t.CanWrite(a)
}
func (tc *TaskComment) CanCreate(a web.Auth) (bool, error) {
t := Task{ID: tc.ID}
return t.CanWrite(a)
}

View File

@ -0,0 +1,79 @@
// Copyright 2020 Vikunja and contriubtors. All rights reserved.
//
// This file is part of Vikunja.
//
// Vikunja is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vikunja 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vikunja. If not, see <https://www.gnu.org/licenses/>.
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
)
type TaskComment struct {
ID int64 `xorm:"autoincr pk unique not null" json:"id"`
Comment string `xorm:"text not null" json:"comment"`
AuthorID int64 `xorm:"not null" json:"-"`
Author *user.User `xorm:"extends" json:"author"`
TaskID int64 `xorm:"not null" json:"-" param:"task"`
Created timeutil.TimeStamp `xorm:"created"`
Updated timeutil.TimeStamp `xorm:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`
}
func (tc *TaskComment) TableName() string {
return "task_comments"
}
// Create creates a new task comment
func (tc *TaskComment) Create(a web.Auth) (err error) {
tc.AuthorID = a.GetID()
_, err = x.Insert(tc)
return
}
// Delete removes a task comment
func (tc *TaskComment) Delete() (err error) {
_, err = x.ID(tc.ID).NoAutoCondition().Delete(tc)
return
}
// Update updates a task text by its ID
func (tc *TaskComment) Update() (err error) {
_, err = x.ID(tc.ID).Cols("comment").Update(tc)
return
}
// ReadAll returns all comments for a task
func (tc *TaskComment) ReadAll(auth web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error) {
comments := []*TaskComment{}
err = x.
Where("task_id = ? AND comment like ?", tc.TaskID, "%"+search+"%").
Join("LEFT", "users", "users.id = task_comments.author_id").
Limit(getLimitFromPageIndex(page, perPage)).
Find(&comments)
if err != nil {
return
}
numberOfTotalItems, err = x.
Where("task_id = ? AND comment like ?", tc.TaskID, "%"+search+"%").
Count(&comments)
return comments, len(comments), numberOfTotalItems, err
}

View File

@ -64,7 +64,7 @@ func (t *Task) canDoTask(a web.Auth) (bool, error) {
return false, err
}
// A user can do a task if he has write acces to its list
// A user can do a task if it has write acces to its list
l := &List{ID: lI.ListID}
return l.CanWrite(a)
}