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;
@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<>();
@OneToMany(fetch = FetchType.LAZY, mappedBy = "event")
@@ -1,5 +1,6 @@
package com.sasiedzi.event.web.rest;
import com.sasiedzi.event.domain.CurrentUserHolder;
import com.sasiedzi.event.domain.Registration;
import com.sasiedzi.event.domain.User;
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.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@@ -54,6 +56,11 @@ public class RegistrationResource {
this.userRepository = userRepository;
}
private static Long currentEventId = 1751L;
@Autowired
CurrentUserHolder currentUser;
/**
* {@code POST /registrations} : Create a new registration.
*
@@ -64,6 +71,11 @@ public class RegistrationResource {
@PostMapping("")
public ResponseEntity<Registration> createRegistration(@Valid @RequestBody Registration registration, Principal principal)
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);
AdminUserDTO userFromAuthentication;
if (principal instanceof AbstractAuthenticationToken) {
@@ -97,6 +109,11 @@ public class RegistrationResource {
@PathVariable(value = "id", required = false) final Long id,
@Valid @RequestBody Registration registration
) 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);
if (registration.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
@@ -131,6 +148,11 @@ public class RegistrationResource {
@PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody Registration registration
) 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);
if (registration.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
@@ -208,6 +230,12 @@ public class RegistrationResource {
*/
@DeleteMapping("/{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);
registrationRepository.deleteById(id);
return ResponseEntity.noContent()
@@ -20,6 +20,7 @@ export default defineComponent({
const alertService = inject('alertService', () => useAlertService(), true);
const { formatDateShort } = useDateFormat();
const dataUtils = useDataUtils();
const isCurrentEvent = ref(false);
const registrationService = inject('registrationService', () => new RegistrationService());
const accountService = inject<AccountService>('accountService');
@@ -34,6 +35,7 @@ export default defineComponent({
const retrieveEvent = async (eventId: string) => {
try {
const res = await eventService().find(eventId);
isCurrentEvent.value = eventId == '1751';
event.value = res;
// sortedAndIndexedRegistrations.value = res.registrations;
sortedAndIndexedRegistrations.value = res.registrations.sort(
@@ -108,6 +110,7 @@ export default defineComponent({
accountService,
eventService,
event,
isCurrentEvent,
...dataUtils,
formatDateShort,
previousState,
@@ -35,7 +35,12 @@
<span>{{ event.comment }}</span>
</dd>
</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">
<font-awesome-icon icon="plus"></font-awesome-icon>&nbsp;<span>Dołącz do wydarzenia</span>
</button>
@@ -69,12 +74,13 @@
variant="danger"
class="btn btn-sm"
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
>
<font-awesome-icon icon="times"></font-awesome-icon>
<span class="d-none d-md-inline">Delete</span>
</b-button>
{{ registration.user?.id }}/{{ currentUserId }}
</td>
<td>{{ registration.comment }}</td>
<!-- <td>{{ registration.active }}</td>-->
+1 -1
View File
@@ -12,7 +12,7 @@ export const createRouter = () =>
routes: [
{
path: '/',
redirect: '/event/1551/view',
redirect: '/event/1751/view',
},
{
path: '/forbidden',