Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Samuel Dudík
PA165 Winery Management System
Commits
8d0f7726
Commit
8d0f7726
authored
May 24, 2022
by
Ondřej Pavlica
Browse files
Add Spring user role string constants
parent
adbfe131
Changes
8
Hide whitespace changes
Inline
Side-by-side
winery/api/src/main/java/cz/muni/fi/pa165/winery/enums/UserRoleType.java
View file @
8d0f7726
...
...
@@ -2,5 +2,8 @@ package cz.muni.fi.pa165.winery.enums;
public
enum
UserRoleType
{
ADMIN
,
USER
USER
;
public
static
final
String
SPRING_ROLE_ADMIN
=
"ROLE_ADMIN"
;
public
static
final
String
SPRING_ROLE_USER
=
"ROLE_USER"
;
}
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/GrapeController.java
View file @
8d0f7726
package
cz.muni.fi.pa165.winery.webapp.controllers
;
import
cz.muni.fi.pa165.winery.dto.wine.GrapeDto
;
import
cz.muni.fi.pa165.winery.enums.UserRoleType
;
import
cz.muni.fi.pa165.winery.services.wine.GrapeService
;
import
cz.muni.fi.pa165.winery.webapp.models.grape.GrapeListingViewModel
;
import
cz.muni.fi.pa165.winery.webapp.models.grape.GrapeUpsertViewModel
;
...
...
@@ -25,7 +26,7 @@ public class GrapeController extends ControllerBase {
}
@GetMapping
(
""
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
index
()
{
var
grapes
=
grapeService
.
getAll
();
...
...
@@ -39,7 +40,7 @@ public class GrapeController extends ControllerBase {
}
@GetMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
int
id
)
{
var
grape
=
grapeService
.
get
(
id
);
if
(
grape
==
null
)
{
...
...
@@ -53,7 +54,7 @@ public class GrapeController extends ControllerBase {
}
@PostMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
@Valid
@ModelAttribute
(
"model"
)
GrapeUpsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -69,7 +70,7 @@ public class GrapeController extends ControllerBase {
}
@GetMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
()
{
var
viewModel
=
new
GrapeUpsertViewModel
();
initializeViewModel
(
viewModel
);
...
...
@@ -78,7 +79,7 @@ public class GrapeController extends ControllerBase {
}
@PostMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
(
@Valid
@ModelAttribute
(
"model"
)
GrapeUpsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -95,7 +96,7 @@ public class GrapeController extends ControllerBase {
@PostMapping
(
"/delete"
)
@ResponseBody
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
String
delete
(
long
id
)
{
try
{
grapeService
.
delete
(
GrapeDto
.
builder
().
id
(
id
).
build
());
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/HarvestController.java
View file @
8d0f7726
package
cz.muni.fi.pa165.winery.webapp.controllers
;
import
cz.muni.fi.pa165.winery.dto.wine.HarvestDto
;
import
cz.muni.fi.pa165.winery.enums.UserRoleType
;
import
cz.muni.fi.pa165.winery.services.wine.GrapeService
;
import
cz.muni.fi.pa165.winery.services.wine.HarvestService
;
import
cz.muni.fi.pa165.winery.webapp.models.ViewModelBase
;
...
...
@@ -33,7 +34,7 @@ public class HarvestController extends ControllerBase {
}
@GetMapping
(
""
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
index
()
{
var
harvests
=
harvestService
.
getAll
()
.
stream
()
...
...
@@ -61,7 +62,7 @@ public class HarvestController extends ControllerBase {
}
@GetMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
int
id
)
{
var
harvest
=
harvestService
.
get
(
id
);
if
(
harvest
==
null
)
{
...
...
@@ -78,7 +79,7 @@ public class HarvestController extends ControllerBase {
}
@PostMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
@Valid
@ModelAttribute
(
"model"
)
HarvestUpsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -94,7 +95,7 @@ public class HarvestController extends ControllerBase {
}
@GetMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
()
{
var
viewModel
=
new
HarvestUpsertViewModel
();
initializeViewModel
(
viewModel
);
...
...
@@ -104,7 +105,7 @@ public class HarvestController extends ControllerBase {
}
@PostMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
(
@Valid
@ModelAttribute
(
"model"
)
HarvestUpsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -121,7 +122,7 @@ public class HarvestController extends ControllerBase {
@PostMapping
(
"/delete"
)
@ResponseBody
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
String
delete
(
long
id
)
{
try
{
harvestService
.
delete
(
HarvestDto
.
builder
().
id
(
id
).
build
());
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/OrderController.java
View file @
8d0f7726
package
cz.muni.fi.pa165.winery.webapp.controllers
;
import
cz.muni.fi.pa165.winery.dto.order.OrderDto
;
import
cz.muni.fi.pa165.winery.enums.UserRoleType
;
import
cz.muni.fi.pa165.winery.services.order.OrderItemService
;
import
cz.muni.fi.pa165.winery.services.order.OrderService
;
import
cz.muni.fi.pa165.winery.services.user.UserService
;
...
...
@@ -31,7 +32,7 @@ public class OrderController extends ControllerBase {
}
@GetMapping
(
""
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
index
()
{
var
orders
=
new
ArrayList
<
OrderDto
>();
...
...
@@ -59,7 +60,7 @@ public class OrderController extends ControllerBase {
}
@GetMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
int
id
)
{
var
order
=
orderService
.
get
(
id
,
true
);
if
(
order
==
null
)
{
...
...
@@ -77,7 +78,7 @@ public class OrderController extends ControllerBase {
}
@PostMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
@Valid
@ModelAttribute
(
"model"
)
OrdersUpsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -109,7 +110,7 @@ public class OrderController extends ControllerBase {
@PostMapping
(
"/delete"
)
@ResponseBody
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
String
delete
(
long
id
)
{
orderService
.
delete
(
OrderDto
.
builder
().
id
(
id
).
items
(
new
HashSet
<>()).
build
());
return
"Successfuly deleted"
;
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/ProductReviewController.java
View file @
8d0f7726
package
cz.muni.fi.pa165.winery.webapp.controllers
;
import
cz.muni.fi.pa165.winery.dto.review.ProductReviewDto
;
import
cz.muni.fi.pa165.winery.enums.UserRoleType
;
import
cz.muni.fi.pa165.winery.services.review.ProductReviewService
;
import
cz.muni.fi.pa165.winery.services.user.UserService
;
import
cz.muni.fi.pa165.winery.services.wine.WineBottleService
;
...
...
@@ -137,7 +138,7 @@ public class ProductReviewController extends ControllerBase{
@PostMapping
(
"/delete"
)
@ResponseBody
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
String
delete
(
long
id
)
{
try
{
productReviewService
.
delete
(
ProductReviewDto
.
builder
().
id
(
id
).
build
());
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/UserController.java
View file @
8d0f7726
package
cz.muni.fi.pa165.winery.webapp.controllers
;
import
cz.muni.fi.pa165.winery.dto.user.UserDto
;
import
cz.muni.fi.pa165.winery.enums.UserRoleType
;
import
cz.muni.fi.pa165.winery.services.user.UserRoleService
;
import
cz.muni.fi.pa165.winery.services.user.UserService
;
import
cz.muni.fi.pa165.winery.webapp.models.user.UserInsertViewModel
;
...
...
@@ -33,7 +34,7 @@ public class UserController extends ControllerBase {
}
@GetMapping
(
""
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
index
()
{
var
users
=
userService
.
getAll
();
...
...
@@ -47,7 +48,7 @@ public class UserController extends ControllerBase {
}
@GetMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
int
id
)
{
var
user
=
userService
.
get
(
id
);
if
(
user
==
null
)
{
...
...
@@ -61,7 +62,7 @@ public class UserController extends ControllerBase {
}
@PostMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
@Valid
@ModelAttribute
(
"model"
)
UserUpdateViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -81,7 +82,7 @@ public class UserController extends ControllerBase {
}
@GetMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
()
{
var
viewModel
=
new
UserInsertViewModel
();
initializeViewModel
(
viewModel
);
...
...
@@ -90,7 +91,7 @@ public class UserController extends ControllerBase {
}
@PostMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
(
@Valid
@ModelAttribute
(
"model"
)
UserInsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -108,7 +109,7 @@ public class UserController extends ControllerBase {
@PostMapping
(
"/delete"
)
@ResponseBody
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
String
delete
(
long
id
)
{
try
{
userService
.
delete
(
UserDto
.
builder
().
id
(
id
).
roles
(
new
ArrayList
<>()).
build
());
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/WineBottleController.java
View file @
8d0f7726
package
cz.muni.fi.pa165.winery.webapp.controllers
;
import
cz.muni.fi.pa165.winery.dto.wine.WineBottleDto
;
import
cz.muni.fi.pa165.winery.enums.UserRoleType
;
import
cz.muni.fi.pa165.winery.services.wine.GrapeService
;
import
cz.muni.fi.pa165.winery.services.wine.WineBottleService
;
import
cz.muni.fi.pa165.winery.services.wine.WineTypeService
;
...
...
@@ -87,7 +88,7 @@ public class WineBottleController extends ControllerBase {
@GetMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
int
id
)
{
var
bottle
=
wineBottleService
.
get
(
id
);
if
(
bottle
==
null
)
{
...
...
@@ -106,7 +107,7 @@ public class WineBottleController extends ControllerBase {
}
@PostMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
@Valid
@ModelAttribute
(
"model"
)
WineBottleUpsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -122,7 +123,7 @@ public class WineBottleController extends ControllerBase {
}
@GetMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
()
{
var
viewModel
=
new
WineBottleUpsertViewModel
();
initializeViewModel
(
viewModel
);
...
...
@@ -131,7 +132,7 @@ public class WineBottleController extends ControllerBase {
}
@PostMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
(
@Valid
@ModelAttribute
(
"model"
)
WineBottleUpsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -148,7 +149,7 @@ public class WineBottleController extends ControllerBase {
@PostMapping
(
"/delete"
)
@ResponseBody
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
String
delete
(
long
id
)
{
try
{
wineBottleService
.
delete
(
WineBottleDto
.
builder
().
id
(
id
).
build
());
...
...
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/controllers/WineTypeController.java
View file @
8d0f7726
package
cz.muni.fi.pa165.winery.webapp.controllers
;
import
cz.muni.fi.pa165.winery.dto.wine.WineTypeDto
;
import
cz.muni.fi.pa165.winery.enums.UserRoleType
;
import
cz.muni.fi.pa165.winery.services.wine.GrapeService
;
import
cz.muni.fi.pa165.winery.services.wine.WineTypeService
;
import
cz.muni.fi.pa165.winery.webapp.models.ViewModelBase
;
...
...
@@ -32,7 +33,7 @@ public class WineTypeController extends ControllerBase {
}
@GetMapping
(
""
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
index
()
{
var
types
=
wineTypeService
.
getAll
();
...
...
@@ -56,7 +57,7 @@ public class WineTypeController extends ControllerBase {
}
@GetMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
int
id
)
{
var
type
=
wineTypeService
.
get
(
id
);
if
(
type
==
null
)
{
...
...
@@ -73,7 +74,7 @@ public class WineTypeController extends ControllerBase {
}
@PostMapping
(
"/edit"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
edit
(
@Valid
@ModelAttribute
(
"model"
)
WineTypeUpsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -89,7 +90,7 @@ public class WineTypeController extends ControllerBase {
}
@GetMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
()
{
var
viewModel
=
new
WineTypeUpsertViewModel
();
initializeViewModel
(
viewModel
);
...
...
@@ -98,7 +99,7 @@ public class WineTypeController extends ControllerBase {
}
@PostMapping
(
"/add"
)
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
ModelAndView
add
(
@Valid
@ModelAttribute
(
"model"
)
WineTypeUpsertViewModel
viewModel
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
return
view
(
bindingResult
.
getModel
());
...
...
@@ -115,7 +116,7 @@ public class WineTypeController extends ControllerBase {
@PostMapping
(
"/delete"
)
@ResponseBody
@Secured
(
"
ROLE_ADMIN
"
)
@Secured
(
UserRoleType
.
SPRING_
ROLE_ADMIN
)
public
String
delete
(
long
id
)
{
try
{
wineTypeService
.
delete
(
WineTypeDto
.
builder
().
id
(
id
).
build
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment