|
23 | 23 | import static de.tudarmstadt.ukp.clarin.webanno.security.UserDao.EMPTY_PASSWORD;
|
24 | 24 | import static de.tudarmstadt.ukp.clarin.webanno.security.UserDao.REALM_PROJECT_PREFIX;
|
25 | 25 | import static de.tudarmstadt.ukp.clarin.webanno.security.model.Role.ROLE_USER;
|
| 26 | +import static java.lang.String.format; |
26 | 27 | import static org.apache.commons.lang3.StringUtils.startsWith;
|
27 | 28 |
|
28 | 29 | import java.io.File;
|
@@ -125,33 +126,39 @@ public void importData(ProjectImportRequest aRequest, Project aProject,
|
125 | 126 | ExportedUser[] projectUsers = aExProject.getArrayProperty(KEY_USERS, ExportedUser.class);
|
126 | 127 | Set<String> projectUserNames = new HashSet<>();
|
127 | 128 | for (ExportedUser importedUser : projectUsers) {
|
128 |
| - if (!userService.exists(importedUser.getUsername())) { |
129 |
| - User u = new User(); |
130 |
| - u.setRealm(REALM_PROJECT_PREFIX + aProject.getId()); |
131 |
| - u.setEmail(importedUser.getEmail()); |
132 |
| - u.setUiName(importedUser.getUiName()); |
133 |
| - u.setUsername(importedUser.getUsername()); |
134 |
| - u.setCreated(importedUser.getCreated()); |
135 |
| - u.setLastLogin(importedUser.getLastLogin()); |
136 |
| - u.setUpdated(importedUser.getUpdated()); |
137 |
| - u.setEnabled(importedUser.isEnabled()); |
138 |
| - u.setRoles(Set.of(ROLE_USER)); |
139 |
| - userService.create(u); |
140 |
| - |
141 |
| - // Ok, this is a bug... if we export a project and then import it again into the |
142 |
| - // same instance, then the users are not created (because they exist already) |
143 |
| - // and thus the clone of the project does not have any project-bound users. |
144 |
| - // ... but ... |
145 |
| - // if we instead add users that pre-existed to this set, then we can end up adding |
146 |
| - // project-bound users from another project (i.e. from the original one which we |
147 |
| - // are cloning). That means if the original project is deleted, then the users |
148 |
| - // will be deleted and this our clone project gets its users removed. Also not good. |
149 |
| - // |
150 |
| - // So we currently stick with not importing permissions for project-bound users |
151 |
| - // from the original project... this can be fixed when/if at some point we allow |
152 |
| - // re-mapping users during import - or if we have some smart idea... |
153 |
| - projectUserNames.add(importedUser.getUsername()); |
| 129 | + if (userService.exists(importedUser.getUsername())) { |
| 130 | + aRequest.addMessage(format("Unable to create project-bound user [%s] with ID " |
| 131 | + + "[%s] because a user with this ID already exists in the system. " |
| 132 | + + "Annotations of this user are not accessible in the imported project.", |
| 133 | + importedUser.getUiName(), importedUser.getUsername())); |
| 134 | + continue; |
154 | 135 | }
|
| 136 | + |
| 137 | + User u = new User(); |
| 138 | + u.setRealm(REALM_PROJECT_PREFIX + aProject.getId()); |
| 139 | + u.setEmail(importedUser.getEmail()); |
| 140 | + u.setUiName(importedUser.getUiName()); |
| 141 | + u.setUsername(importedUser.getUsername()); |
| 142 | + u.setCreated(importedUser.getCreated()); |
| 143 | + u.setLastLogin(importedUser.getLastLogin()); |
| 144 | + u.setUpdated(importedUser.getUpdated()); |
| 145 | + u.setEnabled(importedUser.isEnabled()); |
| 146 | + u.setRoles(Set.of(ROLE_USER)); |
| 147 | + userService.create(u); |
| 148 | + |
| 149 | + // Ok, this is a bug... if we export a project and then import it again into the |
| 150 | + // same instance, then the users are not created (because they exist already) |
| 151 | + // and thus the clone of the project does not have any project-bound users. |
| 152 | + // ... but ... |
| 153 | + // if we instead add users that pre-existed to this set, then we can end up adding |
| 154 | + // project-bound users from another project (i.e. from the original one which we |
| 155 | + // are cloning). That means if the original project is deleted, then the users |
| 156 | + // will be deleted and this our clone project gets its users removed. Also not good. |
| 157 | + // |
| 158 | + // So we currently stick with not importing permissions for project-bound users |
| 159 | + // from the original project... this can be fixed when/if at some point we allow |
| 160 | + // re-mapping users during import - or if we have some smart idea... |
| 161 | + projectUserNames.add(importedUser.getUsername()); |
155 | 162 | }
|
156 | 163 |
|
157 | 164 | // Import permissions - always import permissions for the importing user and for
|
|
0 commit comments