Skip to content

Commit 5343ec1

Browse files
committed
fix
1 parent d4f35bd commit 5343ec1

File tree

2 files changed

+80
-5
lines changed

2 files changed

+80
-5
lines changed

models/issues/issue.go

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,8 @@ func teamUnitsRepoCond(id string, userID, orgID, teamID int64, units ...unit.Typ
13741374
"`team_unit`.org_id": orgID,
13751375
}.And(
13761376
builder.In("`team_unit`.type", units),
1377+
).And(
1378+
builder.Gt{"`team_unit`.access_mode": int(perm.AccessModeNone)},
13771379
),
13781380
),
13791381
),
@@ -1402,17 +1404,64 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
14021404
} else {
14031405
cond = cond.And(
14041406
builder.Or(
1405-
repo_model.UserOwnedRepoCond(userID), // owned repos
1406-
repo_model.UserAccessRepoCond(repoIDstr, userID), // user can access repo in a unit independent way
1407-
repo_model.UserAssignedRepoCond(repoIDstr, userID), // user has been assigned accessible public repos
1408-
repo_model.UserMentionedRepoCond(repoIDstr, userID), // user has been mentioned accessible public repos
1409-
repo_model.UserCreateIssueRepoCond(repoIDstr, userID, isPull), // user has created issue/pr accessible public repos
1407+
repo_model.UserOwnedRepoCond(userID), // owned repos
1408+
repo_model.UserUnitAccessRepoCond(repoIDstr, userID, unitType), // user can access repo in a unit independent way
1409+
UserAssignedIssueCond(userID), // user has been assigned accessible public repos
1410+
UserMentionedIssueCond(userID), // user has been mentioned accessible public repos
1411+
UserCreateIssueCond(userID, isPull), // user has created issue/pr accessible public repos
14101412
),
14111413
)
14121414
}
14131415
return cond
14141416
}
14151417

1418+
// UserAssignedIssueCond return user as assignee issues list
1419+
func UserAssignedIssueCond(userID int64) builder.Cond {
1420+
return builder.And(
1421+
builder.Eq{
1422+
"repository.is_private": false,
1423+
},
1424+
builder.In("issue.id",
1425+
builder.Select("issue_assignees.issue_id").From("issue_assignees").
1426+
Where(builder.Eq{
1427+
"issue_assignees.assignee_id": userID,
1428+
}),
1429+
),
1430+
)
1431+
}
1432+
1433+
// UserMentionedIssueCond return user metinoed issues list
1434+
func UserMentionedIssueCond(userID int64) builder.Cond {
1435+
return builder.And(
1436+
builder.Eq{
1437+
"repository.is_private": false,
1438+
},
1439+
builder.In("issue.id",
1440+
builder.Select("issue_user.issue_id").From("issue_user").
1441+
Where(builder.Eq{
1442+
"issue_user.is_mentioned": true,
1443+
"issue_user.uid": userID,
1444+
}),
1445+
),
1446+
)
1447+
}
1448+
1449+
// UserCreateIssueCond return user created issues list
1450+
func UserCreateIssueCond(userID int64, isPull bool) builder.Cond {
1451+
return builder.And(
1452+
builder.Eq{
1453+
"repository.is_private": false,
1454+
},
1455+
builder.In("issue.id",
1456+
builder.Select("issue.id").From("issue").
1457+
Where(builder.Eq{
1458+
"issue.poster_id": userID,
1459+
"issue.is_pull": isPull,
1460+
}),
1461+
),
1462+
)
1463+
}
1464+
14161465
func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session {
14171466
return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
14181467
And("issue_assignees.assignee_id = ?", assigneeID)

models/repo/repo_list.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,32 @@ func UserAccessRepoCond(idStr string, userID int64) builder.Cond {
256256
)
257257
}
258258

259+
// UserUnitAccessRepoCond returns a condition for selecting all repositories a user has unit independent access to and can access the special unit
260+
func UserUnitAccessRepoCond(idStr string, userID int64, unitType unit.Type) builder.Cond {
261+
return builder.In(idStr, builder.Select("`access`.repo_id").
262+
From("`access`").
263+
Join("INNER", "repository", "`repository`.id = `access`.repo_id").
264+
Join("INNER", "user", "`user`.id = `repository`.owner_id").
265+
Where(
266+
builder.And(
267+
builder.Eq{"`access`.user_id": userID},
268+
builder.Gt{"`access`.mode": int(perm.AccessModeNone)},
269+
builder.Or(
270+
// if repo is an org repo, user need to have unit access permission of the team or be a collaborator of this repo
271+
builder.And(
272+
builder.Eq{"`user`.type": int(user_model.UserTypeOrganization)},
273+
builder.Or(
274+
builder.In("`access`.repo_id", userOrgTeamUnitRepoBuilder(userID, unitType)),
275+
UserCollaborationRepoCond("`access`.repo_id", userID),
276+
),
277+
),
278+
builder.Eq{"`user`.type": int(user_model.UserTypeIndividual)},
279+
),
280+
),
281+
),
282+
)
283+
}
284+
259285
// userCollaborationRepoCond returns a condition for selecting all repositories a user is collaborator in
260286
func UserCollaborationRepoCond(idStr string, userID int64) builder.Cond {
261287
return builder.In(idStr, builder.Select("repo_id").

0 commit comments

Comments
 (0)