Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yp05327 committed Mar 24, 2023
1 parent d4f35bd commit 5343ec1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 5 deletions.
59 changes: 54 additions & 5 deletions models/issues/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,8 @@ func teamUnitsRepoCond(id string, userID, orgID, teamID int64, units ...unit.Typ
"`team_unit`.org_id": orgID,
}.And(
builder.In("`team_unit`.type", units),
).And(
builder.Gt{"`team_unit`.access_mode": int(perm.AccessModeNone)},
),
),
),
Expand Down Expand Up @@ -1402,17 +1404,64 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
} else {
cond = cond.And(
builder.Or(
repo_model.UserOwnedRepoCond(userID), // owned repos
repo_model.UserAccessRepoCond(repoIDstr, userID), // user can access repo in a unit independent way
repo_model.UserAssignedRepoCond(repoIDstr, userID), // user has been assigned accessible public repos
repo_model.UserMentionedRepoCond(repoIDstr, userID), // user has been mentioned accessible public repos
repo_model.UserCreateIssueRepoCond(repoIDstr, userID, isPull), // user has created issue/pr accessible public repos
repo_model.UserOwnedRepoCond(userID), // owned repos
repo_model.UserUnitAccessRepoCond(repoIDstr, userID, unitType), // user can access repo in a unit independent way
UserAssignedIssueCond(userID), // user has been assigned accessible public repos
UserMentionedIssueCond(userID), // user has been mentioned accessible public repos
UserCreateIssueCond(userID, isPull), // user has created issue/pr accessible public repos
),
)
}
return cond
}

// UserAssignedIssueCond return user as assignee issues list
func UserAssignedIssueCond(userID int64) builder.Cond {
return builder.And(
builder.Eq{
"repository.is_private": false,
},
builder.In("issue.id",
builder.Select("issue_assignees.issue_id").From("issue_assignees").
Where(builder.Eq{
"issue_assignees.assignee_id": userID,
}),
),
)
}

// UserMentionedIssueCond return user metinoed issues list
func UserMentionedIssueCond(userID int64) builder.Cond {
return builder.And(
builder.Eq{
"repository.is_private": false,
},
builder.In("issue.id",
builder.Select("issue_user.issue_id").From("issue_user").
Where(builder.Eq{
"issue_user.is_mentioned": true,
"issue_user.uid": userID,
}),
),
)
}

// UserCreateIssueCond return user created issues list
func UserCreateIssueCond(userID int64, isPull bool) builder.Cond {
return builder.And(
builder.Eq{
"repository.is_private": false,
},
builder.In("issue.id",
builder.Select("issue.id").From("issue").
Where(builder.Eq{
"issue.poster_id": userID,
"issue.is_pull": isPull,
}),
),
)
}

func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session {
return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
And("issue_assignees.assignee_id = ?", assigneeID)
Expand Down
26 changes: 26 additions & 0 deletions models/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,32 @@ func UserAccessRepoCond(idStr string, userID int64) builder.Cond {
)
}

// UserUnitAccessRepoCond returns a condition for selecting all repositories a user has unit independent access to and can access the special unit
func UserUnitAccessRepoCond(idStr string, userID int64, unitType unit.Type) builder.Cond {
return builder.In(idStr, builder.Select("`access`.repo_id").
From("`access`").
Join("INNER", "repository", "`repository`.id = `access`.repo_id").
Join("INNER", "user", "`user`.id = `repository`.owner_id").
Where(
builder.And(
builder.Eq{"`access`.user_id": userID},
builder.Gt{"`access`.mode": int(perm.AccessModeNone)},
builder.Or(
// if repo is an org repo, user need to have unit access permission of the team or be a collaborator of this repo
builder.And(
builder.Eq{"`user`.type": int(user_model.UserTypeOrganization)},
builder.Or(
builder.In("`access`.repo_id", userOrgTeamUnitRepoBuilder(userID, unitType)),
UserCollaborationRepoCond("`access`.repo_id", userID),
),
),
builder.Eq{"`user`.type": int(user_model.UserTypeIndividual)},
),
),
),
)
}

// userCollaborationRepoCond returns a condition for selecting all repositories a user is collaborator in
func UserCollaborationRepoCond(idStr string, userID int64) builder.Cond {
return builder.In(idStr, builder.Select("repo_id").
Expand Down

0 comments on commit 5343ec1

Please sign in to comment.