Skip to content

Feature - role emails #3920

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Feature - role emails #3920

wants to merge 11 commits into from

Conversation

bomoko
Copy link
Contributor

@bomoko bomoko commented May 28, 2025

General Checklist

  • Affected Issues have been mentioned in the Closing issues section
  • Documentation has been written/updated
  • PR title is ready for inclusion in changelog

Database Migrations

  • If your PR contains a database migation, it MUST be the latest in date order alphabetically

Description

This PR will add the ability to email users when their organization roles change.

@bomoko bomoko added this to the 2.26.0 milestone May 28, 2025
*/
exports.up = function(knex) {
return knex.schema.alterTable('user', function(table) {
table.boolean('org_email_optin').notNullable().defaultTo(true);
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth changing this up a bit now to make further options in the future, thinking things like

table.boolean('opt_email_org_role').notNullable().defaultTo(true); // when a users role within the organization management changes
table.boolean('opt_email_sshkey').notNullable().defaultTo(true); // when an ssh key is added or removed from the user
table.boolean('opt_email_group_role').notNullable().defaultTo(false); // when the users role within a group is changed. this should probably default to false because it could be quite noisy for some users

Copy link
Member

@shreddedbacon shreddedbacon Jun 3, 2025

Choose a reason for hiding this comment

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

Also note with the opt_email_group_role possible notifications, another reason for default false would be for some of AIO customers that may use other systems for managing users that could already send these notifications. having it as default opt out would be best. and then users would be able to opt in specifically for this.

@@ -29,6 +29,7 @@ export interface User {
admin?: boolean;
organizationRole?: string;
platformRoles?: [string];
emailOptIn?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if this should be an interface, to allow for future expansion

interface IEmailNotifications {
  organizationRoleChanges?: boolean;
  sshKeyChanges?: boolean;
  groupRoleChanges?: boolean;
}

export interface User {
  ...
  emailNotifications?: IEmailNotifications;
}


// Here we deal explicitly with a class of 'user_action' events
if notification.Meta.Level == "user_action" {
if notification.Meta.Event == "api:addAdminToOrganization" {
Copy link
Member

Choose a reason for hiding this comment

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

This currently only fires on if a user is added as a manager to an organization. What about removal (https://github.com/uselagoon/lagoon/blob/v2.25.0/services/api/src/resources/user/resolvers.ts#L409)

Additionally, it could be worth notifying on the following:
Would we want to notify users if their platform roles changed? Maybe? This would probably be non-optional though so we don't have to expose the option to adjust it to general users

Would probably be good to notify when ssh keys are added or removed from an account, github does this, others probably do too

Possible future notify if a group role was changed? These actual addUserToGroup and removeUserFromGroup resolvers may need new logic in them to check if the group/role are unchanged though, otherwise if you run the same command twice with the same inputs the action is still performed and the user would receive an email saying their role was changed to the same role.

@@ -485,10 +487,23 @@ export const addAdminToOrganization: ResolverFn = async (
details: `${user.email} role ${role}`,
},
};

var addAdminToOrganizationEmail = true;
Copy link
Member

Choose a reason for hiding this comment

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

rather than have the payload flag being addAdminToOrganizationEmail would be more generic to have it be named sendUserEmail and then if the other optional email notifications are added in the future, the logic would be to determine which type of notification it is in the resolver and set this flag.

then the logs2notifications service useraction event handler would only need to check if sendUserEmail=true

Comment on lines +11 to +34
type addAdmintoOrganizationUser struct {
Id string `json:"id"`
Email string `json:"email"`
Organization int `json:"organization"`
Role string `json:"role"`
}

type addAdminToOrganizationResource struct {
Id int `json:"id"`
Type string `json:"type"`
Details string `json:"details"` // stores the org name
}

// There is also a third payload struct called "linkedResource" which we could use, but it seems redundant

type addAdminToOrganization struct {
Meta struct {
Payload struct {
AddAdminToOrganizationEmail bool `json:"addAdminToOrganizationEmail"`
User addAdmintoOrganizationUser `json:"user"`
Resource addAdminToOrganizationResource `json:"resource"`
} `json:"payload"`
} `json:"meta"`
}
Copy link
Member

Choose a reason for hiding this comment

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

When auditLogs were added, we set up a new data structure in the activity payload that contained information specific to this.

We should probably do something similar for the email notifications in the resolvers that would send emails with a new structure that contains this payload data. rather than relying on information that may or may not be present in all other resolvers.

In a previous comment I mentioned replacing addAdminToOrganizationEmail with sendUserEmail, but it could even be that if the new payload is in the message then send the email instead. No need for a specific flag then, as the injected payload could be "the flag"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants