Skip to content

Commit 29637b0

Browse files
authored
Fix commits pushed with deploy keys not shown in dashboard (#24521)
Fix #21324 In the current logic, if the `Actor` user is not an admin user, all activities from private organizations won't be shown even if the `Actor` user is a member of the organization. As mentioned in the issue, when using deploy key to make a commit and push, the activity's `act_user_id` will be the id of the organization so the activity won't be shown to non-admin users because the visibility of the organization is private. https://github.com/go-gitea/gitea/blob/55a57177600028ba8e4a480a08f1ee4d69d219d6/models/activities/action.go#L490-L503 This PR improves this logic so the activities of private organizations can be shown.
1 parent 8030614 commit 29637b0

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

models/activities/action.go

+21-6
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,27 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
494494
).From("`user`"),
495495
))
496496
} else if !opts.Actor.IsAdmin {
497-
cond = cond.And(builder.In("act_user_id",
498-
builder.Select("`user`.id").Where(
499-
builder.Eq{"keep_activity_private": false}.
500-
And(builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))).
501-
Or(builder.Eq{"id": opts.Actor.ID}).From("`user`"),
502-
))
497+
uidCond := builder.Select("`user`.id").From("`user`").Where(
498+
builder.Eq{"keep_activity_private": false}.
499+
And(builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))).
500+
Or(builder.Eq{"id": opts.Actor.ID})
501+
502+
if opts.RequestedUser != nil {
503+
if opts.RequestedUser.IsOrganization() {
504+
// An organization can always see the activities whose `act_user_id` is the same as its id.
505+
uidCond = uidCond.Or(builder.Eq{"id": opts.RequestedUser.ID})
506+
} else {
507+
// A user can always see the activities of the organizations to which the user belongs.
508+
uidCond = uidCond.Or(
509+
builder.Eq{"type": user_model.UserTypeOrganization}.
510+
And(builder.In("`user`.id", builder.Select("org_id").
511+
Where(builder.Eq{"uid": opts.RequestedUser.ID}).
512+
From("team_user"))),
513+
)
514+
}
515+
}
516+
517+
cond = cond.And(builder.In("act_user_id", uidCond))
503518
}
504519

505520
// check readable repositories by doer/actor

0 commit comments

Comments
 (0)