mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +00:00
Move keys to models/asymkey (#17917)
* Move keys to models/keys * Rename models/keys -> models/asymkey * change the missed package name * Fix package alias * Fix test * Fix docs * Fix test * Fix test * merge
This commit is contained in:
parent
0a9fcf63a4
commit
3ca5dc7e32
75 changed files with 1001 additions and 887 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
|
@ -34,9 +35,9 @@ func ServNoCommand(ctx *context.PrivateContext) {
|
|||
}
|
||||
results := private.KeyAndOwner{}
|
||||
|
||||
key, err := models.GetPublicKeyByID(keyID)
|
||||
key, err := asymkey_model.GetPublicKeyByID(keyID)
|
||||
if err != nil {
|
||||
if models.IsErrKeyNotExist(err) {
|
||||
if asymkey_model.IsErrKeyNotExist(err) {
|
||||
ctx.JSON(http.StatusUnauthorized, private.Response{
|
||||
Err: fmt.Sprintf("Cannot find key: %d", keyID),
|
||||
})
|
||||
|
@ -50,7 +51,7 @@ func ServNoCommand(ctx *context.PrivateContext) {
|
|||
}
|
||||
results.Key = key
|
||||
|
||||
if key.Type == models.KeyTypeUser || key.Type == models.KeyTypePrincipal {
|
||||
if key.Type == asymkey_model.KeyTypeUser || key.Type == asymkey_model.KeyTypePrincipal {
|
||||
user, err := user_model.GetUserByID(key.OwnerID)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
|
@ -184,9 +185,9 @@ func ServCommand(ctx *context.PrivateContext) {
|
|||
}
|
||||
|
||||
// Get the Public Key represented by the keyID
|
||||
key, err := models.GetPublicKeyByID(keyID)
|
||||
key, err := asymkey_model.GetPublicKeyByID(keyID)
|
||||
if err != nil {
|
||||
if models.IsErrKeyNotExist(err) {
|
||||
if asymkey_model.IsErrKeyNotExist(err) {
|
||||
ctx.JSON(http.StatusNotFound, private.ErrServCommand{
|
||||
Results: results,
|
||||
Err: fmt.Sprintf("Cannot find key: %d", keyID),
|
||||
|
@ -205,7 +206,7 @@ func ServCommand(ctx *context.PrivateContext) {
|
|||
results.UserID = key.OwnerID
|
||||
|
||||
// If repo doesn't exist, deploy key doesn't make sense
|
||||
if !repoExist && key.Type == models.KeyTypeDeploy {
|
||||
if !repoExist && key.Type == asymkey_model.KeyTypeDeploy {
|
||||
ctx.JSON(http.StatusNotFound, private.ErrServCommand{
|
||||
Results: results,
|
||||
Err: fmt.Sprintf("Cannot find repository %s/%s", results.OwnerName, results.RepoName),
|
||||
|
@ -216,15 +217,15 @@ func ServCommand(ctx *context.PrivateContext) {
|
|||
// Deploy Keys have ownerID set to 0 therefore we can't use the owner
|
||||
// So now we need to check if the key is a deploy key
|
||||
// We'll keep hold of the deploy key here for permissions checking
|
||||
var deployKey *models.DeployKey
|
||||
var deployKey *asymkey_model.DeployKey
|
||||
var user *user_model.User
|
||||
if key.Type == models.KeyTypeDeploy {
|
||||
if key.Type == asymkey_model.KeyTypeDeploy {
|
||||
results.IsDeployKey = true
|
||||
|
||||
var err error
|
||||
deployKey, err = models.GetDeployKeyByRepo(key.ID, repo.ID)
|
||||
deployKey, err = asymkey_model.GetDeployKeyByRepo(key.ID, repo.ID)
|
||||
if err != nil {
|
||||
if models.IsErrDeployKeyNotExist(err) {
|
||||
if asymkey_model.IsErrDeployKeyNotExist(err) {
|
||||
ctx.JSON(http.StatusNotFound, private.ErrServCommand{
|
||||
Results: results,
|
||||
Err: fmt.Sprintf("Public (Deploy) Key: %d:%s is not authorized to %s %s/%s.", key.ID, key.Name, modeString, results.OwnerName, results.RepoName),
|
||||
|
@ -297,7 +298,7 @@ func ServCommand(ctx *context.PrivateContext) {
|
|||
owner.Visibility.IsPrivate() ||
|
||||
(user != nil && user.IsRestricted) || // user will be nil if the key is a deploykey
|
||||
setting.Service.RequireSignInView) {
|
||||
if key.Type == models.KeyTypeDeploy {
|
||||
if key.Type == asymkey_model.KeyTypeDeploy {
|
||||
if deployKey.Mode < mode {
|
||||
ctx.JSON(http.StatusUnauthorized, private.ErrServCommand{
|
||||
Results: results,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue