|
@ -6,12 +6,12 @@ package resolvers |
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
"errors" |
|
|
"errors" |
|
|
"git.aiterp.net/stufflog/server/graph/loaders" |
|
|
|
|
|
"log" |
|
|
"log" |
|
|
"sort" |
|
|
"sort" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
"git.aiterp.net/stufflog/server/graph/graphcore" |
|
|
"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/generate" |
|
|
"git.aiterp.net/stufflog/server/internal/slerrors" |
|
|
"git.aiterp.net/stufflog/server/internal/slerrors" |
|
|
"git.aiterp.net/stufflog/server/models" |
|
|
"git.aiterp.net/stufflog/server/models" |
|
@ -301,6 +301,63 @@ func (r *mutationResolver) CreateIssue(ctx context.Context, input graphcore.Issu |
|
|
return issue, nil |
|
|
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) { |
|
|
func (r *mutationResolver) CreateIssueTask(ctx context.Context, input graphcore.IssueTaskCreateInput) (*models.IssueTask, error) { |
|
|
user := r.Auth.UserFromContext(ctx) |
|
|
user := r.Auth.UserFromContext(ctx) |
|
|
if user == nil { |
|
|
if user == nil { |
|
@ -336,6 +393,7 @@ func (r *mutationResolver) CreateIssueTask(ctx context.Context, input graphcore. |
|
|
StatusName: status.Name, |
|
|
StatusName: status.Name, |
|
|
Name: input.Name, |
|
|
Name: input.Name, |
|
|
Description: input.Description, |
|
|
Description: input.Description, |
|
|
|
|
|
EstimatedTime: input.EstimatedTime, |
|
|
PointsMultiplier: 1.0, |
|
|
PointsMultiplier: 1.0, |
|
|
} |
|
|
} |
|
|
if input.EstimatedUnits != nil && activity.Countable && !activity.UnitIsTimeSpent { |
|
|
if input.EstimatedUnits != nil && activity.Countable && !activity.UnitIsTimeSpent { |
|
|