Skip to content

Commit 0624f88

Browse files
Merge pull request #40 from aquality-automation/feature/42-sync-suite-feature-tests
Feature/42 sync suite feature tests
2 parents f130c0a + aab44c8 commit 0624f88

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public TestDto create(TestDto template) throws AqualityException {
4646
}
4747

4848
public List<TestDto> get(TestDto template, boolean withChildren) throws AqualityException {
49-
if(baseUser.isFromGlobalManagement() || baseUser.getProjectUser(template.getProject_id()).isViewer()){
49+
if(baseUser.isFromGlobalManagement() || baseUser.getProjectUserByTest(template).isViewer()){
5050
return fillTests(testDao.searchAll(template), withChildren);
5151
}else{
52-
throw new AqualityPermissionsException("Account is not allowed to view Milestones", baseUser);
52+
throw new AqualityPermissionsException("Account is not allowed to view Tests", baseUser);
5353
}
5454
}
5555

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

Lines changed: 25 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,19 @@ public ProjectUserDto getProjectUserBySuiteId(Integer suite_id) throws AqualityE
113109
return getProjectUser(template.getProject_id());
114110
}
115111

112+
public ProjectUserDto getProjectUserByTest(TestDto testDto) throws AqualityException {
113+
if(testDto.getProject_id() != null){
114+
return getProjectUser(testDto.getProject_id());
115+
}
116+
117+
try {
118+
TestDao testDao = new TestDao();
119+
return getProjectUser(testDao.searchAll(testDto).get(0).getProject_id());
120+
}catch (IndexOutOfBoundsException e){
121+
throw new AqualityException("Cannot define project id");
122+
}
123+
}
124+
116125
public ProjectUserDto getProjectUserByMilestoneId(Integer milestone_id) throws AqualityException {
117126
MilestoneDao milestoneDao = new MilestoneDao();
118127
MilestoneDto template = new MilestoneDto();
@@ -126,4 +135,13 @@ public UserDto toPublic(){
126135
this.setSession_code("");
127136
return this;
128137
}
138+
139+
private ProjectUserDto getEmptyProjectUser(){
140+
ProjectUserDto emptyPU = new ProjectUserDto();
141+
emptyPU.setViewer(0);
142+
emptyPU.setAdmin(0);
143+
emptyPU.setManager(0);
144+
emptyPU.setEngineer(0);
145+
return emptyPU;
146+
}
129147
}

0 commit comments

Comments
 (0)