forked from longtao.wu/droboticflow
49 lines
2.3 KiB
Go
49 lines
2.3 KiB
Go
package domain
|
|
|
|
// SupplierAcceptanceAuthorization is independent of production project grants.
|
|
// Its absence grants no shared acceptance access.
|
|
type SupplierAcceptanceAuthorization struct {
|
|
ID string `json:"id" bson:"_id"`
|
|
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
|
SupplierID string `json:"supplierId" bson:"supplierId"`
|
|
Enabled bool `json:"enabled" bson:"enabled"`
|
|
Version int `json:"version" bson:"version"`
|
|
UpdatedAt string `json:"updatedAt,omitempty" bson:"updatedAt"`
|
|
History []SupplierAcceptanceAuthorizationChange `json:"history,omitempty" bson:"history"`
|
|
}
|
|
|
|
type SupplierAcceptanceAuthorizationChange struct {
|
|
Enabled bool `json:"enabled" bson:"enabled"`
|
|
ActorID string `json:"actorId" bson:"actorId"`
|
|
At string `json:"at" bson:"at"`
|
|
}
|
|
|
|
// AcceptanceClaimAccess survives revocation only for this assignee and claim.
|
|
// A new assignment, stage, or review round must obtain a new authorization.
|
|
type AcceptanceClaimAccess struct {
|
|
UserID string `json:"userId" bson:"userId"`
|
|
SupplierID string `json:"supplierId" bson:"supplierId"`
|
|
GrantVersion int `json:"grantVersion" bson:"grantVersion"`
|
|
StageID string `json:"stageId" bson:"stageId"`
|
|
Round int `json:"round" bson:"round"`
|
|
ClaimedAt string `json:"claimedAt" bson:"claimedAt"`
|
|
}
|
|
|
|
func (v *AcceptanceClaimAccess) Matches(item HumanItemRecord, user UserRecord) bool {
|
|
return v != nil && v.UserID == user.ID && v.SupplierID == user.SupplierID &&
|
|
item.AssignedUserID == user.ID && v.StageID == item.CurrentStageID &&
|
|
v.Round == item.ReviewRound && v.ClaimedAt != "" && v.ClaimedAt == item.ClaimedAt
|
|
}
|
|
|
|
func SharedAcceptanceItem(item HumanItemRecord, batch *HumanBatchRecord) bool {
|
|
if item.PluginID != "annotation-qa" || item.ProcessingScope == "internal" || batch == nil || batch.ProcessingScope == "internal" {
|
|
return false
|
|
}
|
|
for _, stage := range batch.Stages {
|
|
if stage.ID == item.CurrentStageID {
|
|
return stage.Kind == HumanStageAcceptance && stage.RequiredRole == string(UserRoleAcceptanceReviewer)
|
|
}
|
|
}
|
|
return false
|
|
}
|