Skip to content

Commit

Permalink
Only notify project owner on project overtime (#7842)
Browse files Browse the repository at this point in the history
* add migration adn revision

* only notify project owner about project overtime

* add migration entry

* add changelog entry

* fix evolution & schema file

* remove overtimemailinglist from organizations.csv dummy data used for testing

---------

Co-authored-by: Florian M <fm3@users.noreply.github.com>
  • Loading branch information
MichaelBuessemeyer and fm3 committed May 30, 2024
1 parent d3b0638 commit 5818b61
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- When downloading + reuploading an annotation that is based on a segmentation layer with active mapping, that mapping is now still be selected after the reupload. [#7822](https://github.com/scalableminds/webknossos/pull/7822)

### Changed
- From now on only project owner get a notification email upon project overtime. The organization specific email list `overTimeMailingList` was removed. [#7842](https://github.com/scalableminds/webknossos/pull/7842)

### Fixed
- Fixed a bug where brushing on a fallback segmentation with active mapping and with segment index file would lead to failed saves. [#7833](https://github.com/scalableminds/webknossos/pull/7833)
Expand Down
1 change: 1 addition & 0 deletions MIGRATIONS.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ User-facing changes are documented in the [changelog](CHANGELOG.released.md).

- [114-ai-models.sql](conf/evolutions/114-ai-models.sql)
- [115-annotation-locked-by-user.sql](conf/evolutions/115-annotation-locked-by-user.sql)
- [116-drop-overtimemailinglist.sql](conf/evolutions/116-drop-overtimemailinglist.sql)
8 changes: 2 additions & 6 deletions app/mail/DefaultMails.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ class DefaultMails @Inject()(conf: WkConf) {
recipients = List(recipient)
)

def overLimitMail(user: User,
projectName: String,
taskId: String,
annotationId: String,
recipients: List[String]): Mail =
def overLimitMail(user: User, projectName: String, taskId: String, annotationId: String, projectOwner: String): Mail =
Mail(
from = defaultSender,
subject = s"WEBKNOSSOS | Time limit reached. ${user.abbreviatedName} in $projectName",
bodyHtml = html.mail.notifyAdminTimeLimit(user.name, projectName, taskId, annotationId, uri).body,
recipients = recipients
recipients = List(projectOwner)
)

def newUserMail(name: String, recipient: String, enableAutoVerify: Boolean): Mail =
Expand Down
6 changes: 2 additions & 4 deletions app/models/organization/Organization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ case class Organization(
includedStorageBytes: Option[Long], // None means unlimited
_rootFolder: ObjectId,
newUserMailingList: String = "",
overTimeMailingList: String = "",
enableAutoVerify: Boolean = false,
lastTermsOfServiceAcceptanceTime: Option[Instant] = None,
lastTermsOfServiceAcceptanceVersion: Int = 0,
Expand Down Expand Up @@ -59,7 +58,6 @@ class OrganizationDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionCont
r.includedstorage,
ObjectId(r._Rootfolder),
r.newusermailinglist,
r.overtimemailinglist,
r.enableautoverify,
r.lasttermsofserviceacceptancetime.map(Instant.fromSql),
r.lasttermsofserviceacceptanceversion,
Expand Down Expand Up @@ -102,11 +100,11 @@ class OrganizationDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionCont
for {
_ <- run(q"""INSERT INTO webknossos.organizations
(_id, name, additionalInformation, logoUrl, displayName, _rootFolder,
newUserMailingList, overTimeMailingList, enableAutoVerify,
newUserMailingList, enableAutoVerify,
pricingplan, paidUntil, includedusers, includedstorage, lastTermsOfServiceAcceptanceTime, lastTermsOfServiceAcceptanceVersion, created, isDeleted)
VALUES
(${o._id}, ${o.name}, ${o.additionalInformation}, ${o.logoUrl}, ${o.displayName}, ${o._rootFolder},
${o.newUserMailingList}, ${o.overTimeMailingList}, ${o.enableAutoVerify},
${o.newUserMailingList}, ${o.enableAutoVerify},
${o.pricingPlan}, ${o.paidUntil}, ${o.includedUsers}, ${o.includedStorageBytes}, ${o.lastTermsOfServiceAcceptanceTime},
${o.lastTermsOfServiceAcceptanceVersion}, ${o.created}, ${o.isDeleted})
""".asUpdate)
Expand Down
3 changes: 0 additions & 3 deletions app/models/organization/OrganizationService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ class OrganizationService @Inject()(organizationDAO: OrganizationDAO,
} yield ownerEmail
}

def overTimeMailRecipient(organization: Organization)(implicit ctx: DBAccessContext): Fox[String] =
fallbackOnOwnerEmail(organization.overTimeMailingList, organization)

def newUserMailRecipient(organization: Organization)(implicit ctx: DBAccessContext): Fox[String] =
fallbackOnOwnerEmail(organization.newUserMailingList, organization)

Expand Down
6 changes: 2 additions & 4 deletions app/models/user/time/TimeSpanService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ class TimeSpanService @Inject()(annotationDAO: AnnotationDAO,
project <- projectDAO.findOne(task._project)
annotationTime <- annotation.tracingTime ?~> "no annotation.tracingTime"
timeLimit <- project.expectedTime ?~> "no project.expectedTime"
organization <- organizationDAO.findOne(user._organization)(GlobalAccessContext)
projectOwner <- userService.findOneCached(project._owner)(GlobalAccessContext)
projectOwnerEmail <- userService.emailFor(projectOwner)(GlobalAccessContext)
mailRecipient <- organizationService.overTimeMailRecipient(organization)(GlobalAccessContext)
} yield {
if (annotationTime >= timeLimit && annotationTime - time.toMillis < timeLimit) {
Mailer ! Send(defaultMails
.overLimitMail(user, project.name, task._id.toString, annotation.id, List(mailRecipient, projectOwnerEmail)))
Mailer ! Send(
defaultMails.overLimitMail(user, project.name, task._id.toString, annotation.id, projectOwnerEmail))
}
}

Expand Down
26 changes: 26 additions & 0 deletions conf/evolutions/116-drop-overtimemailinglist.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
START TRANSACTION;

do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 115, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql;

DROP VIEW webknossos.userInfos;
DROP VIEW webknossos.organizations_;

ALTER TABLE webknossos.organizations DROP COLUMN overTimeMailingList;



CREATE VIEW webknossos.organizations_ AS SELECT * FROM webknossos.organizations WHERE NOT isDeleted;

CREATE VIEW webknossos.userInfos AS
SELECT
u._id AS _user, m.email, u.firstName, u.lastname, o.displayName AS organization_displayName,
u.isDeactivated, u.isDatasetManager, u.isAdmin, m.isSuperUser,
u._organization, o.name AS organization_name, u.created AS user_created,
m.created AS multiuser_created, u._multiUser, m._lastLoggedInIdentity, u.lastActivity, m.isEmailVerified
FROM webknossos.users_ u
JOIN webknossos.organizations_ o ON u._organization = o._id
JOIN webknossos.multiUsers_ m on u._multiUser = m._id;

UPDATE webknossos.releaseInformation SET schemaVersion = 116;

COMMIT TRANSACTION;
24 changes: 24 additions & 0 deletions conf/evolutions/reversions/116-drop-overtimemailinglist.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
START TRANSACTION;

do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 116, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql;

DROP VIEW webknossos.userInfos;
DROP VIEW webknossos.organizations_;

ALTER TABLE webknossos.organizations ADD COLUMN overTimeMailingList VARCHAR(512) NOT NULL DEFAULT '';

CREATE VIEW webknossos.organizations_ AS SELECT * FROM webknossos.organizations WHERE NOT isDeleted;

CREATE VIEW webknossos.userInfos AS
SELECT
u._id AS _user, m.email, u.firstName, u.lastname, o.displayName AS organization_displayName,
u.isDeactivated, u.isDatasetManager, u.isAdmin, m.isSuperUser,
u._organization, o.name AS organization_name, u.created AS user_created,
m.created AS multiuser_created, u._multiUser, m._lastLoggedInIdentity, u.lastActivity, m.isEmailVerified
FROM webknossos.users_ u
JOIN webknossos.organizations_ o ON u._organization = o._id
JOIN webknossos.multiUsers_ m on u._multiUser = m._id;

UPDATE webknossos.releaseInformation SET schemaVersion = 115;

COMMIT TRANSACTION;
6 changes: 3 additions & 3 deletions test/db/organizations.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
_id,name,additionalinformation,logoUrl,displayName,_rootFolder,newusermailinglist,overtimemailinglist,enableautoverify,pricingPlan,paidUntil,includedUsers,includedStorage,lastStorageScanTime,created,isdeleted
'5ab0c6a674d0af7b003b23ac','Organization_X','lorem ipsum','/assets/images/mpi-logos.svg','Organization_X',570b9f4e4bb848d0885ea917,'','',f,'Custom',,,,,0,'2000-01-01 09:30:31.91+01','2018-03-20 09:30:31.91+01',f
'6bb0c6a674d0af7b003b23bd','Organization_Y','foo bar','/assets/images/mpi-logos.svg','Organization_Y','570b9f4e4bb848d088a83aef','','',f,'Custom',,,,,0,'2000-01-01 09:30:31.91+01','2018-03-24 09:30:31.91+01',f
_id,name,additionalinformation,logoUrl,displayName,_rootFolder,newusermailinglist,enableautoverify,pricingPlan,paidUntil,includedUsers,includedStorage,lastStorageScanTime,created,isdeleted
'5ab0c6a674d0af7b003b23ac','Organization_X','lorem ipsum','/assets/images/mpi-logos.svg','Organization_X',570b9f4e4bb848d0885ea917,'',f,'Custom',,,,,0,'2000-01-01 09:30:31.91+01','2018-03-20 09:30:31.91+01',f
'6bb0c6a674d0af7b003b23bd','Organization_Y','foo bar','/assets/images/mpi-logos.svg','Organization_Y','570b9f4e4bb848d088a83aef','',f,'Custom',,,,,0,'2000-01-01 09:30:31.91+01','2018-03-24 09:30:31.91+01',f
3 changes: 1 addition & 2 deletions tools/postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CREATE TABLE webknossos.releaseInformation (
schemaVersion BIGINT NOT NULL
);

INSERT INTO webknossos.releaseInformation(schemaVersion) values(115);
INSERT INTO webknossos.releaseInformation(schemaVersion) values(116);
COMMIT TRANSACTION;


Expand Down Expand Up @@ -323,7 +323,6 @@ CREATE TABLE webknossos.organizations(
displayName VARCHAR(1024) NOT NULL DEFAULT '',
_rootFolder CHAR(24) NOT NULL UNIQUE,
newUserMailingList VARCHAR(512) NOT NULL DEFAULT '',
overTimeMailingList VARCHAR(512) NOT NULL DEFAULT '',
enableAutoVerify BOOLEAN NOT NULL DEFAULT false,
pricingPlan webknossos.PRICING_PLANS NOT NULL DEFAULT 'Custom',
paidUntil TIMESTAMPTZ DEFAULT NULL,
Expand Down

0 comments on commit 5818b61

Please sign in to comment.