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

Add subscription transfer and contact deletion to CLI #443

Merged

Conversation

Nixolay
Copy link
Contributor

@Nixolay Nixolay commented Oct 15, 2019

Close #424

@coveralls
Copy link

coveralls commented Oct 15, 2019

Coverage Status

Coverage remained the same at 79.876% when pulling afe4895 on feature/424-add-subscription-transfer-and-contact-deletion-cli into 83e9692 on master.

@Nixolay Nixolay requested a review from beevee October 16, 2019 06:07
@Nixolay Nixolay changed the title feature: Add subscription transfer and contact deletion to CLI Add subscription transfer and contact deletion to CLI Oct 17, 2019
cmd/cli/main.go Outdated
@@ -71,6 +77,14 @@ func main() {
logger.Errorf("Failed to enable images in all notifications")
}
}

if err := transferUserSubscriptionsAndContacts(dataBase); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Following style of another actions in this document it looks more clear to have something like

	if *fromUser != "" && *toUser != "" {
		if err := transferUserSubscriptionsAndContacts(dataBase, *fromUser, *toUser); err != nil {
			logger.Error(err)
		}
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

Another issue here is that tranfer of subscriptions require from user both toUser and fromUser. I think it will be better if we will check that only one of this valuea is specified and print warning message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected

cmd/cli/main.go Outdated
logger.Error(err)
}

if err := deleteUser(dataBase); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing as in previous comment: can be rewritten in this way:

	if *userDel != "" {
		if err := deleteUser(dataBase, userDel); err != nil {
			logger.Error(err)
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected

cmd/cli/user.go Outdated
)

func transferUserSubscriptionsAndContacts(database moira.Database) error {
if *fromUser == "" && *toUser == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

first my though after looking on this was: "What this variables mean and where are they declared?"

I think that passing this varibales in agruments will increase readability of this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected

cmd/cli/user.go Outdated
return database.SaveSubscriptions(subscriptions)
}

func deleteUser(database moira.Database) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as earlier. I will be more readable if we will receive user id here via function arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected

@Nixolay Nixolay removed the request for review from beevee October 21, 2019 07:18
cmd/cli/user.go Outdated
}
}

subscriptionIDs, err := database.GetUserSubscriptionIDs(*userDel)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok we decided that passing arguments as fromUser and toUser will be more clear instead of using global variables. But what should we do with userDel? I think that this should be another one argument for function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected

@Nixolay Nixolay force-pushed the feature/424-add-subscription-transfer-and-contact-deletion-cli branch from 0a9261e to 7f10e8f Compare October 21, 2019 09:23
cmd/cli/main.go Outdated
@@ -71,6 +77,17 @@ func main() {
logger.Errorf("Failed to enable images in all notifications")
}
}
if *fromUser == "" && *toUser == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that here should be a == instead of !=? As I can see this expression is true only if fromUser and toUser are empty strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected

cmd/cli/main.go Outdated
}
}

if *userDel == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also probably should be !=

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected

@Nixolay Nixolay force-pushed the feature/424-add-subscription-transfer-and-contact-deletion-cli branch 2 times, most recently from 1590ed2 to 1ed0fe3 Compare October 21, 2019 12:14
   * Added flags for this feature: user-del, from-user, to-user
   * Create new functions transferUserSubscriptionsAndContacts and deleteUser
Close #424
@Nixolay Nixolay force-pushed the feature/424-add-subscription-transfer-and-contact-deletion-cli branch from 1ed0fe3 to afe4895 Compare October 21, 2019 12:16
cmd/cli/main.go Show resolved Hide resolved
cmd/cli/main.go Show resolved Hide resolved
@beevee beevee requested review from litleleprikon and removed request for borovskyav October 22, 2019 13:43
@beevee beevee dismissed litleleprikon’s stale review October 22, 2019 13:44

No changes required

@beevee beevee removed the request for review from litleleprikon October 22, 2019 13:51
@beevee beevee merged commit 0f0da27 into master Oct 22, 2019
@beevee beevee deleted the feature/424-add-subscription-transfer-and-contact-deletion-cli branch October 22, 2019 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add subscription transfer and contact deletion to CLI
4 participants