fix: reset id before creating

This commit is contained in:
kolaente 2024-09-17 10:46:14 +02:00
parent 410ff28b71
commit c252c8f0cd
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
14 changed files with 18 additions and 4 deletions

View File

@ -306,6 +306,7 @@ func (b *Bucket) Create(s *xorm.Session, a web.Auth) (err error) {
}
b.CreatedByID = b.CreatedBy.ID
b.ID = 0
_, err = s.Insert(b)
if err != nil {
return

View File

@ -97,7 +97,7 @@ func (lt *LabelTask) Create(s *xorm.Session, auth web.Auth) (err error) {
return ErrLabelIsAlreadyOnTask{lt.LabelID, lt.TaskID}
}
// Insert it
lt.ID = 0
_, err = s.Insert(lt)
if err != nil {
return err
@ -386,7 +386,10 @@ func (t *Task) UpdateTaskLabels(s *xorm.Session, creator web.Auth, labels []*Lab
}
// Insert it
_, err = s.Insert(&LabelTask{LabelID: l.ID, TaskID: t.ID})
_, err = s.Insert(&LabelTask{
LabelID: l.ID,
TaskID: t.ID,
})
if err != nil {
return err
}

View File

@ -154,6 +154,7 @@ func (share *LinkSharing) Create(s *xorm.Session, a web.Auth) (err error) {
share.SharingType = SharingTypeWithoutPassword
}
share.ID = 0
_, err = s.Insert(share)
share.Password = ""
share.SharedBy, _ = user.GetFromAuth(a)

View File

@ -104,6 +104,7 @@ func (tl *TeamProject) Create(s *xorm.Session, a web.Auth) (err error) {
}
// Insert the new team
tl.ID = 0
_, err = s.Insert(tl)
if err != nil {
return err

View File

@ -110,7 +110,7 @@ func (lu *ProjectUser) Create(s *xorm.Session, a web.Auth) (err error) {
return ErrUserAlreadyHasAccess{UserID: lu.UserID, ProjectID: lu.ProjectID}
}
// Insert user <-> project relation
lu.ID = 0
_, err = s.Insert(lu)
if err != nil {
return err

View File

@ -263,6 +263,7 @@ func (pv *ProjectView) Create(s *xorm.Session, a web.Auth) (err error) {
}
func createProjectView(s *xorm.Session, p *ProjectView, a web.Auth, createBacklogBucket bool, addExistingTasksToView bool) (err error) {
p.ID = 0
_, err = s.Insert(p)
if err != nil {
return

View File

@ -186,6 +186,7 @@ func (r *Reaction) Create(s *xorm.Session, a web.Auth) (err error) {
return
}
r.ID = 0
_, err = s.Insert(r)
return
}

View File

@ -121,6 +121,7 @@ func (sf *SavedFilter) toProject() *Project {
// @Router /filters [put]
func (sf *SavedFilter) Create(s *xorm.Session, auth web.Auth) (err error) {
sf.OwnerID = auth.GetID()
sf.ID = 0
_, err = s.Insert(sf)
if err != nil {
return

View File

@ -147,6 +147,7 @@ func (sb *Subscription) TableName() string {
func (sb *Subscription) Create(s *xorm.Session, auth web.Auth) (err error) {
// Rights method already does the validation of the entity type, so we don't need to do that here
sb.ID = 0
sb.UserID = auth.GetID()
sub, err := GetSubscriptionForUser(s, sb.EntityType, sb.EntityID, auth)

View File

@ -66,6 +66,7 @@ func (tc *TaskComment) TableName() string {
// @Router /tasks/{taskID}/comments [put]
func (tc *TaskComment) Create(s *xorm.Session, a web.Auth) (err error) {
tc.ID = 0
tc.Created = time.Time{}
tc.Updated = time.Time{}

View File

@ -230,6 +230,7 @@ func (rel *TaskRelation) Create(s *xorm.Session, a web.Auth) error {
return err
}
rel.CreatedByID = rel.CreatedBy.ID
rel.ID = 0
// Build up the other relation (see the comment above for explanation)
otherRelation := &TaskRelation{

View File

@ -62,7 +62,7 @@ func (tm *TeamMember) Create(s *xorm.Session, a web.Auth) (err error) {
return ErrUserIsMemberOfTeam{tm.TeamID, tm.UserID}
}
// Insert the user
tm.ID = 0
_, err = s.Insert(tm)
if err != nil {
return err

View File

@ -236,6 +236,7 @@ func (t *Team) CreateNewTeam(s *xorm.Session, a web.Auth, firstUserShouldBeAdmin
return ErrTeamNameCannotBeEmpty{}
}
t.ID = 0
t.CreatedByID = doer.ID
t.CreatedBy = doer

View File

@ -127,6 +127,7 @@ func (w *Webhook) Create(s *xorm.Session, a web.Auth) (err error) {
}
w.CreatedByID = a.GetID()
w.ID = 0
_, err = s.Insert(w)
if err != nil {
return err