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

Display name for organizations #2869

Merged
merged 9 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
- Added the shortcut to copy the currently hovered cell id (CTRL + I) to non-volume-tracings, too. [#2726](https://github.com/scalableminds/webknossos/pull/2726)
- Added permission for team managers to refresh datasets. [#2688](https://github.com/scalableminds/webknossos/pull/2688)
- Added backend-unit-test setup and a first test for NML validation. [#2829](https://github.com/scalableminds/webknossos/pull/2829)
- Added displayName for organizations [#2869](https://github.com/scalableminds/webknossos/pull/2869)


### Changed
Expand Down
1 change: 1 addition & 0 deletions MIGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ User-facing changes are documented in the [changelog](CHANGELOG.md).
### Postgres Evolutions:
- [013-add-logoUrl.sql](conf/evolutions/013-add-logoUrl.sql)
- [014-equalize-schema-and-evolutions.sql](conf/evolutions/014-equalize-schema-and-evolutions.sql)
- [015-add-organization-displayname.sql](conf/evolutions/015-add-organization-displayname.sql)

## [18.07.0](https://github.com/scalableminds/webknossos/releases/tag/18.07.0) - 2018-07-05
First release
17 changes: 10 additions & 7 deletions app/controllers/Authentication.scala
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,12 @@ class Authentication @Inject()(
val loginInfo = LoginInfo(CredentialsProvider.ID, email)
var errors = List[String]()
val firstName = normalizeName(signUpData.firstName).getOrElse {
errors ::= Messages("user.firstName.invalid"); ""
errors ::= Messages("user.firstName.invalid");
""
}
val lastName = normalizeName(signUpData.lastName).getOrElse {
errors ::= Messages("user.lastName.invalid"); ""
errors ::= Messages("user.lastName.invalid");
""
}
UserService.retrieve(loginInfo).toFox.futureBox.flatMap {
case Full(_) =>
Expand All @@ -390,7 +392,7 @@ class Authentication @Inject()(
organization <- createOrganization(signUpData.organization) ?~> Messages("organization.create.failed")
user <- UserService.insert(organization.name, email, firstName, lastName, signUpData.password, isActive = true, teamRole = true,
loginInfo, passwordHasher.hash(signUpData.password), isAdmin = true)
_ <- createOrganizationFolder(signUpData.organization, loginInfo)
_ <- createOrganizationFolder(organization.name, loginInfo)
} yield Ok
}
case f: Failure => Fox.failure(f.msg)
Expand All @@ -409,15 +411,16 @@ class Authentication @Inject()(
Fox.sequenceOfFulls(List(noOrganizationPresent, configurationFlagSet, userIsSuperUser)).map(_.headOption).toFox
}

private def createOrganization(organizationName: String) = {
val organization = OrganizationSQL(ObjectId.generate, organizationName, "", "")
val organizationTeam = TeamSQL(ObjectId.generate, organization._id, organization.name, isOrganizationTeam = true)
private def createOrganization(organizationDisplayName: String) =
for {
organizationName <- normalizeName(organizationDisplayName).toFox ?~> "invalid organization name"
organization = OrganizationSQL(ObjectId.generate, organizationName.replaceAll(" ", "_"), "", "", organizationDisplayName)
organizationTeam = TeamSQL(ObjectId.generate, organization._id, organization.name, isOrganizationTeam = true)
_ <- OrganizationSQLDAO.insertOne(organization)(GlobalAccessContext)
_ <- TeamSQLDAO.insertOne(organizationTeam)(GlobalAccessContext)
_ <- InitialDataService.insertLocalDataStoreIfEnabled
} yield organization
}


private def createOrganizationFolder(organizationName: String, loginInfo: LoginInfo)(implicit request: RequestHeader) = {
def sendRPCToDataStore(dataStore: DataStoreSQL, token: String) = {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/InitialDataController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Sampletown
Samplecountry
"""
val organizationTeamId = BSONObjectID.generate
val defaultOrganization = Organization("/assets/images/mpi-logos.svg", additionalInformation, "Connectomics department", List(), organizationTeamId)
val defaultOrganization = Organization("MPI for Brain Research", "/assets/images/mpi-logos.svg", additionalInformation, "Connectomics department", List(), organizationTeamId)
val organizationTeam = Team(defaultOrganization.name, defaultOrganization.name, organizationTeamId)
val organizationTeamSQL = TeamSQL(ObjectId.fromBsonId(organizationTeamId), ObjectId.fromBsonId(defaultOrganization._id), defaultOrganization.name, isOrganizationTeam = true)

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/OrganizationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OrganizationController @Inject()(val messagesApi: MessagesApi) extends Con
for {
allOrgs <- OrganizationDAO.findAll(GlobalAccessContext)
} yield {
Ok(Json.toJson(allOrgs.map(org => Json.obj("id" -> org.id, "name" -> org.name, "additionalInformation" -> org.additionalInformation))))
Ok(Json.toJson(allOrgs.map(org => Json.obj("id" -> org.id, "name" -> org.name, "additionalInformation" -> org.additionalInformation, "displayname" -> org.displayName))))
}
}

Expand Down
11 changes: 8 additions & 3 deletions app/models/team/Organization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ case class OrganizationSQL(
name: String,
additionalInformation: String,
logoUrl: String,
displayName: String,
created: Long = System.currentTimeMillis(),
isDeleted: Boolean = false
)
Expand All @@ -35,7 +36,8 @@ object OrganizationSQL {
ObjectId.fromBsonId(o._id),
o.name,
o.additionalInformation,
o.logoUrl
o.logoUrl,
o.displayName
)
)
}
Expand All @@ -56,6 +58,7 @@ object OrganizationSQLDAO extends SQLDAO[OrganizationSQL, OrganizationsRow, Orga
r.name,
r.additionalinformation,
r.logourl,
r.displayname,
r.created.getTime,
r.isdeleted)
)
Expand All @@ -77,8 +80,8 @@ object OrganizationSQLDAO extends SQLDAO[OrganizationSQL, OrganizationsRow, Orga
for {
r <- run(

sqlu"""insert into webknossos.organizations(_id, name, additionalInformation, logoUrl, created, isDeleted)
values(${o._id.id}, ${o.name}, ${o.additionalInformation}, ${o.logoUrl}, ${new java.sql.Timestamp(o.created)}, ${o.isDeleted})
sqlu"""insert into webknossos.organizations(_id, name, additionalInformation, logoUrl, displayName, created, isDeleted)
values(${o._id.id}, ${o.name}, ${o.additionalInformation}, ${o.logoUrl}, ${o.displayName}, ${new java.sql.Timestamp(o.created)}, ${o.isDeleted})
""")
} yield ()

Expand All @@ -92,6 +95,7 @@ object OrganizationSQLDAO extends SQLDAO[OrganizationSQL, OrganizationsRow, Orga


case class Organization(
displayName: String,
logoUrl: String,
additionalInformation: String,
name: String,
Expand All @@ -116,6 +120,7 @@ object Organization extends FoxImplicits {
teamBsonIds <- Fox.combined(teams.map(_._id.toBSONObjectId.toFox))
} yield {
Organization(
o.displayName,
o.logoUrl,
o.additionalInformation,
o.name,
Expand Down
8 changes: 8 additions & 0 deletions conf/evolutions/015-add-organization-displayname.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- https://github.com/scalableminds/webknossos/pull/2869

START TRANSACTION;
DROP VIEW webknossos.organizations_;
ALTER TABLE webknossos.organizations ADD COLUMN displayName VARCHAR(1024) NOT NULL DEFAULT '';
CREATE VIEW webknossos.organizations_ AS SELECT * FROM webknossos.organizations WHERE NOT isDeleted;
UPDATE webknossos.organizations SET displayName = name;
COMMIT TRANSACTION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
START TRANSACTION;
DROP VIEW webknossos.organizations_;
ALTER TABLE webknossos.organizations DROP COLUMN displayName;
CREATE VIEW webknossos.organizations_ AS SELECT * FROM webknossos.organizations WHERE NOT isDeleted;
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,created,isdeleted
'5ab0c6a674d0af7b003b23ac','Organization_X','lorem ipsum','/assets/images/mpi-logos.svg','2018-03-20 09:30:31.91+01',f
'6bb0c6a674d0af7b003b23bd','Organization_Y','foo bar','/assets/images/mpi-logos.svg','2018-03-24 09:30:31.91+01',f
_id,name,additionalinformation,logoUrl,displayName,created,isdeleted
'5ab0c6a674d0af7b003b23ac','Organization_X','lorem ipsum','/assets/images/mpi-logos.svg','Organization_X','2018-03-20 09:30:31.91+01',f
'6bb0c6a674d0af7b003b23bd','Organization_Y','foo bar','/assets/images/mpi-logos.svg','Organization_Y','2018-03-24 09:30:31.91+01',f
1 change: 1 addition & 0 deletions tools/postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ CREATE TABLE webknossos.organizations(
name VARCHAR(256) NOT NULL,
additionalInformation VARCHAR(2048) NOT NULL DEFAULT '',
logoUrl VARCHAR(2048) NOT NULL DEFAULT '',
displayName VARCHAR(1024) NOT NULL DEFAULT '',
created TIMESTAMPTZ NOT NULL DEFAULT NOW(),
isDeleted BOOLEAN NOT NULL DEFAULT false
);
Expand Down