Merge remote-tracking branch 'forgejo/forgejo-f3' into wip-forgejo

This commit is contained in:
Earl Warren 2023-09-04 13:11:35 +02:00
commit b9315b83cb
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
40 changed files with 3944 additions and 49 deletions

View file

@ -33,6 +33,9 @@ const (
SSPI // 7
)
// This should be in the above list of types but is separated to avoid conflicts with Gitea changes
const F3 Type = 129
// String returns the string name of the LoginType
func (typ Type) String() string {
return Names[typ]
@ -51,6 +54,7 @@ var Names = map[Type]string{
PAM: "PAM",
OAuth2: "OAuth2",
SSPI: "SPNEGO with SSPI",
F3: "F3",
}
// Config represents login config as far as the db is concerned
@ -179,6 +183,10 @@ func (source *Source) IsSSPI() bool {
return source.Type == SSPI
}
func (source *Source) IsF3() bool {
return source.Type == F3
}
// HasTLS returns true of this source supports TLS.
func (source *Source) HasTLS() bool {
hasTLSer, ok := source.Cfg.(HasTLSer)

View file

@ -230,6 +230,21 @@ func GetRepoTopicByName(ctx context.Context, repoID int64, topicName string) (*T
return nil, err
}
// GetRepoTopicByID retrieves topic from ID for a repo if it exist
func GetRepoTopicByID(ctx context.Context, repoID, topicID int64) (*Topic, error) {
cond := builder.NewCond()
var topic Topic
cond = cond.And(builder.Eq{"repo_topic.repo_id": repoID}).And(builder.Eq{"topic.id": topicID})
sess := db.GetEngine(ctx).Table("topic").Where(cond)
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
if has, err := sess.Select("topic.*").Get(&topic); err != nil {
return nil, err
} else if !has {
return nil, ErrTopicNotExist{""}
}
return &topic, nil
}
// AddTopic adds a topic name to a repository (if it does not already have it)
func AddTopic(repoID int64, topicName string) (*Topic, error) {
ctx, committer, err := db.TxContext(db.DefaultContext)

View file

@ -39,7 +39,12 @@ type SearchUserOptions struct {
}
func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
var cond builder.Cond = builder.Eq{"type": opts.Type}
var cond builder.Cond
if opts.Type == UserTypeIndividual {
cond = builder.In("type", UserTypeIndividual, UserTypeF3)
} else {
cond = builder.Eq{"type": opts.Type}
}
if len(opts.Keyword) > 0 {
lowerKeyword := strings.ToLower(opts.Keyword)
keywordCond := builder.Or(

View file

@ -55,6 +55,9 @@ const (
UserTypeRemoteUser
)
// It belongs above but is set explicitly here to avoid conflicts
const UserTypeF3 UserType = 128
const (
// EmailNotificationsEnabled indicates that the user would like to receive all email notifications except your own
EmailNotificationsEnabled = "enabled"
@ -220,7 +223,7 @@ func (u *User) GetEmail() string {
// GetAllUsers returns a slice of all individual users found in DB.
func GetAllUsers() ([]*User, error) {
users := make([]*User, 0)
return users, db.GetEngine(db.DefaultContext).OrderBy("id").Where("type = ?", UserTypeIndividual).Find(&users)
return users, db.GetEngine(db.DefaultContext).OrderBy("id").In("type", UserTypeIndividual, UserTypeF3).Find(&users)
}
// IsLocal returns true if user login type is LoginPlain.
@ -416,6 +419,10 @@ func (u *User) IsBot() bool {
return u.Type == UserTypeBot
}
func (u *User) IsF3() bool {
return u.Type == UserTypeF3
}
// DisplayName returns full name if it's not empty,
// returns username otherwise.
func (u *User) DisplayName() string {
@ -969,7 +976,8 @@ func GetUserByName(ctx context.Context, name string) (*User, error) {
if len(name) == 0 {
return nil, ErrUserNotExist{0, name, 0}
}
u := &User{LowerName: strings.ToLower(name), Type: UserTypeIndividual}
// adding Type: UserTypeIndividual is a noop because it is zero and discarded
u := &User{LowerName: strings.ToLower(name)}
has, err := db.GetEngine(ctx).Get(u)
if err != nil {
return nil, err
@ -1005,7 +1013,7 @@ func GetMaileableUsersByIDs(ctx context.Context, ids []int64, isMention bool) ([
if isMention {
return ous, db.GetEngine(ctx).
In("id", ids).
Where("`type` = ?", UserTypeIndividual).
In("`type`", UserTypeIndividual, UserTypeF3).
And("`prohibit_login` = ?", false).
And("`is_active` = ?", true).
In("`email_notifications_preference`", EmailNotificationsEnabled, EmailNotificationsOnMention, EmailNotificationsAndYourOwn).
@ -1014,7 +1022,7 @@ func GetMaileableUsersByIDs(ctx context.Context, ids []int64, isMention bool) ([
return ous, db.GetEngine(ctx).
In("id", ids).
Where("`type` = ?", UserTypeIndividual).
In("`type`", UserTypeIndividual, UserTypeF3).
And("`prohibit_login` = ?", false).
And("`is_active` = ?", true).
In("`email_notifications_preference`", EmailNotificationsEnabled, EmailNotificationsAndYourOwn).