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

Hide unactive on explore users and some refactors #2741

Merged
merged 12 commits into from
Oct 24, 2017

Conversation

lunny
Copy link
Member

@lunny lunny commented Oct 19, 2017

Unactive user should not displayed on explore UI. This PR also reafctors SearchUserName to SearchUsers.

@lunny lunny added type/enhancement An improvement of existing functionality type/refactoring Existing code has been cleaned up. There should be no new functionality. labels Oct 19, 2017
@lunny lunny force-pushed the lunny/hide_unactive_user_explore branch from 7ad18cd to 884fdcd Compare October 19, 2017 07:18
@lunny lunny added this to the 1.3.0 milestone Oct 19, 2017
@codecov-io
Copy link

codecov-io commented Oct 19, 2017

Codecov Report

Merging #2741 into master will increase coverage by 0.17%.
The diff coverage is 92.3%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2741      +/-   ##
==========================================
+ Coverage    26.9%   27.08%   +0.17%     
==========================================
  Files          88       88              
  Lines       17289    17264      -25     
==========================================
+ Hits         4652     4676      +24     
+ Misses      11958    11909      -49     
  Partials      679      679
Impacted Files Coverage Δ
models/org.go 68.94% <ø> (-0.87%) ⬇️
models/user.go 21.45% <92.3%> (+3.21%) ⬆️
models/issue_watch.go 66.66% <0%> (-17.55%) ⬇️
models/notification.go 69.35% <0%> (+10.75%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0390030...21cadbd. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 19, 2017
@lunny lunny added type/bug and removed type/enhancement An improvement of existing functionality labels Oct 19, 2017
Copy link
Member

@ethantkoenig ethantkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor things

@@ -240,7 +240,8 @@ func TestCountOrganizations(t *testing.T) {
func TestOrganizations(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should be moved from org_test to user_test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will only set type = UserTypeOrganization, it's for organizations but not users. Since Users and Organizations share the user table. SearchUsers will be shared also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it tests a function that is defined in user.go, whereas it previously tested a function that was defined in org.go. It is my understanding that if something is defined in XYZ.go, its test should be in XYZ_test.go; is my understanding incorrect?

Copy link
Member Author

@lunny lunny Oct 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But should I rename it from TestOrganizations to TestUsers or just put TestOrganizations to user_test.go? This function logically test organizations but SearchUsers is shared by Users and Organizations although it's in user.go. So I don't think we can obey the rule you mentioned above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest renaming it to TestSearchUsers, and expanding it to test for both individual users and organizations, but you can do what you think is best.

One way or another, however, we should make sure that the SearchUsers function is fully tested (both individual users and organizations).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will send another commit to do that.

models/user.go Outdated
IsActive util.OptionalBool
}

func (opts *SearchUserOptions) toConds() builder.Cond {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since this returns a Cond, please call it toCond().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethantkoenig For SearchUserOptions contains not only 1 condition it should be toConds. And builder.Cond maybe one condition or composite conditions, so toConds will be more suitable.

@lunny lunny force-pushed the lunny/hide_unactive_user_explore branch from f27202c to c849eab Compare October 22, 2017 02:21
@lunny
Copy link
Member Author

lunny commented Oct 22, 2017

@ethantkoenig done.

Copy link
Member

@ethantkoenig ethantkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but looks good otherwise. +1 for adding the methods to OptionalBool

// 9 are inactive, thus notifications for user 1 and 4 is created
notf := AssertExistsAndLoadBean(t, &Notification{UserID: 1, IssueID: issue.ID}).(*Notification)
assert.Equal(t, NotificationStatusUnread, notf.Status)
CheckConsistencyFor(t, &Issue{ID: issue.ID})
Copy link
Member

@ethantkoenig ethantkoenig Oct 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't need to call CheckConsistencyFor(t, &Issue{ID: issue.ID}) twice, since nothing changes in between the calls. Preferably, only call at the end of the test, for consistency with other tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

return o == OptionalBoolFalse
}

// IsNone return true if equal to OptionalBoolFalse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OptionalBoolFalse -> OptionalBoolNone

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -16,8 +16,12 @@ func TestCreateOrUpdateIssueNotifications(t *testing.T) {

assert.NoError(t, CreateOrUpdateIssueNotifications(issue, 2))

// Two watchers are inactive, thus only notification for user 10 is created
notf := AssertExistsAndLoadBean(t, &Notification{UserID: 10, IssueID: issue.ID}).(*Notification)
// 9 are inactive, thus notifications for user 1 and 4 is created
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: change to // User 9 is inactive, .... The current version could mistakenly be interpreted as "9 users are inactive".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@ethantkoenig
Copy link
Member

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Oct 22, 2017
@appleboy
Copy link
Member

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Oct 24, 2017
@lafriks lafriks merged commit 6eeadb2 into go-gitea:master Oct 24, 2017
@lunny lunny deleted the lunny/hide_unactive_user_explore branch October 25, 2017 00:34
vdbt pushed a commit to vdbt/gitea that referenced this pull request Oct 27, 2017
* hide unactive on explore users and some refactors

* fix test for removed Organizations

* fix test for removed Organizations

* fix imports

* fix logic bug

* refactor the toConds

* Rename TestOrganizations to TestSearchUsers and add tests for users

* fix other tests

* fix other tests

* fix watchers tests

* fix comments and remove unused code
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants