Fixed tag removal issue.

This commit is contained in:
Asaf Gartner 2022-01-31 10:22:25 +02:00
parent 378d6eb836
commit 92d6a31aa9
3 changed files with 39 additions and 38 deletions

View File

@ -798,45 +798,43 @@ func HandleSnippetForInternedMessage(ctx context.Context, dbConn db.ConnOrTx, in
var desiredTags []int
var allTags []int
if len(messageTags) > 0 {
// Fetch projects so we know what tags the user can apply to their snippet.
projects, err := hmndata.FetchProjects(ctx, tx, interned.HMNUser, hmndata.ProjectsQuery{
OwnerIDs: []int{interned.HMNUser.ID},
})
if err != nil {
return oops.New(err, "failed to look up user projects")
}
// Fetch projects so we know what tags the user can apply to their snippet.
projects, err := hmndata.FetchProjects(ctx, tx, interned.HMNUser, hmndata.ProjectsQuery{
OwnerIDs: []int{interned.HMNUser.ID},
})
if err != nil {
return oops.New(err, "failed to look up user projects")
}
projectIDs := make([]int, len(projects))
for i, p := range projects {
projectIDs[i] = p.Project.ID
}
projectIDs := make([]int, len(projects))
for i, p := range projects {
projectIDs[i] = p.Project.ID
}
type tagsRow struct {
Tag models.Tag `db:"tags"`
}
iUserTags, err := db.Query(ctx, tx, tagsRow{},
`
SELECT $columns
FROM
tags
JOIN handmade_project AS project ON project.tag = tags.id
WHERE
project.id = ANY ($1)
`,
projectIDs,
)
if err != nil {
return oops.New(err, "failed to fetch tags for user projects")
}
type tagsRow struct {
Tag models.Tag `db:"tags"`
}
iUserTags, err := db.Query(ctx, tx, tagsRow{},
`
SELECT $columns
FROM
tags
JOIN handmade_project AS project ON project.tag = tags.id
WHERE
project.id = ANY ($1)
`,
projectIDs,
)
if err != nil {
return oops.New(err, "failed to fetch tags for user projects")
}
for _, itag := range iUserTags {
tag := itag.(*tagsRow).Tag
for _, messageTag := range messageTags {
allTags = append(allTags, tag.ID)
if strings.EqualFold(tag.Text, messageTag) {
desiredTags = append(desiredTags, tag.ID)
}
for _, itag := range iUserTags {
tag := itag.(*tagsRow).Tag
allTags = append(allTags, tag.ID)
for _, messageTag := range messageTags {
if strings.EqualFold(tag.Text, messageTag) {
desiredTags = append(desiredTags, tag.ID)
}
}
}

View File

@ -463,7 +463,7 @@ func SetProjectTag(
IncludeHidden: true,
})
if err != nil {
return nil, err
return nil, oops.New(err, "Failed to fetch project")
}
var resultTag *models.Tag

View File

@ -760,7 +760,10 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
return oops.New(err, "Failed to update project")
}
hmndata.SetProjectTag(ctx, tx, payload.ProjectID, payload.Tag)
_, err = hmndata.SetProjectTag(ctx, tx, payload.ProjectID, payload.Tag)
if err != nil {
return err
}
if user.IsStaff {
_, err = tx.Exec(ctx,