Skip to content

Commit a03691c

Browse files
committed
added possibility to get ProjectUser by test Id
1 parent 8fd710a commit a03691c

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/main/java/main/controllers/Project/TestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public List<TestDto> get(TestDto template) throws AqualityException {
6060

6161
@Override
6262
public boolean delete(TestDto template) throws AqualityException {
63-
if(baseUser.isManager() || baseUser.getProjectUser(template.getProject_id()).isEditor()){
63+
if(baseUser.isManager() || baseUser.getProjectUserByTestId(template.getProject_id()).isEditor()){
6464
return testDao.delete(template);
6565
}else{
6666
throw new AqualityPermissionsException("Account is not allowed to delete Test", baseUser);

src/main/java/main/model/dto/UserDto.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import main.annotations.DataBaseSearchable;
88
import main.exceptions.AqualityException;
99
import main.model.db.dao.project.MilestoneDao;
10+
import main.model.db.dao.project.TestDao;
1011
import main.model.db.dao.project.TestSuiteDao;
1112
import main.utils.BooleanUtil;
1213

@@ -94,15 +95,10 @@ public boolean isFromGlobalManagement(){
9495
}
9596

9697
public ProjectUserDto getProjectUser(Integer projectId){
97-
ProjectUserDto emptyPU = new ProjectUserDto();
98-
emptyPU.setViewer(0);
99-
emptyPU.setAdmin(0);
100-
emptyPU.setManager(0);
101-
emptyPU.setEngineer(0);
10298
if(projectUsers != null){
103-
return projectUsers.stream().filter(x -> x.getProject_id().equals(projectId)).findFirst().orElse(emptyPU);
99+
return projectUsers.stream().filter(x -> x.getProject_id().equals(projectId)).findFirst().orElse(getEmptyProjectUser());
104100
}
105-
return emptyPU;
101+
return getEmptyProjectUser();
106102
}
107103

108104
public ProjectUserDto getProjectUserBySuiteId(Integer suite_id) throws AqualityException {
@@ -113,6 +109,14 @@ public ProjectUserDto getProjectUserBySuiteId(Integer suite_id) throws AqualityE
113109
return getProjectUser(template.getProject_id());
114110
}
115111

112+
public ProjectUserDto getProjectUserByTestId(Integer test_id) throws AqualityException {
113+
TestDao testDao = new TestDao();
114+
TestDto template = new TestDto();
115+
template.setId(test_id);
116+
template = testDao.searchAll(template).get(0);
117+
return getProjectUser(template.getProject_id());
118+
}
119+
116120
public ProjectUserDto getProjectUserByMilestoneId(Integer milestone_id) throws AqualityException {
117121
MilestoneDao milestoneDao = new MilestoneDao();
118122
MilestoneDto template = new MilestoneDto();
@@ -126,4 +130,13 @@ public UserDto toPublic(){
126130
this.setSession_code("");
127131
return this;
128132
}
133+
134+
private ProjectUserDto getEmptyProjectUser(){
135+
ProjectUserDto emptyPU = new ProjectUserDto();
136+
emptyPU.setViewer(0);
137+
emptyPU.setAdmin(0);
138+
emptyPU.setManager(0);
139+
emptyPU.setEngineer(0);
140+
return emptyPU;
141+
}
129142
}

0 commit comments

Comments
 (0)