Skip to content
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
35 changes: 25 additions & 10 deletions daikoku/app/fr/maif/daikoku/controllers/TeamController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import fr.maif.daikoku.actions.{
DaikokuActionMaybeWithGuest
}
import fr.maif.daikoku.audit.AuditTrailEvent
import fr.maif.daikoku.controllers.authorizations.async._
import fr.maif.daikoku.domain._
import fr.maif.daikoku.controllers.authorizations.async.*
import fr.maif.daikoku.domain.*
import fr.maif.daikoku.domain.json.TeamFormat
import fr.maif.daikoku.env.Env
import fr.maif.daikoku.login.{LdapConfig, LdapSupport}
import fr.maif.daikoku.services.DeletionService
import fr.maif.daikoku.storage.drivers.postgres.PostgresDataStore
import fr.maif.daikoku.utils.Cypher.{decrypt, encrypt}
import fr.maif.daikoku.utils.future.EnhancedObject
import fr.maif.daikoku.utils.{IdGenerator, Translator}
Expand All @@ -24,8 +25,8 @@ import org.apache.pekko.stream.scaladsl.{Sink, Source}
import org.joda.time.DateTime
import org.mindrot.jbcrypt.BCrypt
import play.api.i18n.I18nSupport
import play.api.libs.json._
import play.api.mvc._
import play.api.libs.json.*
import play.api.mvc.*

import scala.concurrent.{ExecutionContext, Future}

Expand Down Expand Up @@ -1049,14 +1050,28 @@ class TeamController(
"@{user.name} has find User with many attributes (@{u.id})"
)
)(teamId, ctx) { _ =>
env.dataStore.userRepo
.findOne(
Json.obj(
"_deleted" -> false
) ++ (ctx.request.body \ "attributes").as[JsObject]
val attributes = (ctx.request.body \ "attributes").as[JsObject]
val (clause, params, _) =
attributes.fields.foldLeft(("", Seq.empty[String], 1)) {
case ((acc, values, idx), (key, value)) =>
val separator = if (acc.isEmpty) "" else " AND "
(
s"$acc${separator}lower(content ->> '$key') = lower($$$idx)",
values :+ value.as[String],
idx + 1
)
}

env.dataStore
.asInstanceOf[PostgresDataStore]
.queryOneRaw(
query =
s"SELECT content FROM users WHERE _deleted = false AND $clause",
name = "content",
params = params
)
.map {
case Some(user) => Ok(user.asJson)
case Some(user) => Ok(user.as(json.UserFormat).asSimpleJson)
case None => NotFound(Json.obj("error" -> "user not found"))
}
}
Expand Down
118 changes: 118 additions & 0 deletions daikoku/javascript/tests/specs/teams.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,122 @@ test("un utilisateur peut creer une équipe si la securité de reation d'équipe

await page.getByRole('button', { name: 'Mes équipes' }).click();
await expect(page.locator('.modal-footer').getByRole('button', { name: 'Créer une équipe' })).toBeHidden();
});

test("Inviter un utilisateur dans une équipe sans caseSensitive", async ({ page }) => {
await page.goto(ACCUEIL);
await loginAs(MICHAEL, page);
await page.getByRole('button', { name: 'Mes équipes' }).click();
await page.locator('#portal-root').getByRole('link', { name: 'API Division' }).click();
await page.getByText('Membres').click();
await page.getByRole('button', { name: 'Inviter un collaborateur' }).click();
await page.getByRole('textbox', { name: 'Email' }).fill('Andy.BERNARD@dundermifflin.com');
await page.getByRole('button', { name: 'Rechercher', exact: true }).click();
await page.waitForTimeout(1000);
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Déconnexion' }).click();
await page.waitForTimeout(1000);
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Se connecter' }).click();
await page.locator('input[name="username"]').click();
await page.locator('input[name="username"]').fill('Andy.BERNARD@dundermifflin.com');
await page.locator('input[name="password"]').fill('password');
await page.getByRole('button', { name: 'Se connecter' }).click();
await page.waitForTimeout(1000);
await page.getByRole('link', { name: 'Accès aux notifications' }).click();
await page.getByRole('button', { name: 'Rejeter' }).click();
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Déconnexion' }).click();


await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Se connecter' }).click();
await page.locator('input[name="username"]').fill('michael.scott@dundermifflin.com');
await page.locator('input[name="password"]').fill('password');
await page.getByRole('button', { name: 'Se connecter' }).click();

await page.getByRole('button', { name: 'Mes équipes' }).click();
await page.getByRole('link', { name: 'API Division' }).click();
await page.getByText('Membres').click();
await page.getByRole('button', { name: 'Inviter un collaborateur' }).click();
await page.getByRole('textbox', { name: 'Email' }).fill('andy.bernard@dundermifflin.com');
await page.getByRole('button', { name: 'Rechercher', exact: true }).click();
await page.getByText('En attente (1)').click();
await page.getByText('Andy Bernard', { exact: true }).click();
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Déconnexion' }).click();
await page.waitForTimeout(1000);
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Se connecter' }).click();
await page.locator('input[name="username"]').fill('Andy.BERNARD@dundermifflin.com');
await page.locator('input[name="password"]').fill('password');
await page.getByRole('button', { name: 'Se connecter' }).click();
await page.waitForTimeout(1000);
await page.getByRole('link', { name: 'Accès aux notifications' }).click();
await page.getByRole('button', { name: 'Accepter' }).click();
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Déconnexion' }).click();
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Se connecter' }).click();
await page.locator('input[name="username"]').fill('michael.scott@dundermifflin.com');
await page.locator('input[name="password"]').fill('password');
await page.getByRole('button', { name: 'Se connecter' }).click();
await page.getByRole('button', { name: 'Mes équipes' }).click();
await page.getByRole('link', { name: 'API Division' }).click();
await page.getByText('Membres').click();
await page.getByRole('main').getByText('Membres').click();
await page.getByText('Andy Bernard').click();
await expect(page.getByRole('listitem', { name: 'Andy Bernard' })).toHaveText('Andy Bernard');

await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Paramètres Daikoku' }).click();
await page.getByText('Utilisateurs', { exact: true }).click();
await page.getByText('Andy Bernard').click();
});

test("inviter un utilisateur plusieurs fois en case insensitive ne doit pas créer plusieurs users dans le tenant", async ({ page }) => {

await page.goto(ACCUEIL);
await loginAs(MICHAEL, page);
await page.getByRole('button', { name: 'Mes équipes' }).click();
await page.locator('#portal-root').getByRole('link', { name: 'API Division' }).click();
await page.getByText('Membres').click();
await page.getByRole('button', { name: 'Inviter un collaborateur' }).click();
await page.getByRole('textbox', { name: 'Email' }).fill('andy.bernard@dundermifflin.com');
await page.getByRole('button', { name: 'Rechercher', exact: true }).click();
await page.waitForTimeout(1000)
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Déconnexion' }).click();
await page.waitForTimeout(1000)
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Se connecter' }).click();
await page.locator('input[name="username"]').fill('andy.bernard@dundermifflin.com');
await page.locator('input[name="password"]').fill('password');
await page.getByRole('button', { name: 'Se connecter' }).click();
await page.waitForTimeout(1000)
await page.getByRole('link', { name: 'Accès aux notifications' }).click();
await page.getByRole('button', { name: 'Rejeter' }).click();
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Déconnexion' }).click();
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Se connecter' }).click();
await page.locator('input[name="username"]').fill('michael.scott@dundermifflin.com');
await page.locator('input[name="password"]').fill('password');
await page.getByRole('button', { name: 'Se connecter' }).click();
await page.getByRole('button', { name: 'user menu' }).click();
await page.waitForTimeout(1000)
await page.getByRole('button', { name: 'Mes équipes' }).click();
await page.getByRole('link', { name: 'API Division' }).click();
await page.getByText('Membres').click();
await page.getByRole('button', { name: 'Inviter un collaborateur' }).click();
await page.getByRole('textbox', { name: 'Email' }).click();
await page.getByRole('textbox', { name: 'Email' }).fill('andy.bernard@dundermifflin.com');
await page.getByRole('button', { name: 'Rechercher', exact: true }).click();
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Dunder Mifflin' }).click();
await page.getByRole('button', { name: 'user menu' }).click();
await page.getByRole('link', { name: 'Paramètres Daikoku' }).click();
await page.getByText('Utilisateurs', { exact: true }).click();
expect(page.getByText('Andy Bernard').first()).toBeVisible;
expect(page.getByText('Andy Bernard').nth(1)).not.toBeAttached();
});
Loading