1 |
45658
|
michele.ar
|
package eu.dnetlib.administration.uis.modules.base;
|
2 |
41837
|
michele.ar
|
|
3 |
45655
|
michele.ar
|
import java.util.Arrays;
|
4 |
41837
|
michele.ar
|
import java.util.List;
|
5 |
45655
|
michele.ar
|
import java.util.stream.Collectors;
|
6 |
41837
|
michele.ar
|
|
7 |
45672
|
michele.ar
|
import org.springframework.beans.factory.annotation.Autowired;
|
8 |
45655
|
michele.ar
|
import org.springframework.ui.ModelMap;
|
9 |
41837
|
michele.ar
|
import org.springframework.web.bind.annotation.RequestBody;
|
10 |
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
11 |
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
12 |
45655
|
michele.ar
|
import org.springframework.web.bind.annotation.RestController;
|
13 |
41837
|
michele.ar
|
|
14 |
45655
|
michele.ar
|
import eu.dnetlib.administration.uis.annotations.Authorization;
|
15 |
|
|
import eu.dnetlib.administration.uis.annotations.MenuEntry;
|
16 |
|
|
import eu.dnetlib.administration.uis.annotations.MenuGroup;
|
17 |
45634
|
michele.ar
|
import eu.dnetlib.administration.uis.annotations.PermissionLevel;
|
18 |
45658
|
michele.ar
|
import eu.dnetlib.administration.uis.auth.AuthorizationDAO;
|
19 |
|
|
import eu.dnetlib.administration.uis.auth.User;
|
20 |
|
|
import eu.dnetlib.administration.uis.modules.UIModule;
|
21 |
45687
|
michele.ar
|
import eu.dnetlib.exceptions.DnetGenericException;
|
22 |
41837
|
michele.ar
|
|
23 |
45655
|
michele.ar
|
@RestController
|
24 |
45676
|
michele.ar
|
@RequestMapping("/ajax/users")
|
25 |
45655
|
michele.ar
|
@MenuEntry("Users")
|
26 |
|
|
@MenuGroup("Configuration")
|
27 |
|
|
@Authorization(PermissionLevel.SUPER_ADMIN)
|
28 |
|
|
public class UsersModule extends UIModule {
|
29 |
|
|
|
30 |
45672
|
michele.ar
|
@Autowired
|
31 |
41837
|
michele.ar
|
private AuthorizationDAO dao;
|
32 |
45655
|
michele.ar
|
|
33 |
45687
|
michele.ar
|
@RequestMapping(value = "", method = RequestMethod.GET)
|
34 |
|
|
public List<User> listUsers() throws DnetGenericException {
|
35 |
|
|
return dao.getPermissionLevels().entrySet()
|
36 |
|
|
.stream()
|
37 |
|
|
.map(e -> new User(e.getKey(), null, null, e.getValue()))
|
38 |
|
|
.sorted()
|
39 |
|
|
.collect(Collectors.toList());
|
40 |
41837
|
michele.ar
|
}
|
41 |
|
|
|
42 |
45687
|
michele.ar
|
@RequestMapping(value = "", method = RequestMethod.POST)
|
43 |
|
|
public boolean updateUsers(@RequestBody final List<User> users) throws DnetGenericException {
|
44 |
|
|
dao.updatePermissionLevels(users.stream().collect(Collectors.toMap(User::getId, User::getPermissionLevels)));
|
45 |
41837
|
michele.ar
|
return true;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
45655
|
michele.ar
|
@Override
|
49 |
|
|
public void populateModelMap(final ModelMap map) {
|
50 |
|
|
map.addAttribute("availableLevels", Arrays.stream(PermissionLevel.values()).map(PermissionLevel::asMap).collect(Collectors.toList()));
|
51 |
|
|
}
|
52 |
|
|
|
53 |
41837
|
michele.ar
|
}
|