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

Sendmail command #13079

Merged
merged 25 commits into from
Oct 24, 2020
Merged

Sendmail command #13079

merged 25 commits into from
Oct 24, 2020

Conversation

zhiburt
Copy link
Contributor

@zhiburt zhiburt commented Oct 8, 2020

Implements a sendmail command which sends a message to all users that are present in db.

Tented to close #12996

I am not versed in a code base so there may be some issues 😞 .

Thank you.

Usefull to have when you need to be confident that message was sent.
@codecov-io
Copy link

codecov-io commented Oct 8, 2020

Codecov Report

Merging #13079 into master will increase coverage by 0.07%.
The diff coverage is 1.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13079      +/-   ##
==========================================
+ Coverage   42.05%   42.12%   +0.07%     
==========================================
  Files         681      687       +6     
  Lines       75121    75632     +511     
==========================================
+ Hits        31594    31862     +268     
- Misses      38372    38547     +175     
- Partials     5155     5223      +68     
Impacted Files Coverage Δ
cmd/admin.go 0.00% <ø> (ø)
cmd/cmd.go 17.85% <0.00%> (-13.40%) ⬇️
cmd/mailer.go 0.00% <0.00%> (ø)
modules/private/mail.go 0.00% <0.00%> (ø)
routers/private/mail.go 0.00% <0.00%> (ø)
routers/private/internal.go 88.46% <100.00%> (+0.46%) ⬆️
modules/queue/helper.go 47.36% <0.00%> (-14.71%) ⬇️
routers/init.go 52.06% <0.00%> (-14.61%) ⬇️
modules/queue/setting.go 31.25% <0.00%> (-14.43%) ⬇️
services/gitdiff/gitdiff.go 67.39% <0.00%> (-7.50%) ⬇️
... and 72 more

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 e374bb7...af3cff6. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 8, 2020
Copy link
Member

@techknowlogick techknowlogick left a comment

Choose a reason for hiding this comment

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

Awesome!! Thanks so much for the PR :) We ❤️ new contributors.

A couple of bits of feedback:

  • Could you split this off into a separate file (admin.go is getting a bit long at this point), perhaps cmd/mailer.go?
  • Can you add checks that if either title or content is empty then error out?
  • Could you add a confirmation step (and perhaps a --force flag to bypass confirmation) so that emails don't accidentally get sent out.

@techknowlogick techknowlogick added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Oct 9, 2020
@techknowlogick techknowlogick added this to the 1.14.0 milestone Oct 9, 2020
cmd/admin.go Outdated Show resolved Hide resolved
@zhiburt
Copy link
Contributor Author

zhiburt commented Oct 9, 2020

Thank you for your message @techknowlogick.

According to your second point I could image that content/body may be empty what do you think?

cmd/admin.go Outdated Show resolved Hide resolved
cmd/mailer.go Outdated Show resolved Hide resolved
@techknowlogick
Copy link
Member

Perhaps you could add a warning when user is asked to confirm they want to send mail when subject or content is empty instead of my original suggestion of stopping send mail?

Print waring if it's empty or haven't been set up.
The warning will be skiped if there's a `--force` flag.
@zhiburt
Copy link
Contributor Author

zhiburt commented Oct 12, 2020

Just to notice if --force is passed warning will not be printed.
And I left title as required just because an empty email makes not a lot of sense?

Co-authored-by: 6543 <6543@obermui.de>
cmd/mailer.go Outdated Show resolved Hide resolved
IterateUsers uses batching by default.

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
cmd/mailer.go Outdated Show resolved Hide resolved
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
@zeripath
Copy link
Contributor

Sorry to jump in so late.

We need to decide what type of command this is.

If it is intended to communicate with a running Gitea we should create and use an internal api to call and communicate with the running server.

If, as it appears, it is intended not to communicate with a running Gitea you could have used the already available Async methods and just ran flush queues at the end of it.

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
@zhiburt
Copy link
Contributor Author

zhiburt commented Oct 19, 2020

If, as it appears, it is intended not to communicate with a running Gitea you could have used the already available Async methods and just ran flush queues at the end of it.

Thanks for the hint over Flush function

We need to decide what type of command this is.

If it is intended to communicate with a running Gitea we should create and use an internal api to call and communicate with the running server.

We could support 2 types of calls probably, which could be determined by a flag.

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
@zhiburt
Copy link
Contributor Author

zhiburt commented Oct 22, 2020

@lunny

I think we should do that via internal API but not push to the queue directly as @zeripath said.

@zeripath

If it is intended to communicate with a running Gitea we should create and use an internal api to call and communicate with the running server.

I've started looking at the API and as I see to use an API as an admin we need to authenticate yourself right?
So it would increase an amount of arguments at the end of the day maybe there's no reason to?

And why actually you consider here it's appropriate to be attached to a running Gitea where others admin commands doesn't what is the benefit?

And if we expose such API in my opinion it just make more sense to provide a page with a form for this purpose and that is it.

@zhiburt zhiburt requested review from 6543 and lafriks October 22, 2020 17:40
cmd/admin.go Outdated Show resolved Hide resolved
cmd/admin.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot 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, 2020
Co-authored-by: 6543 <6543@obermui.de>
@lunny
Copy link
Member

lunny commented Oct 23, 2020

If the configuration sets the mailer queue as levelqueue, the command will fail when start, except queue is a network service.
But if we always use an internal API to do that, it will always work.
The internal API is in /api/v1/internal which can only be visit via the token saved in app.ini. It has no documentation and maybe changed if needed.

@zhiburt
Copy link
Contributor Author

zhiburt commented Oct 23, 2020

Thanks for the clarification.

So I've updated the PR to use a private API

@GiteaBot GiteaBot 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, 2020
@techknowlogick
Copy link
Member

🚀

@techknowlogick techknowlogick merged commit a1952af into go-gitea:master Oct 24, 2020
ivanvc added a commit to ivanvc/gitea that referenced this pull request Oct 27, 2020
…s-stored-in-email-address-table

* origin/master:
  [UI] Hide consecutive additions and removals of the same label (go-gitea#13315)
  [skip ci] Updated translations via Crowdin
  Fix send mail (go-gitea#13312)
  [skip ci] Updated translations via Crowdin
  Deny wrong pull (go-gitea#13308)
  Group Label Changed Comments in timeline (go-gitea#13304)
  [skip ci] Updated translations via Crowdin
  Attempt to handle unready PR in tests (go-gitea#13305)
  go-gitea#12897 - add mastodon provider (go-gitea#13293)
  [skip ci] Updated translations via Crowdin
  Fix Storage mapping (go-gitea#13297)
  Update Mirror IsEmpty status on synchronize (go-gitea#13185)
  Fix bug isEnd detection on getIssues/getPullRequests (go-gitea#13299)
  systemd service: Add commented PATH environment option for Git prefix (go-gitea#13170)
  Sendmail command (go-gitea#13079)
  Various UI and arc-green fixes (go-gitea#13291)
@go-gitea go-gitea locked and limited conversation to collaborators Dec 14, 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/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A sub command to send admin email to all the users.
9 participants