Commit 94c7925a authored by Aurelien Surier Garofalo's avatar Aurelien Surier Garofalo
Browse files

Applied basic roles on UI and API

parent f44ac114
......@@ -12,7 +12,9 @@ import io.github.jhipster.web.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.mycompany.myapp.security.AuthoritiesConstants;
import javax.validation.Valid;
import java.net.URI;
......@@ -55,6 +57,7 @@ public class AgenceResource {
*/
@PostMapping("/agences")
@Timed
@PreAuthorize("hasRole(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Agence> createAgence(@Valid @RequestBody Agence agence) throws URISyntaxException {
log.debug("REST request to save Agence : {}", agence);
if (agence.getId() != null) {
......@@ -78,6 +81,7 @@ public class AgenceResource {
*/
@PutMapping("/agences")
@Timed
@PreAuthorize("hasRole(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Agence> updateAgence(@Valid @RequestBody Agence agence) throws URISyntaxException {
log.debug("REST request to update Agence : {}", agence);
if (agence.getId() == null) {
......@@ -140,6 +144,7 @@ public class AgenceResource {
*/
@DeleteMapping("/agences/{id}")
@Timed
@PreAuthorize("hasRole(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<Void> deleteAgence(@PathVariable Long id) {
log.debug("REST request to delete Agence : {}", id);
......
......@@ -50,12 +50,14 @@
</button>
<button type="submit"
[routerLink]="['/agence', agence.id, 'edit']"
*jhiHasAnyAuthority="'ROLE_ADMIN'"
class="btn btn-primary btn-sm">
<fa-icon [icon]="'pencil-alt'"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
</button>
<button type="submit"
[routerLink]="['/', { outlets: { popup: 'agence/'+ agence.id + '/delete'} }]"
*jhiHasAnyAuthority="'ROLE_ADMIN'"
replaceUrl="true"
queryParamsHandling="merge"
class="btn btn-danger btn-sm">
......
......@@ -14,77 +14,77 @@ import { IAgence } from 'app/shared/model/agence.model';
@Injectable({ providedIn: 'root' })
export class AgenceResolve implements Resolve<IAgence> {
constructor(private service: AgenceService) {}
constructor(private service: AgenceService) {}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const id = route.params['id'] ? route.params['id'] : null;
if (id) {
return this.service.find(id).pipe(map((agence: HttpResponse<Agence>) => agence.body));
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const id = route.params['id'] ? route.params['id'] : null;
if (id) {
return this.service.find(id).pipe(map((agence: HttpResponse<Agence>) => agence.body));
}
return of(new Agence());
}
return of(new Agence());
}
}
export const agenceRoute: Routes = [
{
path: 'agence',
component: AgenceComponent,
data: {
authorities: ['ROLE_USER'],
pageTitle: 'myTransportApp.agence.home.title'
{
path: 'agence',
component: AgenceComponent,
data: {
authorities: ['ROLE_USER'],
pageTitle: 'myTransportApp.agence.home.title'
},
canActivate: [UserRouteAccessService]
},
canActivate: [UserRouteAccessService]
},
{
path: 'agence/:id/view',
component: AgenceDetailComponent,
resolve: {
agence: AgenceResolve
{
path: 'agence/:id/view',
component: AgenceDetailComponent,
resolve: {
agence: AgenceResolve
},
data: {
authorities: ['ROLE_USER'],
pageTitle: 'myTransportApp.agence.home.title'
},
canActivate: [UserRouteAccessService]
},
data: {
authorities: ['ROLE_USER'],
pageTitle: 'myTransportApp.agence.home.title'
{
path: 'agence/new',
component: AgenceUpdateComponent,
resolve: {
agence: AgenceResolve
},
data: {
authorities: ['ROLE_USER'],
pageTitle: 'myTransportApp.agence.home.title'
},
canActivate: [UserRouteAccessService]
},
canActivate: [UserRouteAccessService]
},
{
path: 'agence/new',
component: AgenceUpdateComponent,
resolve: {
agence: AgenceResolve
},
data: {
authorities: ['ROLE_USER'],
pageTitle: 'myTransportApp.agence.home.title'
},
canActivate: [UserRouteAccessService]
},
{
path: 'agence/:id/edit',
component: AgenceUpdateComponent,
resolve: {
agence: AgenceResolve
},
data: {
authorities: ['ROLE_USER'],
pageTitle: 'myTransportApp.agence.home.title'
},
canActivate: [UserRouteAccessService]
}
{
path: 'agence/:id/edit',
component: AgenceUpdateComponent,
resolve: {
agence: AgenceResolve
},
data: {
authorities: ['ROLE_ADMIN'],
pageTitle: 'myTransportApp.agence.home.title'
},
canActivate: [UserRouteAccessService]
}
];
export const agencePopupRoute: Routes = [
{
path: 'agence/:id/delete',
component: AgenceDeletePopupComponent,
resolve: {
agence: AgenceResolve
},
data: {
authorities: ['ROLE_USER'],
pageTitle: 'myTransportApp.agence.home.title'
},
canActivate: [UserRouteAccessService],
outlet: 'popup'
}
{
path: 'agence/:id/delete',
component: AgenceDeletePopupComponent,
resolve: {
agence: AgenceResolve
},
data: {
authorities: ['ROLE_ADMIN'],
pageTitle: 'myTransportApp.agence.home.title'
},
canActivate: [UserRouteAccessService],
outlet: 'popup'
}
];
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment