Prod deploy 18 listopada

This commit is contained in:
2024-11-18 20:38:53 +01:00
parent a6731fcdfc
commit 770791302c
5 changed files with 41 additions and 4 deletions
@@ -44,7 +44,7 @@ public class Event implements Serializable {
private String comment; private String comment;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "event") @OneToMany(fetch = FetchType.EAGER, mappedBy = "event")
@JsonIgnoreProperties(value = { "user", "event", "transactionItems" }, allowSetters = true) @JsonIgnoreProperties(value = { "event", "transactionItems" }, allowSetters = true)
private Set<Registration> registrations = new HashSet<>(); private Set<Registration> registrations = new HashSet<>();
@OneToMany(fetch = FetchType.LAZY, mappedBy = "event") @OneToMany(fetch = FetchType.LAZY, mappedBy = "event")
@@ -1,5 +1,6 @@
package com.sasiedzi.event.web.rest; package com.sasiedzi.event.web.rest;
import com.sasiedzi.event.domain.CurrentUserHolder;
import com.sasiedzi.event.domain.Registration; import com.sasiedzi.event.domain.Registration;
import com.sasiedzi.event.domain.User; import com.sasiedzi.event.domain.User;
import com.sasiedzi.event.repository.RegistrationRepository; import com.sasiedzi.event.repository.RegistrationRepository;
@@ -20,6 +21,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -54,6 +56,11 @@ public class RegistrationResource {
this.userRepository = userRepository; this.userRepository = userRepository;
} }
private static Long currentEventId = 1751L;
@Autowired
CurrentUserHolder currentUser;
/** /**
* {@code POST /registrations} : Create a new registration. * {@code POST /registrations} : Create a new registration.
* *
@@ -64,6 +71,11 @@ public class RegistrationResource {
@PostMapping("") @PostMapping("")
public ResponseEntity<Registration> createRegistration(@Valid @RequestBody Registration registration, Principal principal) public ResponseEntity<Registration> createRegistration(@Valid @RequestBody Registration registration, Principal principal)
throws URISyntaxException { throws URISyntaxException {
if (
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") && !registration.getEvent().getId().equals(currentEventId)
) {
throw new AccessDeniedException("Registration is closed for this event");
}
LOG.debug("REST request to save Registration : {}", registration); LOG.debug("REST request to save Registration : {}", registration);
AdminUserDTO userFromAuthentication; AdminUserDTO userFromAuthentication;
if (principal instanceof AbstractAuthenticationToken) { if (principal instanceof AbstractAuthenticationToken) {
@@ -97,6 +109,11 @@ public class RegistrationResource {
@PathVariable(value = "id", required = false) final Long id, @PathVariable(value = "id", required = false) final Long id,
@Valid @RequestBody Registration registration @Valid @RequestBody Registration registration
) throws URISyntaxException { ) throws URISyntaxException {
if (
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") && !registration.getEvent().getId().equals(currentEventId)
) {
throw new AccessDeniedException("Registration is closed for this event");
}
LOG.debug("REST request to update Registration : {}, {}", id, registration); LOG.debug("REST request to update Registration : {}, {}", id, registration);
if (registration.getId() == null) { if (registration.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
@@ -131,6 +148,11 @@ public class RegistrationResource {
@PathVariable(value = "id", required = false) final Long id, @PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody Registration registration @NotNull @RequestBody Registration registration
) throws URISyntaxException { ) throws URISyntaxException {
if (
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") && !registration.getEvent().getId().equals(currentEventId)
) {
throw new AccessDeniedException("Registration is closed for this event");
}
LOG.debug("REST request to partial update Registration partially : {}, {}", id, registration); LOG.debug("REST request to partial update Registration partially : {}, {}", id, registration);
if (registration.getId() == null) { if (registration.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
@@ -208,6 +230,12 @@ public class RegistrationResource {
*/ */
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public ResponseEntity<Void> deleteRegistration(@PathVariable("id") Long id) { public ResponseEntity<Void> deleteRegistration(@PathVariable("id") Long id) {
Registration registration = registrationRepository.findById(id).get();
if (
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") && !registration.getEvent().getId().equals(currentEventId)
) {
throw new AccessDeniedException("Registration is closed for this event");
}
LOG.debug("REST request to delete Registration : {}", id); LOG.debug("REST request to delete Registration : {}", id);
registrationRepository.deleteById(id); registrationRepository.deleteById(id);
return ResponseEntity.noContent() return ResponseEntity.noContent()
@@ -20,6 +20,7 @@ export default defineComponent({
const alertService = inject('alertService', () => useAlertService(), true); const alertService = inject('alertService', () => useAlertService(), true);
const { formatDateShort } = useDateFormat(); const { formatDateShort } = useDateFormat();
const dataUtils = useDataUtils(); const dataUtils = useDataUtils();
const isCurrentEvent = ref(false);
const registrationService = inject('registrationService', () => new RegistrationService()); const registrationService = inject('registrationService', () => new RegistrationService());
const accountService = inject<AccountService>('accountService'); const accountService = inject<AccountService>('accountService');
@@ -34,6 +35,7 @@ export default defineComponent({
const retrieveEvent = async (eventId: string) => { const retrieveEvent = async (eventId: string) => {
try { try {
const res = await eventService().find(eventId); const res = await eventService().find(eventId);
isCurrentEvent.value = eventId == '1751';
event.value = res; event.value = res;
// sortedAndIndexedRegistrations.value = res.registrations; // sortedAndIndexedRegistrations.value = res.registrations;
sortedAndIndexedRegistrations.value = res.registrations.sort( sortedAndIndexedRegistrations.value = res.registrations.sort(
@@ -108,6 +110,7 @@ export default defineComponent({
accountService, accountService,
eventService, eventService,
event, event,
isCurrentEvent,
...dataUtils, ...dataUtils,
formatDateShort, formatDateShort,
previousState, previousState,
@@ -35,7 +35,12 @@
<span>{{ event.comment }}</span> <span>{{ event.comment }}</span>
</dd> </dd>
</dl> </dl>
<router-link :to="{ name: 'RegistrationCreateForEvent', params: { eventId: event.id } }" custom v-slot="{ navigate }"> <router-link
:to="{ name: 'RegistrationCreateForEvent', params: { eventId: event.id } }"
custom
v-slot="{ navigate }"
v-if="isCurrentEvent"
>
<button @click="navigate" class="btn btn-primary"> <button @click="navigate" class="btn btn-primary">
<font-awesome-icon icon="plus"></font-awesome-icon>&nbsp;<span>Dołącz do wydarzenia</span> <font-awesome-icon icon="plus"></font-awesome-icon>&nbsp;<span>Dołącz do wydarzenia</span>
</button> </button>
@@ -69,12 +74,13 @@
variant="danger" variant="danger"
class="btn btn-sm" class="btn btn-sm"
data-cy="entityDeleteButton" data-cy="entityDeleteButton"
v-if="(registration.id && registration.user?.id == currentUserId) || hasAnyAuthority('ROLE_ADMIN')" v-if="(registration.id && registration.user?.id == currentUserId && isCurrentEvent) || hasAnyAuthority('ROLE_ADMIN')"
v-b-modal.removeEntity v-b-modal.removeEntity
> >
<font-awesome-icon icon="times"></font-awesome-icon> <font-awesome-icon icon="times"></font-awesome-icon>
<span class="d-none d-md-inline">Delete</span> <span class="d-none d-md-inline">Delete</span>
</b-button> </b-button>
{{ registration.user?.id }}/{{ currentUserId }}
</td> </td>
<td>{{ registration.comment }}</td> <td>{{ registration.comment }}</td>
<!-- <td>{{ registration.active }}</td>--> <!-- <td>{{ registration.active }}</td>-->
+1 -1
View File
@@ -12,7 +12,7 @@ export const createRouter = () =>
routes: [ routes: [
{ {
path: '/', path: '/',
redirect: '/event/1551/view', redirect: '/event/1751/view',
}, },
{ {
path: '/forbidden', path: '/forbidden',