Skip to content

Commit

Permalink
#486 - UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Aug 4, 2018
1 parent eb6a444 commit 0daf809
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ public String getRole() {
public String getDescription() {
return role.getDescription();
}

public String getTarget() { return role.getTarget().name(); }
}

private static final class PasswordModification {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/alfio/manager/user/UserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import alfio.repository.user.OrganizationRepository;
import alfio.repository.user.UserRepository;
import alfio.repository.user.join.UserOrganizationRepository;
import alfio.util.OptionalWrapper;
import alfio.util.PasswordGenerator;
import ch.digitalfondue.npjt.AffectedRowCountAndKey;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -244,7 +245,11 @@ public void enable(int userId, String currentUsername, boolean status) {
}

public ValidationResult validateUser(Integer id, String username, int organizationId, String role, String firstName, String lastName, String emailAddress) {
if(userRepository.findByUsername(username).isPresent()) {

Optional<User> existing = Optional.ofNullable(id)
.flatMap(uid -> OptionalWrapper.optionally(() -> userRepository.findById(uid)));

if(!existing.filter(e -> e.getUsername().equals(username)).isPresent() && usernameExists(username)) {
return ValidationResult.failed(new ValidationResult.ErrorDescriptor("username", "There is already another user with the same username."));
}
return ValidationResult.of(Stream.of(Pair.of(firstName, "firstName"), Pair.of(lastName, "lastName"), Pair.of(emailAddress, "emailAddress"))
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/alfio/model/user/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@

@Getter
public enum Role {
ADMIN("ROLE_ADMIN", "Administrator"),
OWNER("ROLE_OWNER", "Organization owner"),
SUPERVISOR("ROLE_SUPERVISOR", "Check-in supervisor"),
OPERATOR("ROLE_OPERATOR", "Check-in operator"),
SPONSOR("ROLE_SPONSOR", "Sponsor"),
API_CONSUMER("ROLE_API_CLIENT", "API Client");
ADMIN("ROLE_ADMIN", "Administrator", RoleTarget.ADMIN),
OWNER("ROLE_OWNER", "Organization owner", RoleTarget.USER),
SUPERVISOR("ROLE_SUPERVISOR", "Check-in supervisor", RoleTarget.USER),
OPERATOR("ROLE_OPERATOR", "Check-in operator", RoleTarget.API_KEY),
SPONSOR("ROLE_SPONSOR", "Sponsor", RoleTarget.API_KEY),
API_CONSUMER("ROLE_API_CLIENT", "API Client", RoleTarget.API_KEY);

private final String roleName;
private final String description;
private final RoleTarget target;

Role(String roleName, String description) {
Role(String roleName, String description, RoleTarget target) {
this.roleName = roleName;
this.description = description;
this.target = target;
}

public static Role fromRoleName(String roleName) {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/alfio/model/user/RoleTarget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* This file is part of alf.io.
*
* alf.io is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* alf.io is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with alf.io. If not, see <http://www.gnu.org/licenses/>.
*/
package alfio.model.user;

public enum RoleTarget {
ADMIN, USER, API_KEY
}
20 changes: 10 additions & 10 deletions src/main/webapp/resources/js/admin/feature/user-edit/user-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@
<select data-ng-model="$ctrl.user.role" name="role" class="form-control" id="role" data-required data-ng-options="r.role as r.description for r in $ctrl.roles"></select>
<field-error data-form-obj="editUser" data-field-obj="$ctrl.editUser.role"></field-error>
<script type="text/ng-template" id="helpUserRole.html">
<h4>User Role:</h4>
<h4><span ng-if="$ctrl.user.type == 'USER'">User</span> Role:</h4>
<ul class="list-group">
<li class="list-group-item">
<li class="list-group-item" ng-if="$ctrl.user.type == 'USER'">
<div class="list-group-item-heading"><strong>Organization owner</strong></div>
<div class="list-group-item-text">
Can view and update all the events, he/she can also create other users and access the configuration at organization and event level.
</div>
</li>
<li class="list-group-item">
<li class="list-group-item" ng-if="$ctrl.user.type == 'USER'">
<div class="list-group-item-heading"><strong>Check-in supervisor</strong></div>
<div class="list-group-item-text">
Can view all the events, he/she can also perform the check-in using either the web interface or the app.
Has a limited access to the events (e.g. can't see the statistics), he/she can also perform the check-in using the web interface.
</div>
</li>
<li class="list-group-item">
<li class="list-group-item" ng-if="$ctrl.user.type == 'API_KEY'">
<div class="list-group-item-heading"><strong>Check-in operator</strong></div>
<div class="list-group-item-text">
Can only perform the check-in using the app. Access on the web GUI is denied.
Can only perform the check-in using the app. Access on the web admin is denied.
</div>
</li>
<li class="list-group-item">
<li class="list-group-item" ng-if="$ctrl.user.type == 'API_KEY'">
<div class="list-group-item-heading"><strong>Sponsor</strong></div>
<div class="list-group-item-text">
Can only scan checked-in badges using the app and collect attendees' data. Access on the web GUI is denied.
Can only scan checked-in badges using the app and collect attendees' data. Access on the web admin is denied.
</div>
</li>
<li class="list-group-item">
<li class="list-group-item" ng-if="$ctrl.user.type == 'API_KEY'">
<div class="list-group-item-heading"><strong>API Client</strong></div>
<div class="list-group-item-text">
Technical user for integrating external systems (such as CMS) with Alf.io
Technical user for integrating external systems (such as CMS) with Alf.io. Access on the web admin and the mobile app is denied.
</div>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@

ctrl.$onInit = function() {
ctrl.user = {};

if (ctrl.for === 'apikey') {
ctrl.user.type = 'API_KEY';
} else {
ctrl.user.type = 'USER';
}

ctrl.organizations = [];
ctrl.roles = [];

$q.all([OrganizationService.getAllOrganizations(), UserService.getAllRoles()]).then(function(results) {
ctrl.organizations = results[0].data;
ctrl.roles = results[1].data;
ctrl.roles = _.filter(results[1].data, function(r) { return r.target === ctrl.user.type; });
});

if(ctrl.type === 'edit') {
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/resources/js/admin/feature/users/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
}).filter('orgSelected', function() {
return function(list, orgId) {
if(orgId == null || orgId == undefined) {
if(orgId == null || !angular.isDefined(orgId)) {
return list;
}
return _.filter(list, function(e) { return _.any(e.memberOf, function(i) { return i.id === orgId })})
Expand All @@ -38,7 +38,7 @@
loadUsers();
};

var filterFunction = ctrl.type == 'user' ? function(user) {return user.type !== 'API_KEY'} : function(user) {return user.type === 'API_KEY'};
var filterFunction = function(user) { return ctrl.type === 'user' ^ user.type === 'API_KEY'; };

function loadUsers() {
self.loading = true;
Expand Down

0 comments on commit 0daf809

Please sign in to comment.