Private Issues: Issue-level access control and DB queries #418

Closed
opened 2026-02-23 16:08:50 +00:00 by nphilipp · 2 comments
Member

Story

As a user of Forgejo,
I want to view and list public and private issues via the REST API,
so I can work with private issues using the web API.

Acceptance Criteria

  • An Issue.CanAccess() method exists which determines if the current user is allowed to access an issue. For public issues (IsPrivate == false), this always returns true, for private issues it will check if the current user created the issue or owns the repository (directly or via organization) and return true in this case, otherwise false.
  • A function (name and place TBD) exists to Forgejo can query the DB for private issues, filtering them for the perspective of the current user (see above).
    • The functions Issues() and IssueIDs() (of models/issues/issues_search.go) as well as their building blocks (and their users elsewhere) are updated so they can deal with both public and private issues.
    • These functions are adapted so they can appropriately filter out private issues depending on the user.

Background

Various to be implemented functions will need know if a certain issue should be shown to the user. Some might need to decide this on a one by one basis (e.g. viewing one issue), some might need to query private issues and filter in bulk.

Beware, .OriginalAuthorID must be considered, see models/issues/issue.go:

// IsPoster returns true if given user by ID is the poster.
func (issue *Issue) IsPoster(uid int64) bool {
	return issue.OriginalAuthorID == 0 && issue.PosterID == uid
}
# Story As a user of Forgejo, I want to view and list public and private issues via the REST API, so I can work with private issues using the web API. # Acceptance Criteria - [x] An `Issue.CanAccess()` method exists which determines if the current user is allowed to access an issue. For public issues (`IsPrivate == false`), this always returns true, for private issues it will check if the current user created the issue or owns the repository (directly or via organization) and return true in this case, otherwise false. - [x] _~~A function (name and place TBD) exists to~~_ Forgejo can query the DB for private issues, filtering them for the perspective of the current user (see above). - [x] The functions `Issues()` and `IssueIDs()` (of `models/issues/issues_search.go`) as well as their building blocks _~~(and their users elsewhere)~~_ are updated so they can deal with both public and private issues. - [x] These functions are adapted so they can appropriately filter out private issues depending on the user. # Background Various _~~to be implemented~~_ functions will need know if a certain issue should be shown to the user. Some might need to decide this on a one by one basis (e.g. viewing one issue), some might need to query private issues and filter in bulk. Beware, `.OriginalAuthorID` must be considered, see `models/issues/issue.go`: ``` // IsPoster returns true if given user by ID is the poster. func (issue *Issue) IsPoster(uid int64) bool { return issue.OriginalAuthorID == 0 && issue.PosterID == uid } ```
nphilipp added this to the Sprint 15 project 2026-02-23 16:08:51 +00:00
nphilipp changed title from Private Issues: Issue-level access control to Private Issues: Issue-level access control and DB queries 2026-02-23 16:12:28 +00:00
Author
Member

Issue.CanAccess() and corresponding tests are in my feature branch, in “Add Issue.CanAccess()”.

`Issue.CanAccess()` and corresponding tests are in [my feature branch](https://codeberg.org/nilsph/forgejo/src/branch/forgejo--private-issues), in “Add Issue.CanAccess()”.
Author
Member

In my feature branch, the functions Issues() and IssueIDs() from models/issues/issue_search.go can …

  • … process private issues via setting IssuesOptions.IsPrivate. Implemented in Make Issues(), IssueIDs() cope with private issues.
  • … constrain the result sets to those private issues a user (set in IssueOptions.DoerID) is allowed to see. Implemented in Allow filtering private issues in searches.
In [my feature branch](https://codeberg.org/nilsph/forgejo/src/branch/forgejo--private-issues), the functions `Issues()` and `IssueIDs()` from `models/issues/issue_search.go` can … - … process private issues via setting `IssuesOptions.IsPrivate`. Implemented in `Make Issues(), IssueIDs() cope with private issues`. - … constrain the result sets to those private issues a user (set in `IssueOptions.DoerID`) is allowed to see. Implemented in `Allow filtering private issues in searches`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
forge/forge#418
No description provided.