Unverified Commit f452a65d authored by Makhtar DIAGNE's avatar Makhtar DIAGNE Committed by GitHub
Browse files

Ajout de la propriété siteCode à l'utilisateur (#55)



* [FENIX-58] add siteCode to user

* [FENIX-58] add static constant for sitecode

* [FENIX-58] remove println

* [FENIX-58] add siteCode to user creation & update

* [FENIX-58] add a script to init user's siteCode with an empty string if the property does not exist

* [FENIX-86] add siteCode to allowed keys
Co-authored-by: default avatarMounir Nayab <mounir.nayab@xelians.fr>
parent cc883b9d
......@@ -182,7 +182,7 @@ public class UserExternalService extends AbstractResourceClientService<UserDto,
@Override
protected Collection<String> getAllowedKeys() {
return Arrays.asList("id", "lastname", "firstname", "identifier", "groupId", "language", "email", "otp",
"subrogeable", "phone", "mobile", "lastConnection", "status", "level", TYPE_KEY, CUSTOMER_ID_KEY);
"subrogeable", "phone", "mobile", "lastConnection", "status", "level", TYPE_KEY, CUSTOMER_ID_KEY, "siteCode");
}
@Override
......
......@@ -89,6 +89,8 @@ public class UserConverter implements Converter<UserDto, User> {
*/
public static final String BLOCKED_DURATION = "Durée du blocage";
public static final String SITE_CODE = "Code du site";
private final GroupRepository groupRepository;
private final AddressConverter addressConverter;
......@@ -111,6 +113,7 @@ public class UserConverter implements Converter<UserDto, User> {
userLogbookData.put(STATUS_KEY, LogbookUtils.getValue(user.getStatus().toString()));
userLogbookData.put(SUBROGEABLE_KEY, LogbookUtils.getValue(user.isSubrogeable()));
userLogbookData.put(OTP_KEY, LogbookUtils.getValue(user.isOtp()));
userLogbookData.put(SITE_CODE, LogbookUtils.getValue(user.getSiteCode()));
AddressDto address = user.getAddress() != null ? user.getAddress() : new AddressDto();
addressConverter.addAddress(address, userLogbookData);
Optional<Group> group = groupRepository.findById(user.getGroupId());
......
......@@ -129,4 +129,6 @@ public class User extends CustomerIdDocument implements BaseIdentifierDocument {
private OffsetDateTime passwordExpirationDate;
private Address address = new Address();
private String siteCode;
}
......@@ -559,6 +559,10 @@ public class UserInternalService extends VitamUICrudService<UserDto, User> {
}
addressService.processPatch(user.getAddress(), CastUtils.toMap(entry.getValue()), logbooks);
break;
case "siteCode" :
logbooks.add(new EventDiffDto(UserConverter.SITE_CODE, user.getSiteCode(), entry.getValue()));
user.setSiteCode(CastUtils.toString(entry.getValue()));
break;
default :
throw new IllegalArgumentException("Unable to patch group " + user.getId() + ": key " + entry.getKey() + " is not allowed");
}
......
......@@ -307,6 +307,7 @@ public final class UserInternalServiceIntegTest extends AbstractLogbookIntegrati
final GroupDto group = new GroupDto();
group.setEnabled(true);
group.setCustomerId(customerId);
user.setSiteCode("001");
Mockito.when(customerRepository.findById(any())).thenReturn(Optional.of(customer));
Mockito.when(groupInternalService.getOne(any(), any(), any())).thenReturn(group);
Mockito.when(internalSecurityService.isLevelAllowed(any())).thenReturn(true);
......@@ -338,6 +339,7 @@ public final class UserInternalServiceIntegTest extends AbstractLogbookIntegrati
+ "\"Statut\":\"ENABLED\","
+ "\"Subrogeable\":\"false\","
+ "\"OTP\":\"true\","
+ "\"Code du site\":\"001\","
+ "\"Nom de la rue\":\"rue faubourg poissoniére\","
+ "\"Code postal\":\"75009\","
+ "\"Ville\":\"paris\","
......@@ -400,9 +402,13 @@ public final class UserInternalServiceIntegTest extends AbstractLogbookIntegrati
internalUserService.patch(partialDto);
partialDto.remove("otp");
partialDto.put("siteCode", "001");
internalUserService.patch(partialDto);
partialDto.remove("siteCode");
final Collection<Event> events = eventRepository
.findAll(Query.query(Criteria.where("obId").is(user.getIdentifier()).and("evType").is(EventType.EXT_VITAMUI_UPDATE_USER)));
assertThat(events).hasSize(11);
assertThat(events).hasSize(12);
}
......
......@@ -66,6 +66,7 @@ import static fr.gouv.vitamui.commons.api.CommonConstants.SUPER_USER_ATTRIBUTE;
import static fr.gouv.vitamui.commons.api.CommonConstants.SUPER_USER_IDENTIFIER_ATTRIBUTE;
import static fr.gouv.vitamui.commons.api.CommonConstants.SURROGATION_PARAMETER;
import static fr.gouv.vitamui.commons.api.CommonConstants.TENANTS_BY_APP_ATTRIBUTE;
import static fr.gouv.vitamui.commons.api.CommonConstants.SITE_CODE;
import static fr.gouv.vitamui.commons.api.CommonConstants.TYPE_ATTRIBUTE;
import static fr.gouv.vitamui.commons.api.CommonConstants.USER_ID_ATTRIBUTE;
......@@ -217,6 +218,7 @@ public class UserPrincipalResolver implements PrincipalResolver {
attributes.put(AUTHTOKEN_ATTRIBUTE, Collections.singletonList(authUser.getAuthToken()));
attributes.put(PROOF_TENANT_ID_ATTRIBUTE, Collections.singletonList(authUser.getProofTenantIdentifier()));
attributes.put(TENANTS_BY_APP_ATTRIBUTE, Collections.singletonList(new CasJsonWrapper(authUser.getTenantsByApp())));
attributes.put(SITE_CODE, Collections.singletonList(user.getSiteCode()));
final Set<String> roles = new HashSet<>();
final List<ProfileDto> profiles = authUser.getProfileGroup().getProfiles();
profiles.forEach(profile -> profile.getRoles().forEach(role -> roles.add(role.getName())));
......
......@@ -167,6 +167,8 @@ public class CommonConstants {
public static final String TENANTS_BY_APP_ATTRIBUTE = "tenantsByApp";
public static final String SITE_CODE = "siteCode";
public static final String CUSTOMER_ID_ATTRIBUTE = "customerId";
public static final String CUSTOMER_IDENTIFIER_ATTRIBUTE = "customerIdentifier";
......
......@@ -110,4 +110,6 @@ public class UserDto extends CustomerIdDto {
private OffsetDateTime passwordExpirationDate;
private AddressDto address = new AddressDto();
private String siteCode;
}
......@@ -116,6 +116,7 @@ public class AuthUserDto extends UserDto implements UserDetails {
setNbFailedAttempts(user.getNbFailedAttempts());
setPasswordExpirationDate(user.getPasswordExpirationDate());
setGroupId(user.getGroupId());
setSiteCode(user.getSiteCode());
}
public AuthUserDto(final String username, final Map<String, Object> attributes) {
......@@ -244,6 +245,9 @@ public class AuthUserDto extends UserDto implements UserDetails {
setTenantsByApp((List<TenantInformationDto>) parseJson(value, new TypeReference<List<TenantInformationDto>>() {
}));
break;
case SITE_CODE :
setSiteCode((String) value);
break;
}
}
}
......@@ -296,6 +300,7 @@ public class AuthUserDto extends UserDto implements UserDetails {
user.setNbFailedAttempts(getNbFailedAttempts());
user.setPasswordExpirationDate(getPasswordExpirationDate());
user.setGroupId(getGroupId());
user.setSiteCode(getSiteCode());
return user;
}
}
db = db.getSiblingDB('iam')
print("START FENIX-58_init_user_sitecode_ref.js");
// Update all users without siteCode : add an empty siteCode
db.users.updateMany(
{"siteCode": {$exists: false}},
{
$set: {
"siteCode": ""
}
}
);
print("END FENIX-58_init_user_sitecode_ref.js");
......@@ -56,5 +56,5 @@ export interface AuthUser extends User {
username: string;
customerIdentifier: string;
basicCustomer: BasicCustomer;
siteCode: string;
}
......@@ -57,5 +57,6 @@ export interface User extends Id {
lastConnection: string;
readonly: boolean;
address: Address;
siteCode: string;
}
......@@ -198,6 +198,12 @@
</div>
</ng-container>
<div>
<vitamui-common-input class="field-site-code" formControlName="siteCode" placeholder="Code du site"
i18n-placeholder="user create siteCode@@userCreateSiteCode">
</vitamui-common-input>
</div>
<div class="actions">
<button type="button" class="btn primary" cdkStepperNext [disabled]="form.get('address').pending || form.get('address').invalid"
i18n="user create next step otp@@userCreateNextStepOtpButton">
......
......@@ -68,6 +68,11 @@ h2 {
margin-right: $field-spacing;
}
.field-site-code {
width: 160px;
margin-right: $field-spacing;
}
.field-city {
width: 260px;
margin-right: $field-spacing;
......
......@@ -140,7 +140,8 @@ export class UserCreateComponent implements OnInit, OnDestroy {
zipCode: [null],
city: [null],
country: ['FR']
})
}),
siteCode: [null],
},
{ validator: UserValidators.missingPhoneNumber }
);
......
......@@ -99,6 +99,14 @@
</div>
</ng-container>
<div class="row">
<div class="col-6 form-control">
<vitamui-common-editable-input formControlName="siteCode" label="Code du site"
i18n-label="user info tab siteCode@@UserInfoTabSiteCode">
</vitamui-common-editable-input>
</div>
</div>
<div class="row">
<div class="col-6 form-control">
<vitamui-common-editable-input formControlName="level" label="Niveau du groupe"
......
......@@ -74,7 +74,8 @@ let expectedUser: User = {
zipCode: '75009',
city: 'paris',
country: 'france'
}
},
siteCode: '001'
};
let expectedCustomer: Customer = {
......@@ -182,7 +183,8 @@ describe('UserInfoTabComponent', () => {
zipCode: '75009',
city: 'paris',
country: 'france'
}
},
siteCode: '001'
};
expectedCustomer = {
id: 'idCustomer',
......
......@@ -85,7 +85,8 @@ export class UserInfoTabComponent implements OnChanges {
zipCode: string,
city: string,
country: string,
}
},
siteCode: string
};
clientEmailDomains: string[];
......@@ -115,7 +116,8 @@ export class UserInfoTabComponent implements OnChanges {
zipCode: [null, Validators.required],
city: [null, Validators.required],
country: [null, Validators.required],
})
}),
siteCode: [null],
});
this.form.get('mobile').valueChanges.subscribe(() => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment