Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added field to confirm that dh_user agrees to personal data collection #524

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public UserVO createUser(@NotNull UserVO user, String password) {
if (user.getAllDeviceTypesAvailable() == null) {
user.setAllDeviceTypesAvailable(true);
}

if (user.getAgreedToPersonalDataCollection() == null) {
user.setAgreedToPersonalDataCollection(false);
}
userDao.persist(user);
return user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class UserUpdate implements HiveEntity {
@ApiModelProperty(hidden = true)
private Boolean allDeviceTypesAvailable;

private Boolean agreedToPersonalDataCollection;

public Optional<String> getLogin() {
return Optional.ofNullable(login);
}
Expand Down Expand Up @@ -116,6 +118,14 @@ public void setAllDeviceTypesAvailable(Boolean allDeviceTypesAvailable) {
this.allDeviceTypesAvailable = allDeviceTypesAvailable;
}

public Optional<Boolean> getAgreedToPersonalDataCollection() {
return Optional.ofNullable(agreedToPersonalDataCollection);
}

public void setAgreedToPersonalDataCollection(Boolean agreedToPersonalDataCollection) {
this.agreedToPersonalDataCollection = agreedToPersonalDataCollection;
}

@ApiModelProperty(hidden = true)
public UserRole getRoleEnum() {
return getRole().map(UserRole::getValueForIndex).orElse(null);
Expand All @@ -140,6 +150,9 @@ public UserVO convertTo() {
if (allDeviceTypesAvailable != null) {
result.setAllDeviceTypesAvailable(allDeviceTypesAvailable);
}
if (agreedToPersonalDataCollection != null) {
result.setAgreedToPersonalDataCollection(agreedToPersonalDataCollection);
}
result.setStatus(getStatusEnum());
result.setRole(getRoleEnum());
return result;
Expand Down
12 changes: 12 additions & 0 deletions devicehive-common/src/main/java/com/devicehive/vo/UserVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public class UserVO implements HiveEntity {
@JsonPolicyDef({USER_PUBLISHED, USERS_LISTED, USER_SUBMITTED})
private Boolean allDeviceTypesAvailable;

@SerializedName("agreedToPersonalDataCollection")
@JsonPolicyDef({USER_PUBLISHED, USERS_LISTED, USER_SUBMITTED})
private Boolean agreedToPersonalDataCollection;

/**
* @return true, if user is admin
*/
Expand Down Expand Up @@ -180,6 +184,14 @@ public void setAllDeviceTypesAvailable(Boolean allDeviceTypesAvailable) {
this.allDeviceTypesAvailable = allDeviceTypesAvailable;
}

public Boolean getAgreedToPersonalDataCollection() {
return agreedToPersonalDataCollection;
}

public void setAgreedToPersonalDataCollection(Boolean agreedToPersonalDataCollection) {
this.agreedToPersonalDataCollection = agreedToPersonalDataCollection;
}

@Override
public boolean equals(Object o) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static UserWithDeviceTypeVO fromUserVO(UserVO dc) {
vo.setStatus(dc.getStatus());
vo.setIntroReviewed(dc.getIntroReviewed());
vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable());
vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection());
}

return vo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static UserWithNetworkVO fromUserVO(UserVO dc) {
vo.setStatus(dc.getStatus());
vo.setIntroReviewed(dc.getIntroReviewed());
vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable());
vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection());
}

return vo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ public UserVO updateUser(@NotNull Long id, UserUpdate userToUpdate, UserVO curUs
existing.setIntroReviewed(userToUpdate.getIntroReviewed().get());
}

if (userToUpdate.getAgreedToPersonalDataCollection().isPresent()) {
existing.setAgreedToPersonalDataCollection(userToUpdate.getAgreedToPersonalDataCollection().get());
}

hiveValidator.validate(existing);
return userDao.merge(existing);
}
Expand Down
16 changes: 16 additions & 0 deletions devicehive-rdbms-dao/src/main/java/com/devicehive/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public class User implements HiveEntity {
@JsonPolicyDef({USER_PUBLISHED, USERS_LISTED, USER_SUBMITTED})
private Boolean allDeviceTypesAvailable;

@Column(name = "agreed_to_personal_data_collection")
@SerializedName("agreedToPersonalDataCollection")
@JsonPolicyDef({USER_PUBLISHED, USERS_LISTED, USER_SUBMITTED})
private Boolean agreedToPersonalDataCollection;

/**
* @return true, if user is admin
*/
Expand Down Expand Up @@ -238,6 +243,14 @@ public void setAllDeviceTypesAvailable(Boolean allDeviceTypesAvailable) {
this.allDeviceTypesAvailable = allDeviceTypesAvailable;
}

public Boolean getAgreedToPersonalDataCollection() {
return agreedToPersonalDataCollection;
}

public void setAgreedToPersonalDataCollection(Boolean agreedToPersonalDataCollection) {
this.agreedToPersonalDataCollection = agreedToPersonalDataCollection;
}

@Override
public boolean equals(Object o) {

Expand Down Expand Up @@ -276,6 +289,7 @@ public static UserVO convertToVo(User dc) {
vo.setStatus(dc.getStatus());
vo.setIntroReviewed(dc.getIntroReviewed());
vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable());
vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection());
}
return vo;
}
Expand All @@ -296,6 +310,7 @@ public static User convertToEntity(UserVO dc) {
vo.setStatus(dc.getStatus());
vo.setIntroReviewed(dc.getIntroReviewed());
vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable());
vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection());
}
return vo;
}
Expand All @@ -315,6 +330,7 @@ public static User convertToEntity(UserWithDeviceTypeVO dc) {
vo.setStatus(dc.getStatus());
vo.setIntroReviewed(dc.getIntroReviewed());
vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable());
vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection());

vo.setDeviceTypes(new HashSet<>());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
-- #%L
-- DeviceHive Dao RDBMS Implementation
-- %%
-- Copyright (C) 2016 DataArt
-- %%
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- #L%
---

-- Add agreedToPersonalDataCollection column to users
ALTER TABLE dh_user ADD COLUMN agreed_to_personal_data_collection BOOLEAN DEFAULT FALSE;

-- Set agreedToPersonalDataCollection to false if it is null
UPDATE dh_user SET agreed_to_personal_data_collection = FALSE WHERE agreed_to_personal_data_collection IS NULL;