Ordering organizations and users by name#49
Ordering organizations and users by name#49thibaultmeyer wants to merge 45 commits intogo-gitea:masterfrom thibaultmeyer:feature/3845-ordering-org-user
Conversation
Current coverage is 2.24% (diff: 0.00%)@@ master #49 diff @@
========================================
Files 31 32 +1
Lines 7508 7530 +22
Methods 0 0
Messages 0 0
Branches 0 0
========================================
+ Hits 166 169 +3
- Misses 7326 7344 +18
- Partials 16 17 +1
|
tboerger
left a comment
There was a problem hiding this comment.
Just minor revert of changes.
templates/admin/org/list.tmpl
Outdated
There was a problem hiding this comment.
Please keep that, this is an admin view and I would print there as much information as possible.
There was a problem hiding this comment.
There was a problem hiding this comment.
A proper listing is a different story, but I would like to keep this information.
templates/admin/repo/list.tmpl
Outdated
templates/admin/user/list.tmpl
Outdated
|
Can you rebase it? |
|
You could choose "Rebase and Merge" during the merge process : https://github.com/blog/2243-rebase-and-merge-pull-requests |
| @@ -495,7 +499,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos | |||
| repos := make([]*Repository, 0, pageSize) | |||
| // FIXME: use XORM chain operations instead of raw SQL. | |||
| if err = x.Sql(fmt.Sprintf(`SELECT repository.* FROM repository | |||
There was a problem hiding this comment.
Do we really need to do raw SQL-query here?
There was a problem hiding this comment.
Probably not, but this code is not part of the current pull request. It could be a part of another one (eg : rewrite and optimize all SQL queries)
There was a problem hiding this comment.
Well, if you're making that line better, you could just as well make it even better 😄 Saves us another PR 👍
There was a problem hiding this comment.
I prefer 1 PR = 1 problem solved. This is more simple for everyone and easily to review.
I will replace all raw queries on model files with XORM chain operations in another PR.
| @@ -507,7 +511,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos | |||
| } | |||
|
|
|||
| results, err := x.Query(fmt.Sprintf(`SELECT repository.id FROM repository | |||
| @@ -534,7 +538,7 @@ func (org *User) GetUserMirrorRepositories(userID int64) ([]*Repository, error) | |||
|
|
|||
| repos := make([]*Repository, 0, 10) | |||
| if err = x.Sql(fmt.Sprintf(`SELECT repository.* FROM repository | |||
models/org.go
Outdated
| sess := x.Where("uid=?", uid) | ||
| sess := x. | ||
| Join("LEFT", "user", `"org_user".org_id="user".id`). | ||
| Where("uid=?", uid) |
There was a problem hiding this comment.
This should probably be "org_user.uid=?" no?
There was a problem hiding this comment.
It seem correct, Here we want organizations ordered by name, and in GOGS, organization are just a simple user.
There was a problem hiding this comment.
I meant in the Where-clause, since it's a JOIN 🙂
There was a problem hiding this comment.
since the field uid only exists on the table org_user, the WHERE clause is good. But if you wan't I can add "org_user.uid=?" ?? in all cases it will working.
There was a problem hiding this comment.
Better be safe than sorry, and consistent (also "org_id" is only in org_user but is explicitly listed.
BTW, I don't think you need to quote "org_user" and "user"...)
models/org.go
Outdated
There was a problem hiding this comment.
No JOIN should be needed here, as user id is already in the OrgUser table ?
There was a problem hiding this comment.
Table "public.org_user"
Column | Type | Modifiers
-----------+---------+-------------------------------------------------------
id | integer | not null default nextval('org_user_id_seq'::regclass)
uid | bigint |
org_id | bigint |
is_public | boolean |
is_owner | boolean |
num_teams | integer |
There was a problem hiding this comment.
Join is needed to order by Name
models/org.go
Outdated
There was a problem hiding this comment.
Hmm.. Ideally, we should not quote column names. Quoting is different between different databases. PostgreSQL uses ", MySQL uses `, etc. Where this is necessary, I think using this Xorm function should work.
Same for other SQLs.
There was a problem hiding this comment.
XORM will use as the uniform quote and will replace it as database's self quote. So just use,
Join("INNER", "user", "`user`.id=team_user.uid").
models/org.go
Outdated
There was a problem hiding this comment.
cause in all cases GetUsersByIDs return an array.
There was a problem hiding this comment.
But if get users failed, we should return error to external of function. I think this should be
org.members, err = GetUsersByIDs(ids)
return errThere was a problem hiding this comment.
Agreed, always return errors
models/org.go
Outdated
models/org.go
Outdated
There was a problem hiding this comment.
no need, just return err...
There was a problem hiding this comment.
you right. Fixed
Current coverage is 3.13% (diff: 0.00%)@@ master #49 diff @@
========================================
Files 33 33
Lines 7823 7841 +18
Methods 0 0
Messages 0 0
Branches 0 0
========================================
Hits 246 246
- Misses 7557 7575 +18
Partials 20 20
|
ID column restored on admin console
models/org.go
Outdated
There was a problem hiding this comment.
so this should be
Asc("`user`.name")`It is the FROM field in mailer configuration that needs be used, not the USER field, which is for authentication. Closes gogs/gogs#3615
* Added badges to the README * Restructured the travis config
* Dropped codebeat, we got go reportcard * Dropped gopm file, we are using govendor * Dropped chinese readme, this should be part of the docs * Dropped bra config, not really used * Dropped packager, we will provide our own packages
…or)", replaced with custom name
Creating a notice instead
- Handle XORM error - Quote columns in XORM error - Restore ID column on admin console
|
something wrong. @joubertredrat |
|
Yeah i dont know why... I have just rebase to avoid multiple commit. Git show get right commit but github just explode. I will recreate PR within few minutes |
|
Something goes wrong with rebase, I close this issue, delete GOGS repos and fork Gitea. I will re-create PR without few hours |
|
@lunny strange, I don't have relation with this PR and my commit listed already have PRs in #5 and #54 @0xBAADF00D for me was same, was necessary to remove gogs fork and make new fork from Gitea |

Relative to the issue #3845, this Pull Request add modifications to ordering by name Organizations and User Accounts.
It's more user friendly and make search more easy when organizations and user accounts are ordered by name rather than last update datetime.
I added new function
GetUsersByIDsto decrease the number of SQL queries by using IN predicate rather than just running 1 SQL query per users.