Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,6 @@ private Map<Avtale, Tilgang> tilgangTilAvtaler(List<Avtale> avtaler) {
return tilgangsmappe;
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The removed avtalenEksisterer override previously hid ALL Arena agreements that weren't concluded (!erAvtaleInngått()) from employers. The new filtering logic in Avtalepart only hides MENTOR Arena agreements based on completion status. This means non-mentor Arena agreements that aren't concluded will now be visible to employers. If this behavior change is intentional, consider documenting it; otherwise, the old logic may need to be preserved or combined with the new filter.

Copilot uses AI. Check for mistakes.
}

@Override
public boolean avtalenEksisterer(Avtale avtale) {
if (avtale.getOpphav().equals(Avtaleopphav.ARENA) && !avtale.erAvtaleInngått()) {
return false;
}
return super.avtalenEksisterer(avtale);
}

private boolean harTilgangPåTiltakIBedrift(BedriftNr bedriftNr, Tiltakstype tiltakstype) {
if (!tilganger.containsKey(bedriftNr)) {
return false;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/no/nav/tag/tiltaksgjennomforing/avtale/Avtale.java
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,25 @@ void sjekkOmAltErKlarTilGodkjenning() {
}
}

public boolean sjekkOmAlltErFylltUtUntattFamiljeTilknyting() {
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

Method name has a typo: "Allt" should be "Alt" (singular, consistent with sjekkOmAltErKlarTilGodkjenning on line 788). Additionally, "FamiljeTilknyting" doesn't match the field name "Familietilknytning" used elsewhere, though this inconsistency exists throughout method names in this class.

Copilot uses AI. Check for mistakes.

if (!felterSomIkkeErFyltUt().stream().filter(x -> !x.equals("harFamilietilknytning")).toList().isEmpty()) {
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The double negation with .filter(x -> !x.equals("harFamilietilknytning")).toList().isEmpty() makes this logic confusing. This checks if the filtered list is empty, which means all unfilled fields are "harFamilietilknytning". Consider simplifying to:

if (felterSomIkkeErFyltUt().stream().anyMatch(x -> !x.equals("harFamilietilknytning")))

This is clearer: "if any unfilled field is NOT harFamilietilknytning, return false".

Suggested change
if (!felterSomIkkeErFyltUt().stream().filter(x -> !x.equals("harFamilietilknytning")).toList().isEmpty()) {
if (felterSomIkkeErFyltUt().stream().anyMatch(x -> !x.equals("harFamilietilknytning"))) {

Copilot uses AI. Check for mistakes.
log.warn(
"Avtale= {}, med type= {} har ikke alle felter fylt ut for visning= {}",
this.avtaleNr,
this.tiltakstype,
felterSomIkkeErFyltUt()
);
return false;
}
log.info("Migrert mentoravtale {} er klar for visning.", this.avtaleNr);
return true;
}
Comment on lines +814 to +827
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The new method sjekkOmAlltErFylltUtUntattFamiljeTilknyting() lacks test coverage. Consider adding tests to verify:

  1. Returns true when all fields are filled except "harFamilietilknytning"
  2. Returns false when any other field besides "harFamilietilknytning" is not filled
  3. Returns true when all fields including "harFamilietilknytning" are filled

Copilot uses AI. Check for mistakes.

public boolean erKlarForVisningAvMigrertMentorAvtale() {
return sjekkOmAlltErFylltUtUntattFamiljeTilknyting();
}
Comment on lines +829 to +831
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

This method is a simple wrapper that adds no additional logic or documentation. Consider removing it and directly calling sjekkOmAlltErFylltUtUntattFamiljeTilknyting() from the caller in Avtalepart.java line 237, or add documentation explaining why this wrapper exists.

Suggested change
public boolean erKlarForVisningAvMigrertMentorAvtale() {
return sjekkOmAlltErFylltUtUntattFamiljeTilknyting();
}
// Method removed: erKlarForVisningAvMigrertMentorAvtale()

Copilot uses AI. Check for mistakes.

public void annuller(Veileder veileder, String annullerGrunn) {
annuller(annullerGrunn, veileder.getNavIdent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
Expand Down Expand Up @@ -291,7 +292,14 @@ public ResponseEntity<?> endreAvtale(
Avtalepart avtalepart = innloggingService.hentAvtalepart(innloggetPart);
Avtale avtale = avtaleRepository.findById(avtaleId)
.map(sjekkeSistEndret(sistEndret))
.orElseThrow(RessursFinnesIkkeException::new);avtalepart.endreAvtale(endreAvtale, avtale);
.orElseThrow(RessursFinnesIkkeException::new);

// if (avtale.getOpphav() == Avtaleopphav.ARENA && avtale.getTiltakstype() == Tiltakstype.MENTOR){
// avtalepart.endreAvtale(endreAvtale, avtale, () -> avtalepart.endreMentorFnrArenaMigrertAvtale(avtale, endreAvtale.));
// } else {
// avtalepart.endreAvtale(endreAvtale, avtale);
// }
//
Avtale lagretAvtale = avtaleRepository.save(avtale);
return ResponseEntity.ok().lastModified(lagretAvtale.getSistEndret()).build();
}
Expand Down Expand Up @@ -916,4 +924,20 @@ public Avtale endreKidOgKontonummer(
);
return avtaleRepository.save(avtale);
}

@PatchMapping("/{avtaleId}/oppdater-mentor-fnr")
public void oppdaterMentorFnr(
@PathVariable("avtaleId") UUID avtaleId,
@RequestBody String nyttMentorFnr,
@RequestHeader(HttpHeaders.IF_UNMODIFIED_SINCE) Instant sistEndret
) {
Fnr mentorFnr = new Fnr(nyttMentorFnr);
Veileder veileder = innloggingService.hentVeileder();
Avtale avtale = avtaleRepository.findById(avtaleId)
.map(sjekkeSistEndret(sistEndret))
.orElseThrow(RessursFinnesIkkeException::new);

veileder.oppdaterMentorFnrForMigrertAvtale(mentorFnr, avtale);
avtaleRepository.save(avtale);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected final Page<Avtale> hentAvtalerMedLesetilgang(
.stream()
.filter(this::avtalenEksisterer)
.filter(this.harTilgangTilAvtale(avtaler.getContent()))
.filter(this::mentorAvtaleUnderMigreringSkalVises)
.toList();

if (queryParametre.erSokPaEnkeltperson() && avtalerMedTilgang.isEmpty()) {
Expand Down Expand Up @@ -114,6 +115,10 @@ public void sjekkTilgang(Avtale avtale) {
if (!avtalenEksisterer(avtale)) {
throw new RessursFinnesIkkeException();
}
if (!mentorAvtaleUnderMigreringSkalVises(avtale)) {
log.info("Forsøk på tilgang til skjult mentoravtale med opphav Arena for migrering. AvtaleNr: {}", avtale.getAvtaleNr());
throw new RessursFinnesIkkeException();
}
if (harTilgangTilAvtale(avtale) instanceof Tilgang.Avvis avvis) {
switch (avvis.tilgangskode()) {
case STRENGT_FORTROLIG_ADRESSE -> throw new IkkeTilgangTilDeltakerException(
Expand Down Expand Up @@ -214,4 +219,27 @@ public void settLonntilskuddProsentsats(Avtale avtale) {
);
}
}

private boolean erAvtaleMigrertMentorArena(Avtale avtale) {
return avtale.getTiltakstype() == Tiltakstype.MENTOR
&& avtale.getOpphav() == Avtaleopphav.ARENA;
}

private boolean mentorAvtaleUnderMigreringSkalVises(Avtale avtale) {
boolean erMentorArena = erAvtaleMigrertMentorArena(avtale);

if (!erMentorArena) {
return true;
}

boolean erInternRolle = rolle().erInternBruker();

boolean utFylltUntattFamiljeTilknyting = avtale.erKlarForVisningAvMigrertMentorAvtale();

if (!erInternRolle && !utFylltUntattFamiljeTilknyting) {
log.info("Skjult mentoravtale med opphav Arena for migrering. Rolle: {}, AvtaleNr: {}", rolle(), avtale.getAvtaleNr());
}

return erInternRolle || utFylltUntattFamiljeTilknyting;
Comment on lines +237 to +243
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

Variable name violates camelCase convention: "utFyllt" should be "utfylt" (lowercase 'f'). Additionally, "FamiljeTilknyting" appears to be a misspelling that doesn't match the field name "Familietilknytning", though this inconsistency exists in related method names.

Suggested change
boolean utFylltUntattFamiljeTilknyting = avtale.erKlarForVisningAvMigrertMentorAvtale();
if (!erInternRolle && !utFylltUntattFamiljeTilknyting) {
log.info("Skjult mentoravtale med opphav Arena for migrering. Rolle: {}, AvtaleNr: {}", rolle(), avtale.getAvtaleNr());
}
return erInternRolle || utFylltUntattFamiljeTilknyting;
boolean utfyltUntattFamilietilknytning = avtale.erKlarForVisningAvMigrertMentorAvtale();
if (!erInternRolle && !utfyltUntattFamilietilknytning) {
log.info("Skjult mentoravtale med opphav Arena for migrering. Rolle: {}, AvtaleNr: {}", rolle(), avtale.getAvtaleNr());
}
return erInternRolle || utfyltUntattFamilietilknytning;

Copilot uses AI. Check for mistakes.
}
Comment on lines +228 to +244
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The new filtering logic for migrated mentor agreements from Arena lacks test coverage. Consider adding tests for:

  1. Non-internal users being denied access to incomplete migrated mentor agreements
  2. Internal users (VEILEDER/BESLUTTER) having access to all migrated mentor agreements
  3. Non-internal users having access to completed migrated mentor agreements
  4. Non-mentor or non-Arena agreements not being affected by the filter

Copilot uses AI. Check for mistakes.
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static Fnr generer(int aar, int maned, int dag) {
public static boolean erGyldigFnr(String verdi) {
if (FodselsnummerValidator.ALLOW_SYNTHETIC_NUMBERS) {
return switch (verdi) {
case "12345678910", "00000000000", "11111111111", "99999999999", "23090170723" -> true;
case "12345678910", "00000000000", "11111111111", "99999999999", "23090170723", "23090170712" -> true;
case null, default -> FodselsnummerValidator.isValid(verdi);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,10 @@ public UUID getAzureOid() {
public NavIdent getNavIdent() {
return getIdentifikator();
}

public void oppdaterMentorFnrForMigrertAvtale(Fnr mentorFnr, Avtale avtale) {
super.erAvtaleMigrertMentorArena(avtale);
super.sjekkTilgang(avtale);
avtale.setMentorFnr(mentorFnr);
}
}
2 changes: 1 addition & 1 deletion src/test/resources/config/application-dockercompose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tiltaksgjennomforing:
kafka:
enabled: true
mentor-tilskuddsperioder:
enabled: false
enabled: true

altinn-tilgangsstyring:
uri: http://localhost:8090/altinn-tilgangsstyring
Expand Down
Loading