Skip to content

Commit

Permalink
Adding ability to disable mailer for super users
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed May 14, 2024
1 parent 909bb7e commit 0df9a20
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
13 changes: 13 additions & 0 deletions templates/userAdd.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@
/>
</div>
</div>
{{if (checkPermission .UserPermissions "SuperUser")}}
<div class="field">
<label class="label" for="disablesendemail">Disable email sending (WARNING: only select this if you know what you are doing and understand the consequences)</label>
<div class="control">
<input
id="disablesendemail"
class="checkbox"
type="checkbox"
name="disablesendemail"
/>
</div>
</div>
{{end}}
<button class="button is-info" onclick="addUser()" id="addUserButton"><i class="fa-solid fa-user-plus"></i>&ensp;
Add User</button>
</form>
Expand Down
13 changes: 13 additions & 0 deletions templates/users.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@
/>
</div>
</div>
{{if (checkPermission .UserPermissions "SuperUser")}}
<div class="field">
<label class="label" for="disablesendemail">Disable email sending (WARNING: only select this if you know what you are doing and understand the consequences)</label>
<div class="control">
<input
id="disablesendemail"
class="checkbox"
type="checkbox"
name="disablesendemail"
/>
</div>
</div>
{{end}}
<button class="button is-info" onclick="addUser()" id="addUserButton"><i class="fa-solid fa-user-plus"></i>&ensp;
Add User</button>
</form>
Expand Down
47 changes: 32 additions & 15 deletions views/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import (
"time"

"github.com/labstack/echo/v4"
"gopkg.in/guregu/null.v4"

"github.com/ystv/web-auth/infrastructure/mail"
"github.com/ystv/web-auth/infrastructure/permission"
"github.com/ystv/web-auth/permission/permissions"
"github.com/ystv/web-auth/templates"
"github.com/ystv/web-auth/user"
"github.com/ystv/web-auth/utils"
"gopkg.in/guregu/null.v4"
)

type (
Expand Down Expand Up @@ -357,11 +360,25 @@ func (v *Views) UserAddFunc(c echo.Context) error {
return fmt.Errorf("failed to parse form for userAdd: %w", err)
}

firstName := c.Request().FormValue("firstname")
lastName := c.Request().FormValue("lastname")
username := c.Request().FormValue("username")
universityUsername := c.Request().FormValue("universityusername")
email := c.Request().FormValue("email")
firstName := c.FormValue("firstname")
lastName := c.FormValue("lastname")
username := c.FormValue("username")
universityUsername := c.FormValue("universityusername")
email := c.FormValue("email")
tempDisableSendEmail := c.FormValue("disablesendemail")
sendEmail := true
if tempDisableSendEmail == "on" && func() bool {
m := permission.SufficientPermissionsFor(permissions.SuperUser)

for _, perm := range c1.User.Permissions {
if m[perm.Name] {
return true
}
}
return false
}() {
sendEmail = false
}

password, err := utils.GenerateRandom(utils.GeneratePassword)
if err != nil {
Expand Down Expand Up @@ -398,7 +415,7 @@ func (v *Views) UserAddFunc(c echo.Context) error {

mailer := v.mailer.ConnectMailer()

if mailer != nil {
if mailer != nil && sendEmail {
template, err := v.template.GetEmailTemplate(templates.SignupEmailTemplate)
if err != nil {
return fmt.Errorf("failed to get email in addUser: %w", err)
Expand Down Expand Up @@ -460,15 +477,15 @@ func (v *Views) UserEditFunc(c echo.Context) error {
return fmt.Errorf("failed to parse form for userEdit: %w", err)
}

firstName := c.Request().FormValue("firstname")
nickname := c.Request().FormValue("nickname")
lastName := c.Request().FormValue("lastname")
username := c.Request().FormValue("username")
universityUsername := c.Request().FormValue("universityusername")
LDAPUsername := c.Request().FormValue("ldapusername")
email := c.Request().FormValue("email")
firstName := c.FormValue("firstname")
nickname := c.FormValue("nickname")
lastName := c.FormValue("lastname")
username := c.FormValue("username")
universityUsername := c.FormValue("universityusername")
LDAPUsername := c.FormValue("ldapusername")
email := c.FormValue("email")
// login type can't be changed yet but the infrastructure is in
loginType := c.Request().FormValue("logintype")
loginType := c.FormValue("logintype")
_ = loginType

if firstName != user1.Firstname && len(firstName) > 0 {
Expand Down

0 comments on commit 0df9a20

Please sign in to comment.