Browse Source

fix stuff and add editIssue mutation.

master
Gisle Aune 4 years ago
parent
commit
d0ffe1677e
  1. 2
      database/drivers/mysqldriver/issetasks.go
  2. 1
      graph/resolvers/issue.resolvers.go
  3. 2
      graph/resolvers/issueitem.resolvers.go
  4. 2
      graph/resolvers/log.resolvers.go
  5. 60
      graph/resolvers/mutation.resolvers.go
  6. 2
      graph/resolvers/query.resolvers.go
  7. 16
      graph/schema/issue.gql
  8. 2
      graph/schema/mutation.gql

2
database/drivers/mysqldriver/issetasks.go

@ -31,7 +31,7 @@ func (r *issueTaskRepository) Find(ctx context.Context, id string) (*models.Issu
}
func (r *issueTaskRepository) List(ctx context.Context, filter models.IssueTaskFilter) ([]*models.IssueTask, error) {
q := sq.Select("*").From("issue_task")
q := sq.Select("*").From("issue_task").OrderBy("created_time")
if filter.ActivityIDs != nil {
q = q.Where(sq.Eq{"activity_id": filter.ActivityIDs})
}

1
graph/resolvers/issue.resolvers.go

@ -5,6 +5,7 @@ package resolvers
import (
"context"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/graphutil"
"git.aiterp.net/stufflog/server/graph/loaders"

2
graph/resolvers/issueitem.resolvers.go

@ -5,9 +5,9 @@ package resolvers
import (
"context"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/models"
)

2
graph/resolvers/log.resolvers.go

@ -5,9 +5,9 @@ package resolvers
import (
"context"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/models"
)

60
graph/resolvers/mutation.resolvers.go

@ -6,12 +6,12 @@ package resolvers
import (
"context"
"errors"
"git.aiterp.net/stufflog/server/graph/loaders"
"log"
"sort"
"time"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/internal/generate"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
@ -301,6 +301,63 @@ func (r *mutationResolver) CreateIssue(ctx context.Context, input graphcore.Issu
return issue, nil
}
func (r *mutationResolver) EditIssue(ctx context.Context, input graphcore.IssueEditInput) (*models.Issue, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
return nil, slerrors.PermissionDenied
}
issue, err := loaders.IssueLoaderFromContext(ctx).Load(input.IssueID)
if err != nil {
return nil, err
}
if perm, err := r.Auth.IssuePermission(ctx, *issue); err != nil || !perm.CanManageOwnIssue() {
return nil, slerrors.PermissionDenied
}
if input.SetAssignee != nil {
if *input.SetAssignee != "" {
assignee, err := loaders.UserLoaderFromContext(ctx).Load(*input.SetAssignee)
if err != nil {
return nil, err
}
if perm, err := r.Auth.IssuePermission(ctx, *issue); err != nil || !perm.CanManageOwnIssue() {
return nil, slerrors.Forbidden("Cannot assign to user who cannot manage their own issues.")
}
issue.AssigneeID = assignee.ID
} else {
issue.AssigneeID = ""
}
}
if input.SetName != nil {
issue.Name = *input.SetName
}
if input.SetTitle != nil {
issue.Name = *input.SetTitle
}
if input.SetDueTime != nil {
issue.DueTime = *input.SetDueTime
}
if input.SetStatusName != nil {
status, err := r.Database.ProjectStatuses().Find(ctx, issue.ProjectID, *input.SetStatusName)
if err != nil {
return nil, err
}
issue.StatusName = status.Name
issue.StatusStage = status.Stage
}
err = r.Database.Issues().Save(ctx, *issue)
if err != nil {
return nil, err
}
return issue, nil
}
func (r *mutationResolver) CreateIssueTask(ctx context.Context, input graphcore.IssueTaskCreateInput) (*models.IssueTask, error) {
user := r.Auth.UserFromContext(ctx)
if user == nil {
@ -336,6 +393,7 @@ func (r *mutationResolver) CreateIssueTask(ctx context.Context, input graphcore.
StatusName: status.Name,
Name: input.Name,
Description: input.Description,
EstimatedTime: input.EstimatedTime,
PointsMultiplier: 1.0,
}
if input.EstimatedUnits != nil && activity.Countable && !activity.UnitIsTimeSpent {

2
graph/resolvers/query.resolvers.go

@ -6,9 +6,9 @@ package resolvers
import (
"context"
"errors"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/internal/slerrors"
"git.aiterp.net/stufflog/server/models"
)

16
graph/schema/issue.gql

@ -64,4 +64,20 @@ input IssueCreateInput {
dueTime: Time
"Optional title to use instead of the name when not in a list."
title: String
}
input IssueEditInput {
"The issue to edit."
issueId: String!
"Set the user this issue is assigned to."
setAssignee: String
"Set the status name for the issue."
setStatusName: String
"Rename the issue."
setName: String
"Set the issue title."
setTitle: String
"Change the due time."
setDueTime: Time
}

2
graph/schema/mutation.gql

@ -18,6 +18,8 @@ type Mutation {
# ISSUE
"Create a new issue."
createIssue(input: IssueCreateInput!): Issue!
"Edit an issue."
editIssue(input: IssueEditInput!): Issue!
# ISSUE TASK
"Create a new issue task."
createIssueTask(input: IssueTaskCreateInput!): IssueTask!

Loading…
Cancel
Save