Skip to content

Commit d3dcf0b

Browse files
author
Gabriel Menant
committed
fix: uppercase
1 parent de3a54d commit d3dcf0b

File tree

2 files changed

+143
-10
lines changed

2 files changed

+143
-10
lines changed

daikoku/app/fr/maif/daikoku/controllers/TeamController.scala

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import fr.maif.daikoku.actions.{
99
DaikokuActionMaybeWithGuest
1010
}
1111
import fr.maif.daikoku.audit.AuditTrailEvent
12-
import fr.maif.daikoku.controllers.authorizations.async._
13-
import fr.maif.daikoku.domain._
12+
import fr.maif.daikoku.controllers.authorizations.async.*
13+
import fr.maif.daikoku.domain.*
1414
import fr.maif.daikoku.domain.json.TeamFormat
1515
import fr.maif.daikoku.env.Env
1616
import fr.maif.daikoku.login.{LdapConfig, LdapSupport}
1717
import fr.maif.daikoku.services.DeletionService
18+
import fr.maif.daikoku.storage.drivers.postgres.PostgresDataStore
1819
import fr.maif.daikoku.utils.Cypher.{decrypt, encrypt}
1920
import fr.maif.daikoku.utils.future.EnhancedObject
2021
import fr.maif.daikoku.utils.{IdGenerator, Translator}
@@ -24,8 +25,8 @@ import org.apache.pekko.stream.scaladsl.{Sink, Source}
2425
import org.joda.time.DateTime
2526
import org.mindrot.jbcrypt.BCrypt
2627
import play.api.i18n.I18nSupport
27-
import play.api.libs.json._
28-
import play.api.mvc._
28+
import play.api.libs.json.*
29+
import play.api.mvc.*
2930

3031
import scala.concurrent.{ExecutionContext, Future}
3132

@@ -1049,14 +1050,28 @@ class TeamController(
10491050
"@{user.name} has find User with many attributes (@{u.id})"
10501051
)
10511052
)(teamId, ctx) { _ =>
1052-
env.dataStore.userRepo
1053-
.findOne(
1054-
Json.obj(
1055-
"_deleted" -> false
1056-
) ++ (ctx.request.body \ "attributes").as[JsObject]
1053+
val attributes = (ctx.request.body \ "attributes").as[JsObject]
1054+
val (clause, params, _) =
1055+
attributes.fields.foldLeft(("", Seq.empty[String], 1)) {
1056+
case ((acc, values, idx), (key, value)) =>
1057+
val separator = if (acc.isEmpty) "" else " AND "
1058+
(
1059+
s"$acc${separator}lower(content ->> '$key') = lower($$$idx)",
1060+
values :+ value.as[String],
1061+
idx + 1
1062+
)
1063+
}
1064+
1065+
env.dataStore
1066+
.asInstanceOf[PostgresDataStore]
1067+
.queryOneRaw(
1068+
query =
1069+
s"SELECT content FROM users WHERE _deleted = false AND $clause",
1070+
name = "content",
1071+
params = params
10571072
)
10581073
.map {
1059-
case Some(user) => Ok(user.asJson)
1074+
case Some(user) => Ok(user.as(json.UserFormat).asSimpleJson)
10601075
case None => NotFound(Json.obj("error" -> "user not found"))
10611076
}
10621077
}

daikoku/javascript/tests/specs/teams.spec.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,122 @@ test("un utilisateur peut creer une équipe si la securité de reation d'équipe
141141

142142
await page.getByRole('button', { name: 'Mes équipes' }).click();
143143
await expect(page.locator('.modal-footer').getByRole('button', { name: 'Créer une équipe' })).toBeHidden();
144+
});
145+
146+
test("Inviter un utilisateur dans une équipe sans caseSensitive", async ({ page }) => {
147+
await page.goto(ACCUEIL);
148+
await loginAs(MICHAEL, page);
149+
await page.getByRole('button', { name: 'Mes équipes' }).click();
150+
await page.locator('#portal-root').getByRole('link', { name: 'API Division' }).click();
151+
await page.getByText('Membres').click();
152+
await page.getByRole('button', { name: 'Inviter un collaborateur' }).click();
153+
await page.getByRole('textbox', { name: 'Email' }).fill('Andy.BERNARD@dundermifflin.com');
154+
await page.getByRole('button', { name: 'Rechercher', exact: true }).click();
155+
await page.waitForTimeout(1000);
156+
await page.getByRole('button', { name: 'user menu' }).click();
157+
await page.getByRole('link', { name: 'Déconnexion' }).click();
158+
await page.waitForTimeout(1000);
159+
await page.getByRole('button', { name: 'user menu' }).click();
160+
await page.getByRole('link', { name: 'Se connecter' }).click();
161+
await page.locator('input[name="username"]').click();
162+
await page.locator('input[name="username"]').fill('Andy.BERNARD@dundermifflin.com');
163+
await page.locator('input[name="password"]').fill('password');
164+
await page.getByRole('button', { name: 'Se connecter' }).click();
165+
await page.waitForTimeout(1000);
166+
await page.getByRole('link', { name: 'Accès aux notifications' }).click();
167+
await page.getByRole('button', { name: 'Rejeter' }).click();
168+
await page.getByRole('button', { name: 'user menu' }).click();
169+
await page.getByRole('link', { name: 'Déconnexion' }).click();
170+
171+
172+
await page.getByRole('button', { name: 'user menu' }).click();
173+
await page.getByRole('link', { name: 'Se connecter' }).click();
174+
await page.locator('input[name="username"]').fill('michael.scott@dundermifflin.com');
175+
await page.locator('input[name="password"]').fill('password');
176+
await page.getByRole('button', { name: 'Se connecter' }).click();
177+
178+
await page.getByRole('button', { name: 'Mes équipes' }).click();
179+
await page.getByRole('link', { name: 'API Division' }).click();
180+
await page.getByText('Membres').click();
181+
await page.getByRole('button', { name: 'Inviter un collaborateur' }).click();
182+
await page.getByRole('textbox', { name: 'Email' }).fill('andy.bernard@dundermifflin.com');
183+
await page.getByRole('button', { name: 'Rechercher', exact: true }).click();
184+
await page.getByText('En attente (1)').click();
185+
await page.getByText('Andy Bernard', { exact: true }).click();
186+
await page.getByRole('button', { name: 'user menu' }).click();
187+
await page.getByRole('link', { name: 'Déconnexion' }).click();
188+
await page.waitForTimeout(1000);
189+
await page.getByRole('button', { name: 'user menu' }).click();
190+
await page.getByRole('link', { name: 'Se connecter' }).click();
191+
await page.locator('input[name="username"]').fill('Andy.BERNARD@dundermifflin.com');
192+
await page.locator('input[name="password"]').fill('password');
193+
await page.getByRole('button', { name: 'Se connecter' }).click();
194+
await page.waitForTimeout(1000);
195+
await page.getByRole('link', { name: 'Accès aux notifications' }).click();
196+
await page.getByRole('button', { name: 'Accepter' }).click();
197+
await page.getByRole('button', { name: 'user menu' }).click();
198+
await page.getByRole('link', { name: 'Déconnexion' }).click();
199+
await page.getByRole('button', { name: 'user menu' }).click();
200+
await page.getByRole('link', { name: 'Se connecter' }).click();
201+
await page.locator('input[name="username"]').fill('michael.scott@dundermifflin.com');
202+
await page.locator('input[name="password"]').fill('password');
203+
await page.getByRole('button', { name: 'Se connecter' }).click();
204+
await page.getByRole('button', { name: 'Mes équipes' }).click();
205+
await page.getByRole('link', { name: 'API Division' }).click();
206+
await page.getByText('Membres').click();
207+
await page.getByRole('main').getByText('Membres').click();
208+
await page.getByText('Andy Bernard').click();
209+
await expect(page.getByRole('listitem', { name: 'Andy Bernard' })).toHaveText('Andy Bernard');
210+
211+
await page.getByRole('button', { name: 'user menu' }).click();
212+
await page.getByRole('link', { name: 'Paramètres Daikoku' }).click();
213+
await page.getByText('Utilisateurs', { exact: true }).click();
214+
await page.getByText('Andy Bernard').click();
215+
});
216+
217+
test("inviter un utilisateur plusieurs fois en case insensitive ne doit pas créer plusieurs users dans le tenant", async ({ page }) => {
218+
219+
await page.goto(ACCUEIL);
220+
await loginAs(MICHAEL, page);
221+
await page.getByRole('button', { name: 'Mes équipes' }).click();
222+
await page.locator('#portal-root').getByRole('link', { name: 'API Division' }).click();
223+
await page.getByText('Membres').click();
224+
await page.getByRole('button', { name: 'Inviter un collaborateur' }).click();
225+
await page.getByRole('textbox', { name: 'Email' }).fill('andy.bernard@dundermifflin.com');
226+
await page.getByRole('button', { name: 'Rechercher', exact: true }).click();
227+
await page.waitForTimeout(1000)
228+
await page.getByRole('button', { name: 'user menu' }).click();
229+
await page.getByRole('link', { name: 'Déconnexion' }).click();
230+
await page.waitForTimeout(1000)
231+
await page.getByRole('button', { name: 'user menu' }).click();
232+
await page.getByRole('link', { name: 'Se connecter' }).click();
233+
await page.locator('input[name="username"]').fill('andy.bernard@dundermifflin.com');
234+
await page.locator('input[name="password"]').fill('password');
235+
await page.getByRole('button', { name: 'Se connecter' }).click();
236+
await page.waitForTimeout(1000)
237+
await page.getByRole('link', { name: 'Accès aux notifications' }).click();
238+
await page.getByRole('button', { name: 'Rejeter' }).click();
239+
await page.getByRole('button', { name: 'user menu' }).click();
240+
await page.getByRole('link', { name: 'Déconnexion' }).click();
241+
await page.getByRole('button', { name: 'user menu' }).click();
242+
await page.getByRole('link', { name: 'Se connecter' }).click();
243+
await page.locator('input[name="username"]').fill('michael.scott@dundermifflin.com');
244+
await page.locator('input[name="password"]').fill('password');
245+
await page.getByRole('button', { name: 'Se connecter' }).click();
246+
await page.getByRole('button', { name: 'user menu' }).click();
247+
await page.waitForTimeout(1000)
248+
await page.getByRole('button', { name: 'Mes équipes' }).click();
249+
await page.getByRole('link', { name: 'API Division' }).click();
250+
await page.getByText('Membres').click();
251+
await page.getByRole('button', { name: 'Inviter un collaborateur' }).click();
252+
await page.getByRole('textbox', { name: 'Email' }).click();
253+
await page.getByRole('textbox', { name: 'Email' }).fill('andy.bernard@dundermifflin.com');
254+
await page.getByRole('button', { name: 'Rechercher', exact: true }).click();
255+
await page.getByRole('button', { name: 'user menu' }).click();
256+
await page.getByRole('link', { name: 'Dunder Mifflin' }).click();
257+
await page.getByRole('button', { name: 'user menu' }).click();
258+
await page.getByRole('link', { name: 'Paramètres Daikoku' }).click();
259+
await page.getByText('Utilisateurs', { exact: true }).click();
260+
expect(page.getByText('Andy Bernard').first()).toBeVisible;
261+
expect(page.getByText('Andy Bernard').nth(1)).not.toBeAttached();
144262
});

0 commit comments

Comments
 (0)