-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Ordering organizations and users by name #49
Ordering organizations and users by name #49
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just minor revert of changes.
@@ -15,7 +15,6 @@ | |||
<table class="ui very basic striped table"> | |||
<thead> | |||
<tr> | |||
<th>ID</th> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A proper listing is a different story, but I would like to keep this information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tboerger Done. "ID" column restored
@@ -15,7 +15,6 @@ | |||
<table class="ui very basic striped table"> | |||
<thead> | |||
<tr> | |||
<th>ID</th> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@@ -18,7 +18,6 @@ | |||
<table class="ui very basic striped table"> | |||
<thead> | |||
<tr> | |||
<th>ID</th> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to do raw SQL-query here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be "org_user.uid=?"
no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant in the Where
-clause, since it's a JOIN 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"...)
@@ -298,12 +296,16 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) { | |||
// GetOrgUsersByUserID returns all organization-user relations by user ID. | |||
func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) { | |||
ous := make([]*OrgUser, 0, 10) | |||
sess := x.Where("uid=?", uid) | |||
sess := x. | |||
Join("LEFT", "user", `"org_user".org_id="user".id`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No JOIN should be needed here, as user id is already in the OrgUser table ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Join is needed to order by Name
@@ -453,6 +455,8 @@ func (org *User) getUserTeams(e Engine, userID int64, cols ...string) ([]*Team, | |||
return teams, e.Where("team_user.org_id = ?", org.ID). | |||
And("team_user.uid = ?", userID). | |||
Join("INNER", "team_user", "team_user.team_id = team.id"). | |||
Join("INNER", "user", `"user".id=team_user.uid`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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").
} | ||
org.Members, _ = GetUsersByIDs(ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why ignore the errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cause in all cases GetUsersByIDs
return an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if get users failed, we should return error to external of function. I think this should be
org.members, err = GetUsersByIDs(ids)
return err
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, always return errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -453,6 +455,8 @@ func (org *User) getUserTeams(e Engine, userID int64, cols ...string) ([]*Team, | |||
return teams, e.Where("team_user.org_id = ?", org.ID). | |||
And("team_user.uid = ?", userID). | |||
Join("INNER", "team_user", "team_user.team_id = team.id"). | |||
Join("INNER", "user", `"user".id=team_user.uid`). | |||
Asc("user.name"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need quote on user
too
ids[i] = ou.Uid | ||
} | ||
org.Members, err = GetUsersByIDs(ids) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need, just return err
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if !all { | ||
// Only show public organizations | ||
sess.And("is_public=?", true) | ||
} | ||
err := sess.Find(&ous) | ||
err := sess. | ||
Asc("name"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this should be
Asc("`user`.name")`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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
GetUsersByIDs
to decrease the number of SQL queries by using IN predicate rather than just running 1 SQL query per users.