Skip to content

Commit d429810

Browse files
committed
fix: grant the access to everyone's estimation page to users with an admin role.
Implementation details: - VIEW_ANY_ESTIMATION authority has been added and granted to the users with admin role Fix #889
1 parent 89e2bcc commit d429810

File tree

7 files changed

+15
-6
lines changed

7 files changed

+15
-6
lines changed

src/main/java/ru/mystamps/web/feature/collection/CollectionServiceImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public List<SeriesInCollectionDto> findSeriesInCollection(Integer collectionId,
167167

168168
@Override
169169
@Transactional(readOnly = true)
170-
@PreAuthorize(HasAuthority.ADD_SERIES_PRICE_AND_COLLECTION_OWNER)
170+
@PreAuthorize(HasAuthority.ADD_SERIES_PRICE_AND_COLLECTION_OWNER_OR_VIEW_ANY_ESTIMATION)
171171
public List<SeriesInCollectionWithPriceDto> findSeriesWithPricesBySlug(
172172
String slug,
173173
String lang) {

src/main/java/ru/mystamps/web/support/spring/security/Authority.java

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public final class Authority {
3636
public static final GrantedAuthority IMPORT_SERIES_SALES = new SimpleGrantedAuthority(StringAuthority.IMPORT_SERIES_SALES);
3737
public static final GrantedAuthority MANAGE_TOGGLZ = new SimpleGrantedAuthority(StringAuthority.MANAGE_TOGGLZ);
3838
public static final GrantedAuthority UPDATE_COLLECTION = new SimpleGrantedAuthority(StringAuthority.UPDATE_COLLECTION);
39+
public static final GrantedAuthority VIEW_ANY_ESTIMATION = new SimpleGrantedAuthority(StringAuthority.VIEW_ANY_ESTIMATION);
3940
public static final GrantedAuthority VIEW_DAILY_STATS = new SimpleGrantedAuthority(StringAuthority.VIEW_DAILY_STATS);
4041
public static final GrantedAuthority VIEW_SERIES_SALES = new SimpleGrantedAuthority(StringAuthority.VIEW_SERIES_SALES);
4142
public static final GrantedAuthority VIEW_SITE_EVENTS = new SimpleGrantedAuthority(StringAuthority.VIEW_SITE_EVENTS);

src/main/java/ru/mystamps/web/support/spring/security/CustomUserDetailsService.java

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private static Collection<? extends GrantedAuthority> getAuthorities(UserDetails
8080
authorities.add(Authority.IMPORT_SERIES);
8181
authorities.add(Authority.IMPORT_SERIES_SALES);
8282
authorities.add(Authority.MANAGE_TOGGLZ);
83+
authorities.add(Authority.VIEW_ANY_ESTIMATION);
8384
authorities.add(Authority.VIEW_DAILY_STATS);
8485
authorities.add(Authority.VIEW_SERIES_SALES);
8586
authorities.add(Authority.VIEW_SITE_EVENTS);

src/main/java/ru/mystamps/web/support/spring/security/HasAuthority.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ public final class HasAuthority {
2222
// Constants sorted in an ascending order.
2323
public static final String ADD_PARTICIPANT = "hasAuthority('" + StringAuthority.ADD_PARTICIPANT + "')";
2424
@SuppressWarnings("PMD.LongVariable")
25-
public static final String ADD_SERIES_PRICE_AND_COLLECTION_OWNER
26-
= "hasAuthority('" + StringAuthority.ADD_SERIES_PRICE + "') and principal?.userCollectionSlug == #slug";
25+
public static final String ADD_SERIES_PRICE_AND_COLLECTION_OWNER_OR_VIEW_ANY_ESTIMATION =
26+
"("
27+
+ "hasAuthority('" + StringAuthority.ADD_SERIES_PRICE + "') "
28+
+ "and "
29+
+ "principal?.userCollectionSlug == #slug"
30+
+ ") "
31+
+ "or "
32+
+ "hasAuthority('" + StringAuthority.VIEW_ANY_ESTIMATION + "')";
2733
public static final String ADD_SERIES_SALES = "hasAuthority('" + StringAuthority.ADD_SERIES_SALES + "')";
2834
public static final String CREATE_CATEGORY = "hasAuthority('" + StringAuthority.CREATE_CATEGORY + "')";
2935
public static final String CREATE_COUNTRY = "hasAuthority('" + StringAuthority.CREATE_COUNTRY + "')";

src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ protected void configure(HttpSecurity http) throws Exception {
9292
.mvcMatchers(Url.SITE_EVENTS_PAGE).hasAuthority(StringAuthority.VIEW_SITE_EVENTS)
9393
.mvcMatchers(CountryUrl.SUGGEST_SERIES_COUNTRY).hasAuthority(StringAuthority.CREATE_SERIES)
9494
.mvcMatchers(Url.DAILY_STATISTICS).hasAuthority(StringAuthority.VIEW_DAILY_STATS)
95-
// @todo #884 /collection/{slug}/estimation: only owner should have access to estimation page
96-
.mvcMatchers(CollectionUrl.ESTIMATION_COLLECTION_PAGE).hasAuthority(StringAuthority.ADD_SERIES_PRICE)
95+
.mvcMatchers(CollectionUrl.ESTIMATION_COLLECTION_PAGE)
96+
.access(HasAuthority.ADD_SERIES_PRICE_AND_COLLECTION_OWNER_OR_VIEW_ANY_ESTIMATION)
9797
.regexMatchers(HttpMethod.POST, "/series/[0-9]+")
9898
.hasAnyAuthority(
9999
StringAuthority.UPDATE_COLLECTION,

src/main/java/ru/mystamps/web/support/spring/security/StringAuthority.java

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public final class StringAuthority {
3232
public static final String IMPORT_SERIES_SALES = "IMPORT_SERIES_SALES";
3333
public static final String MANAGE_TOGGLZ = "MANAGE_TOGGLZ";
3434
public static final String UPDATE_COLLECTION = "UPDATE_COLLECTION";
35+
public static final String VIEW_ANY_ESTIMATION = "VIEW_ANY_ESTIMATION";
3536
public static final String VIEW_DAILY_STATS = "VIEW_DAILY_STATS";
3637
public static final String VIEW_SERIES_SALES = "VIEW_SERIES_SALES";
3738
public static final String VIEW_SITE_EVENTS = "VIEW_SITE_EVENTS";

src/test/robotframework/collection/estimation/access.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Paid user has access only to its own estimation page
2828
Admin has access only to its own estimation page
2929
Log In As login=admin password=test openPage=${true}
3030
Go To ${SITE_URL}/collection/paid/estimation
31-
Element Text Should Be id=error-msg Forbidden
31+
Element Text Should Be tag=h3 Paid User's collection
3232
Go To ${SITE_URL}/collection/admin/estimation
3333
Element Text Should Be tag=h3 Site Admin's collection
3434
# No need to log out as a browser will be closed after the test

0 commit comments

Comments
 (0)