Skip to content

Commit 051a651

Browse files
committed
replace togglz by authority
1 parent eeb1127 commit 051a651

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public final class Authority {
3030
public static final GrantedAuthority CREATE_CATEGORY = new SimpleGrantedAuthority(StringAuthority.CREATE_CATEGORY);
3131
public static final GrantedAuthority CREATE_COUNTRY = new SimpleGrantedAuthority(StringAuthority.CREATE_COUNTRY);
3232
public static final GrantedAuthority CREATE_SERIES = new SimpleGrantedAuthority(StringAuthority.CREATE_SERIES);
33+
public static final GrantedAuthority DOWNLOAD_IMAGE = new SimpleGrantedAuthority(StringAuthority.DOWNLOAD_IMAGE);
3334
public static final GrantedAuthority UPDATE_COLLECTION = new SimpleGrantedAuthority(StringAuthority.UPDATE_COLLECTION);
3435
public static final GrantedAuthority VIEW_SITE_EVENTS = new SimpleGrantedAuthority(StringAuthority.VIEW_SITE_EVENTS);
3536
public static final GrantedAuthority VIEW_SERIES_SALES = new SimpleGrantedAuthority(StringAuthority.VIEW_SERIES_SALES);

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

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private static Collection<? extends GrantedAuthority> getAuthorities(UserDetails
7979
authorities.add(Authority.VIEW_SITE_EVENTS);
8080
authorities.add(Authority.ADD_PARTICIPANT);
8181
authorities.add(Authority.ADD_SERIES_SALES);
82+
authorities.add(Authority.DOWNLOAD_IMAGE);
8283
authorities.add(Authority.VIEW_SERIES_SALES);
8384
authorities.add(Authority.MANAGE_TOGGLZ);
8485
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public final class StringAuthority {
2626
public static final String CREATE_CATEGORY = "CREATE_CATEGORY";
2727
public static final String CREATE_COUNTRY = "CREATE_COUNTRY";
2828
public static final String CREATE_SERIES = "CREATE_SERIES";
29+
public static final String DOWNLOAD_IMAGE = "DOWNLOAD_IMAGE";
2930
public static final String UPDATE_COLLECTION = "UPDATE_COLLECTION";
3031
public static final String VIEW_SITE_EVENTS = "VIEW_SITE_EVENTS";
3132
public static final String VIEW_SERIES_SALES = "VIEW_SERIES_SALES";

src/main/java/ru/mystamps/web/support/togglz/Features.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ public enum Features implements Feature {
8282

8383
@Label("/series/add: show link with auto-suggestions")
8484
@EnabledByDefault
85-
SHOW_SUGGESTION_LINK,
86-
87-
@Label("/series/add: possibility to download image from external server")
88-
@EnabledByDefault
89-
DOWNLOAD_IMAGE;
85+
SHOW_SUGGESTION_LINK;
9086

9187
public boolean isActive() {
9288
return FeatureContext.getFeatureManager().isActive(this);

src/main/webapp/WEB-INF/views/series/add.html

+10-6
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,16 @@ <h3 th:text="${#strings.capitalize(add_series)}">
263263
Image
264264
</span>
265265
<!--/*/
266-
<span id="image.required" class="required_field" togglz:inactive="DOWNLOAD_IMAGE">*</span>
266+
<span id="image.required" class="required_field" th:if="${not #authorization.expression('hasAuthority(''DOWNLOAD_IMAGE'')')}">*</span>
267267
/*/-->
268268
</label>
269269
<div class="col-sm-7">
270-
<input type="file" id="image" style="box-shadow: none; border: 0px;" accept="image/png,image/jpeg" th:field="*{image}" togglz:active="DOWNLOAD_IMAGE"/>
271-
<!--/*/
272-
<input type="file" id="image" style="box-shadow: none; border: 0px;" required="required" accept="image/png,image/jpeg" th:field="*{image}" togglz:inactive="DOWNLOAD_IMAGE"/>
273-
/*/-->
270+
<input id="image"
271+
type="file"
272+
style="box-shadow: none; border: 0px;"
273+
accept="image/png,image/jpeg"
274+
th:field="*{image}"
275+
th:attr="required=${not #authorization.expression('hasAuthority(''DOWNLOAD_IMAGE'')') ? 'required' : null}" />
274276
<small togglz:active="ADD_ADDITIONAL_IMAGES_TO_SERIES" sec:authorize="hasAuthority('ADD_IMAGES_TO_SERIES')">
275277
<span class="hint-block" th:text="#{t_add_more_images_hint}">
276278
Later you will be able to add additional images
@@ -282,7 +284,9 @@ <h3 th:text="${#strings.capitalize(add_series)}">
282284
</div>
283285
</div>
284286

285-
<div class="form-group form-group-sm" th:classappend="${#fields.hasErrors('imageUrl') or #fields.hasErrors('downloadedImage') ? 'has-error' : ''}" togglz:active="DOWNLOAD_IMAGE">
287+
<div class="form-group form-group-sm"
288+
th:classappend="${#fields.hasErrors('imageUrl') or #fields.hasErrors('downloadedImage') ? 'has-error' : ''}"
289+
sec:authorize="hasAuthority('DOWNLOAD_IMAGE')">
286290
<label for="image-url" class="control-label col-sm-3">
287291
<span class="field-label" th:text="#{t_image_url}">
288292
Image URL

0 commit comments

Comments
 (0)