Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ghost user if package creator does not exist #23822

Merged
merged 3 commits into from
Apr 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion models/packages/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package packages

import (
"context"
"errors"
"fmt"
"net/url"

Expand All @@ -26,6 +27,7 @@ import (
"code.gitea.io/gitea/modules/packages/rubygems"
"code.gitea.io/gitea/modules/packages/swift"
"code.gitea.io/gitea/modules/packages/vagrant"
"code.gitea.io/gitea/modules/util"

"github.com/hashicorp/go-version"
)
Expand Down Expand Up @@ -99,7 +101,11 @@ func GetPackageDescriptor(ctx context.Context, pv *PackageVersion) (*PackageDesc
}
creator, err := user_model.GetUserByID(ctx, pv.CreatorID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be GetPossibleUserByID?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if the user gets deleted, the CreatorID is not -1 or -2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe we need to check if it's -2 here?

Copy link
Contributor

@yp05327 yp05327 Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does actions user have write permission to create packages?
If not, maybe we don't need to check -2 here.

Copy link
Member

@wolfogre wolfogre Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does actions user have write permission to create packages?

I think it doesn't. Gitea will use the trigger user instead of actions bot user as the package creator in #23729.

However, I think it will be more robust to support actions bot as package creator. (BTW, not the owner)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it is not merged. It seems that actions user can not create packages in current version, but I’m not sure about this, so I asked this question.

Copy link
Member

@wolfogre wolfogre Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it is not merged. It seems that actions user can not create packages in current version, but I’m not sure about this, so I asked this question.

OK, I misunderstand your question. So the answer to Does actions user have write permission to create packages is no now, and I 90% sure it should be no by default, but maybe we can provide an option to set it on UI for users in the future.

if err != nil {
return nil, err
if errors.Is(err, util.ErrNotExist) {
creator = user_model.NewGhostUser()
} else {
return nil, err
}
}
var semVer *version.Version
if p.SemverCompatible {
Expand Down