forgejo/models
Jason Song 6844258c67
Clarify Actions resources ownership (#31724)
Fix #31707.

Also related to #31715.

Some Actions resources could has different types of ownership. It could
be:

- global: all repos and orgs/users can use it.
- org/user level: only the org/user can use it.
- repo level: only the repo can use it.

There are two ways to distinguish org/user level from repo level:
1. `{owner_id: 1, repo_id: 2}` for repo level, and `{owner_id: 1,
repo_id: 0}` for org level.
2. `{owner_id: 0, repo_id: 2}` for repo level, and `{owner_id: 1,
repo_id: 0}` for org level.

The first way seems more reasonable, but it may not be true. The point
is that although a resource, like a runner, belongs to a repo (it can be
used by the repo), the runner doesn't belong to the repo's org (other
repos in the same org cannot use the runner). So, the second method
makes more sense.

And the first way is not user-friendly to query, we must set the repo id
to zero to avoid wrong results.

So, #31715 should be right. And the most simple way to fix #31707 is
just:

```diff
-	shared.GetRegistrationToken(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID)
+	shared.GetRegistrationToken(ctx, 0, ctx.Repo.Repository.ID)
```

However, it is quite intuitive to set both owner id and repo id since
the repo belongs to the owner. So I prefer to be compatible with it. If
we get both owner id and repo id not zero when creating or finding, it's
very clear that the caller want one with repo level, but set owner id
accidentally. So it's OK to accept it but fix the owner id to zero.

(cherry picked from commit a33e74d40d356e8f628ac06a131cb203a3609dec)
2024-08-04 18:24:10 +02:00
..
actions Clarify Actions resources ownership (#31724) 2024-08-04 18:24:10 +02:00
activities Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
admin Next round of db.DefaultContext refactor (#27089) 2023-09-16 14:39:12 +00:00
asymkey Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
auth Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
avatars Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
db Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
dbfs Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
fixtures feat(cli): add --keep-labels flag to forgejo actions register (#4610) 2024-07-22 07:33:45 +00:00
forgefed enhance test & fix reviews 2024-05-14 08:24:31 +02:00
forgejo/semver Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
forgejo_migrations feat(quota): Humble beginnings of a quota engine 2024-08-02 11:10:34 +02:00
git Fix Null Pointer error for CommitStatusesHideActionsURL (#31731) 2024-08-04 10:14:34 +02:00
issues Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
migrations Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
organization Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
packages Arch packages implementation (#4785) 2024-08-04 06:16:29 +00:00
perm Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
project Fix the display of project type for deleted projects (#31732) 2024-08-04 10:14:34 +02:00
pull [GITEA] GetScheduledMergeByPullID may involve a system user 2024-02-05 16:09:41 +01:00
quota feat(quota): Humble beginnings of a quota engine 2024-08-02 11:10:34 +02:00
repo Make GetRepositoryByName more safer (#31712) 2024-08-04 10:14:34 +02:00
secret Clarify Actions resources ownership (#31724) 2024-08-04 18:24:10 +02:00
shared/types Refactor locale&string&template related code (#29165) 2024-02-16 15:20:52 +01:00
system Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
unit Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
unittest Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
user Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
webhook Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
error.go Add merge style fast-forward-only (#28954) 2024-02-14 17:19:19 +01:00
fixture_generation.go Replace more db.DefaultContext (#27628) 2023-10-15 17:46:06 +02:00
fixture_test.go Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
main_test.go Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
org.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
org_team.go Remove GetByBean method because sometimes it's danger when query condition parameter is zero and also introduce new generic methods (#28220) 2023-12-07 15:27:36 +08:00
org_team_test.go Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
org_test.go Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
repo.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
repo_test.go Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
repo_transfer.go chore: use errors.New to replace fmt.Errorf with no parameters will much better (#30621) 2024-04-28 15:39:00 +02:00
repo_transfer_test.go Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00