Files
MokoGitea-Fork/models/issues/issue_priority.go
T
Jonathan Miller 55c2f81c58
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
Generic: Repo Health / Site Health (pull_request) Has been cancelled
Branch Policy Check / Verify merge target (pull_request) Has been cancelled
PR RC Release / Build RC Release (pull_request) Has been cancelled
Generic: Repo Health / Access control (pull_request) Has been cancelled
Branch Cleanup / Delete merged branch (pull_request) Has been cancelled
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || 'development' }}) (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled
feat(issues): org-level priority field with customizable levels (#509)
Add org-level issue priority definitions that appear in the issue
sidebar. Each priority has a name, color, sort order, and optional
default flag. Follows the same architecture as custom statuses (#502).

Includes:
- IssuePriorityDef model with CRUD operations
- Migration v348 adding issue_priority_def table + priority_id on issues
- Org settings UI for managing priorities
- Issue sidebar dropdown for selecting priority

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-06-06 11:52:44 -05:00

92 lines
3.2 KiB
Go

// Copyright 2026 Moko Consulting <hello@mokoconsulting.tech>
// SPDX-License-Identifier: GPL-3.0-or-later
package issues
import (
"context"
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/models/db"
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/timeutil"
)
func init() {
db.RegisterModel(new(IssuePriorityDef))
}
// IssuePriorityDef defines a custom issue priority at the org level.
type IssuePriorityDef struct {
ID int64 `xorm:"pk autoincr"`
OrgID int64 `xorm:"INDEX NOT NULL DEFAULT 0 'org_id'"`
Name string `xorm:"NOT NULL"`
Color string `xorm:"VARCHAR(7)"`
Description string `xorm:"TEXT"`
SortOrder int `xorm:"NOT NULL DEFAULT 0 'sort_order'"`
IsDefault bool `xorm:"NOT NULL DEFAULT false 'is_default'"`
IsActive bool `xorm:"NOT NULL DEFAULT true 'is_active'"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED 'created_unix'"`
UpdatedUnix timeutil.TimeStamp `xorm:"UPDATED 'updated_unix'"`
}
func (IssuePriorityDef) TableName() string {
return "issue_priority_def"
}
// GetIssuePriorityDefsByOrg returns active priority definitions for an org.
func GetIssuePriorityDefsByOrg(ctx context.Context, orgID int64) ([]*IssuePriorityDef, error) {
defs := make([]*IssuePriorityDef, 0, 10)
return defs, db.GetEngine(ctx).
Where("org_id = ? AND is_active = ?", orgID, true).
OrderBy("sort_order ASC, id ASC").
Find(&defs)
}
// GetAllIssuePriorityDefsByOrg returns all priority definitions (including inactive).
func GetAllIssuePriorityDefsByOrg(ctx context.Context, orgID int64) ([]*IssuePriorityDef, error) {
defs := make([]*IssuePriorityDef, 0, 10)
return defs, db.GetEngine(ctx).
Where("org_id = ?", orgID).
OrderBy("sort_order ASC, id ASC").
Find(&defs)
}
// GetIssuePriorityDefByID returns a single priority definition.
func GetIssuePriorityDefByID(ctx context.Context, id int64) (*IssuePriorityDef, error) {
def := new(IssuePriorityDef)
has, err := db.GetEngine(ctx).ID(id).Get(def)
if err != nil {
return nil, err
}
if !has {
return nil, db.ErrNotExist{Resource: "IssuePriorityDef", ID: id}
}
return def, nil
}
// CreateIssuePriorityDef creates a new priority definition.
func CreateIssuePriorityDef(ctx context.Context, def *IssuePriorityDef) error {
_, err := db.GetEngine(ctx).Insert(def)
return err
}
// UpdateIssuePriorityDef updates a priority definition.
func UpdateIssuePriorityDef(ctx context.Context, def *IssuePriorityDef) error {
_, err := db.GetEngine(ctx).ID(def.ID).AllCols().Update(def)
return err
}
// DeleteIssuePriorityDef deletes a priority definition and clears references on issues.
func DeleteIssuePriorityDef(ctx context.Context, id int64) error {
if _, err := db.GetEngine(ctx).Exec("UPDATE issue SET priority_id = 0 WHERE priority_id = ?", id); err != nil {
return err
}
_, err := db.GetEngine(ctx).ID(id).Delete(new(IssuePriorityDef))
return err
}
// SetIssuePriorityID updates the priority_id on an issue.
func SetIssuePriorityID(ctx context.Context, issueID, priorityID int64) error {
_, err := db.GetEngine(ctx).Exec("UPDATE issue SET priority_id = ? WHERE id = ?", priorityID, issueID)
return err
}