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

Some repos are missing in global and org code search #23474

Closed
silverwind opened this issue Mar 14, 2023 · 5 comments
Closed

Some repos are missing in global and org code search #23474

silverwind opened this issue Mar 14, 2023 · 5 comments
Labels

Comments

@silverwind
Copy link
Member

silverwind commented Mar 14, 2023

Description

I have one odd issue with code search where results from some repos do not show up in the global code search or the organization code search. The user is member of the default Owners team of two repos, let's call them org1/repo1 and org2/repo2.

  • Both repos are private
  • Both orgs are private
  • Both repos have the exact same settings in the UI
  • Both repos contain string query in one of their files

/org1/repo1/search?q=query shows results
/org2/repo2/search?q=query shows results
/org1/-/code?q=query shows results
/org2/-/code?q=query show NO results
/explore/code?q=query shows NO results from repo2, only from repo1

  • Giving the user admin permission fixes the issue
  • Adding the user to repo2 as collaborator fixes the issue
  • Switching repo2 to public access fixes the issue
  • Switching org2 to public access has no effect

There is probably still some difference in these repos in the database, but I'm not sure what to look at. Any pointers appreciated on what to look for.

Gitea Version

1.19.0+rc1-37-g0a0f46f29

Can you reproduce the bug on the Gitea demo site?

No

Database

MySQL

@silverwind silverwind changed the title Some repos are missing in global or org code search Some repos are missing in global and org code search Mar 14, 2023
@silverwind
Copy link
Member Author

silverwind commented Mar 14, 2023

I have narrowed it down to the following SQL query:

SELECT name from repository where id in (
  SELECT repo_id FROM team_repo
     INNER JOIN team_user ON `team_user`.team_id = `team_repo`.team_id
     INNER JOIN team_unit ON `team_unit`.team_id = `team_repo`.team_id
     WHERE `team_user`.uid=1234
       AND `team_unit`.`type`=1
       AND `team_unit`.`access_mode`>0
)

It seems the access_mode condition is the failing one, if I remove it, I get the missing repo to show up.

@silverwind
Copy link
Member Author

silverwind commented Mar 14, 2023

I think the access_mode value of the Owners team is incorrect. It is 0 (no access) for some owner teams but should be 4 (full access), but as the owner team is not editable in the UI, I think this can only be remedied via SQL.

@silverwind
Copy link
Member Author

silverwind commented Mar 14, 2023

So I fixed the affected teams with this SQL:

update team_unit set access_mode = 4 where id in (
  select id from (
    select team_unit.id from team_unit
      inner join team on team_unit.team_id = team.id
      where name = "Owners" and team_unit.access_mode = 0
  ) as _
)

Creating a new org seems again create Owner teams with team_unit.access_mode=0, so I think there is a bug in current code that creates these "broken" teams. After creating a new org, I again see a broken Owners team was created with this query:

select distinct(team.id) from team_unit 
  inner join team on team_unit.team_id = team.id
  where name = "Owners" and team_unit.access_mode = 0;

@silverwind
Copy link
Member Author

silverwind commented Mar 14, 2023

Reproduces locally as well. Just create a new org and check the access_mode of Owners via SQL:

localhost> select distinct(team.id) from team_unit inner join team on team_unit.team_id = team.id where name = "Owners" and team_unit.access_mode = 0;
+----+
| id |
+----+
|  4 |
+----+
1 row in set (0.001 sec)

@silverwind
Copy link
Member Author

Fixed by #23675

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant