Skip to content

Commit

Permalink
Legg utrullingssjekk på controller-nivå
Browse files Browse the repository at this point in the history
der controller har tilgang til brukar sitt fødselsnummer
  • Loading branch information
ingfo committed Feb 19, 2025
1 parent 4e9ea55 commit 5f3fd48
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import no.nav.veilarbvedtaksstotte.controller.dto.LagUtkastDTO;
import no.nav.veilarbvedtaksstotte.controller.dto.OppdaterUtkastDTO;
import no.nav.veilarbvedtaksstotte.domain.vedtak.Vedtak;
import no.nav.veilarbvedtaksstotte.service.UtrullingService;
import no.nav.veilarbvedtaksstotte.service.VedtakService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -18,16 +19,18 @@
public class UtkastController {

private final VedtakService vedtakService;
private final UtrullingService utrullingService;

@Autowired
public UtkastController(VedtakService vedtakService) {
public UtkastController(VedtakService vedtakService, UtrullingService utrullingService) {
this.vedtakService = vedtakService;
this.utrullingService = utrullingService;
}

@Deprecated(forRemoval = true)
@GetMapping
public Vedtak hentUtkast(@RequestParam("fnr") Fnr fnr) {
// Sjekkar utrulling for kontoret til brukar ✅
utrullingService.sjekkAtBrukerTilhorerUtrulletKontor(fnr);

return vedtakService.hentUtkast(fnr);
}
Expand All @@ -41,11 +44,12 @@ public BeslutterprosessStatusDTO beslutterprosessStatus(@PathVariable("vedtakId"

@PostMapping
public void lagUtkast(@RequestBody LagUtkastDTO lagUtkastDTO) {
// Sjekkar utrulling for kontoret til brukar ✅

if (lagUtkastDTO == null || lagUtkastDTO.getFnr() == null) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Missing fnr");
}

utrullingService.sjekkAtBrukerTilhorerUtrulletKontor(lagUtkastDTO.getFnr());

vedtakService.lagUtkast(lagUtkastDTO.getFnr());
}

Expand All @@ -67,7 +71,7 @@ public void oppdaterUtkast(@PathVariable("vedtakId") long vedtakId, @RequestBody
@Deprecated(forRemoval = true)
@GetMapping("{fnr}/harUtkast")
public boolean harUtkast(@PathVariable("fnr") Fnr fnr) {
// Sjekkar utrulling for kontoret til brukar ✅
utrullingService.sjekkAtBrukerTilhorerUtrulletKontor(fnr);

return vedtakService.harUtkast(fnr);
}
Expand Down Expand Up @@ -95,5 +99,4 @@ public void oppdaterUtkast(@PathVariable("vedtakId") long vedtakId) {

vedtakService.taOverUtkast(vedtakId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import no.nav.veilarbvedtaksstotte.domain.vedtak.Vedtak;
import no.nav.veilarbvedtaksstotte.service.ArenaVedtakService;
import no.nav.veilarbvedtaksstotte.service.OyeblikksbildeService;
import no.nav.veilarbvedtaksstotte.service.UtrullingService;
import no.nav.veilarbvedtaksstotte.service.VedtakService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
Expand All @@ -21,12 +22,14 @@ public class VedtakController {
private final VedtakService vedtakService;
private final ArenaVedtakService arenaVedtakService;
private final OyeblikksbildeService oyeblikksbildeService;
private final UtrullingService utrullingService;

@Autowired
public VedtakController(VedtakService vedtakService, ArenaVedtakService arenaVedtakService, OyeblikksbildeService oyeblikksbildeService) {
public VedtakController(VedtakService vedtakService, ArenaVedtakService arenaVedtakService, OyeblikksbildeService oyeblikksbildeService, UtrullingService utrullingService) {
this.vedtakService = vedtakService;
this.arenaVedtakService = arenaVedtakService;
this.oyeblikksbildeService = oyeblikksbildeService;
this.utrullingService = utrullingService;
}

@GetMapping(value = "{vedtakId}/pdf", produces = MediaType.APPLICATION_PDF_VALUE)
Expand Down Expand Up @@ -59,7 +62,7 @@ public ResponseEntity<byte[]> hentVedtakOyeblikksCVPdf(@PathVariable("vedtakId")
@Deprecated(forRemoval = true)
@GetMapping("/fattet")
public List<Vedtak> hentFattedeVedtak(@RequestParam("fnr") Fnr fnr) {
// Sjekkar utrulling for kontoret til brukar ✅
utrullingService.sjekkAtBrukerTilhorerUtrulletKontor(fnr);

return vedtakService.hentFattedeVedtak(fnr);
}
Expand Down Expand Up @@ -96,7 +99,7 @@ public OyeblikksbildeEgenvurderingDto hentEgenvurderingOyeblikksbilde(@PathVaria
@Deprecated(forRemoval = true)
@GetMapping("/arena")
public List<ArkivertVedtak> hentVedtakFraArena(@RequestParam("fnr") Fnr fnr) {
// Sjekkar utrulling for kontoret til brukar ✅
utrullingService.sjekkAtBrukerTilhorerUtrulletKontor(fnr);

return arenaVedtakService.hentVedtakFraArena(fnr);
}
Expand All @@ -111,4 +114,3 @@ public ResponseEntity<byte[]> hentVedtakPdfFraArena(
.body(vedtakPdf);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.veilarbvedtaksstotte.controller.v2

import no.nav.veilarbvedtaksstotte.controller.v2.dto.UtkastRequest
import no.nav.veilarbvedtaksstotte.domain.vedtak.Vedtak
import no.nav.veilarbvedtaksstotte.service.UtrullingService
import no.nav.veilarbvedtaksstotte.service.VedtakService
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RestController
Expand All @@ -11,17 +12,18 @@ import org.springframework.web.bind.annotation.RequestMapping
@RestController
@RequestMapping("/api/v2")
class UtkastV2Controller(
val vedtakService: VedtakService
val vedtakService: VedtakService,
private val utrullingService: UtrullingService
) {
@PostMapping("/hent-utkast")
fun hentUtkast(@RequestBody utkastRequest: UtkastRequest): Vedtak {
// Sjekkar utrulling for kontoret til brukar ✅
utrullingService.sjekkAtBrukerTilhorerUtrulletKontor(utkastRequest.fnr)

return vedtakService.hentUtkast(utkastRequest.fnr)
}
@PostMapping("/utkast/hent-harUtkast")
fun harUtkast(@RequestBody utkastRequest: UtkastRequest): Boolean {
// Sjekkar utrulling for kontoret til brukar ✅
utrullingService.sjekkAtBrukerTilhorerUtrulletKontor(utkastRequest.fnr)

return vedtakService.harUtkast(utkastRequest.fnr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ import no.nav.veilarbvedtaksstotte.controller.v2.dto.VedtakRequest
import no.nav.veilarbvedtaksstotte.domain.arkiv.ArkivertVedtak
import no.nav.veilarbvedtaksstotte.domain.vedtak.Vedtak
import no.nav.veilarbvedtaksstotte.service.ArenaVedtakService
import no.nav.veilarbvedtaksstotte.service.UtrullingService
import no.nav.veilarbvedtaksstotte.service.VedtakService
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.RequestBody

@RestController
@RequestMapping("/api/v2/vedtak")
class VedtakV2Controller(
val vedtakService: VedtakService,
val arenaVedtakService: ArenaVedtakService,
private val utrullingService: UtrullingService,
) {
@PostMapping("/hent-fattet")
fun hentFattedeVedtak(@RequestBody vedtakRequest: VedtakRequest): List<Vedtak> {
// Sjekkar utrulling for kontoret til brukar ✅
utrullingService.sjekkAtBrukerTilhorerUtrulletKontor(vedtakRequest.fnr)

return vedtakService.hentFattedeVedtak(vedtakRequest.fnr)
}

@PostMapping("/hent-arena")
fun hentVedtakFraArena(@RequestBody vedtakRequest: VedtakRequest): List<ArkivertVedtak> {
// Sjekkar utrulling for kontoret til brukar ✅
utrullingService.sjekkAtBrukerTilhorerUtrulletKontor(vedtakRequest.fnr)

return arenaVedtakService.hentVedtakFraArena(vedtakRequest.fnr)
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import no.nav.veilarbvedtaksstotte.repository.UtrullingRepository;
import no.nav.veilarbvedtaksstotte.repository.domain.UtrulletEnhet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;

import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -81,4 +83,10 @@ public boolean tilhorerInnloggetVeilederUtrulletKontor() {
return utrullingRepository.erMinstEnEnhetUtrullet(enhetIder);
}

public void sjekkAtBrukerTilhorerUtrulletKontor(Fnr fnr) {
if (!tilhorerBrukerUtrulletKontor(fnr)) {
log.info("Vedtaksstøtte er ikke utrullet for brukers enhet. Tilgang er stoppet");
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Vedtaksstøtte er ikke utrullet for enheten til bruker");
}
}
}

0 comments on commit 5f3fd48

Please sign in to comment.