Skip to content

Commit 8dbd7e9

Browse files
authored
Merge pull request #1647 from zfi/PR-1500
Address corner use case on issue #1500
2 parents 1590774 + 4cd0ebc commit 8dbd7e9

File tree

9 files changed

+153
-21
lines changed

9 files changed

+153
-21
lines changed

src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectSharingDao.java

+51-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package com.parallax.server.blocklyprop.db.dao;
77

8+
import com.parallax.server.blocklyprop.db.generated.tables.ProjectSharing;
89
import com.parallax.server.blocklyprop.db.generated.tables.records.ProjectSharingRecord;
910
import java.util.List;
1011

@@ -14,17 +15,64 @@
1415
*/
1516
public interface ProjectSharingDao {
1617

18+
/**
19+
* Retrieve a project
20+
* @param idProject
21+
* @param accessKey
22+
* @return
23+
*/
1724
ProjectSharingRecord getProject(Long idProject, String accessKey);
1825

26+
27+
/**
28+
* Share an existing project
29+
* @param idProject
30+
* @param shareKey
31+
* @return
32+
*/
1933
ProjectSharingRecord shareProject(Long idProject, String shareKey);
2034

35+
36+
/**
37+
* Disable the shared link to a project
38+
* @param idProject
39+
* @return
40+
*/
2141
int revokeSharing(Long idProject);
2242

23-
public List<ProjectSharingRecord> getSharingInfo(Long idProject);
43+
44+
/**
45+
* Get a project sharing record
46+
* @param idProject
47+
* @return
48+
*/
49+
List<ProjectSharingRecord> getSharingInfo(Long idProject);
2450

2551
// Set the active flag in an existing shared project record
26-
public ProjectSharingRecord activateProject(Long idProject);
52+
53+
/**
54+
* Enable the project sharing link
55+
*
56+
* @param idProject
57+
* @return
58+
*/
59+
ProjectSharingRecord activateProject(Long idProject);
2760

2861
// Remove a project sharing link record
29-
public boolean deleteProjectSharingRecord(Long idProject);
62+
63+
/**
64+
* Delete a project sharing record
65+
*
66+
* @param idProject
67+
* @return
68+
*/
69+
boolean deleteProjectSharingRecord(Long idProject);
70+
71+
72+
/**
73+
* Is the project sharing feature enabled for a project
74+
* @param idProject
75+
* @return
76+
*/
77+
boolean isProjectSharingActive(Long idProject);
3078
}

src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
import com.parallax.server.blocklyprop.db.generated.tables.records.ProjectRecord;
1414
import com.parallax.server.blocklyprop.security.BlocklyPropSecurityUtils;
1515

16+
//import com.parallax.server.blocklyprop.services.impl.ProjectSharingServiceImpl;
17+
import com.parallax.server.blocklyprop.services.ProjectSharingService;
18+
1619
import com.google.inject.Inject;
1720
import com.google.inject.Singleton;
1821
import java.util.GregorianCalendar;
1922
import java.util.List;
23+
2024
import org.apache.shiro.authz.UnauthorizedException;
2125
import org.jooq.Condition;
2226
import org.jooq.DSLContext;
@@ -72,7 +76,15 @@ public void setDSLContext(DSLContext dsl) {
7276
this.create = dsl;
7377
}
7478

75-
79+
80+
private ProjectSharingService projectSharingService;
81+
82+
@Inject
83+
public void setProjectSharingContext(ProjectSharingService projectSharingService) {
84+
this.projectSharingService = projectSharingService;
85+
}
86+
87+
7688
/**
7789
*
7890
* Retrieve a new project record based from an existing project.
@@ -674,7 +686,12 @@ public ProjectRecord saveProjectCodeAs(Long idProject, String code, String newNa
674686
// by the current user OR if the source project is designated as a
675687
// shared or community project
676688
// --------------------------------------------------------------------
677-
if (original.getIdUser().equals(idUser) || original.getShared()) {
689+
boolean sharedStatus = projectSharingService.isProjectShared(idProject);
690+
LOG.info("Project shared status: {}", sharedStatus);
691+
692+
if (original.getIdUser().equals(idUser) || // Project is owned by currently logged in user
693+
sharedStatus || // Project is shared
694+
(!original.getPrivate())) { // Project is public
678695

679696
ProjectRecord cloned = createProject(
680697
newName,
@@ -688,7 +705,7 @@ public ProjectRecord saveProjectCodeAs(Long idProject, String code, String newNa
688705
original.getId());
689706

690707
if (cloned == null) {
691-
LOG.warn("Unable to create a copy og the project.");
708+
LOG.warn("Unable to create a copy of the project.");
692709
}
693710
return cloned;
694711
} else {

src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectSharingDaoImpl.java

+32-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
import com.google.inject.Inject;
99
import com.google.inject.Singleton;
10+
1011
import com.parallax.server.blocklyprop.db.dao.ProjectSharingDao;
1112
import com.parallax.server.blocklyprop.db.generated.Tables;
1213
import com.parallax.server.blocklyprop.db.generated.tables.records.ProjectSharingRecord;
14+
1315
import java.util.HashSet;
1416
import java.util.List;
1517
import java.util.Set;
@@ -61,7 +63,8 @@ public ProjectSharingRecord getProject(Long idProject, String accessKey) {
6163

6264

6365
/**
64-
*
66+
* Create a project sharing record
67+
*
6568
* @param idProject
6669
* @param shareKey
6770
* @return
@@ -178,4 +181,32 @@ public boolean deleteProjectSharingRecord(Long idProject) {
178181

179182
}
180183

184+
185+
/**
186+
* Determine the on/off state of the project's shared link URL
187+
*
188+
* @param idProject
189+
* @return
190+
*/
191+
@Override
192+
public boolean isProjectSharingActive(Long idProject) {
193+
194+
LOG.info("Retrieving sharing record for project {}", idProject);
195+
196+
ProjectSharingRecord project = create
197+
.selectFrom(Tables.PROJECT_SHARING)
198+
.where((Tables.PROJECT_SHARING.ID_PROJECT
199+
.equal(idProject)))
200+
.fetchOne();
201+
202+
if (project == null) {
203+
LOG.info("The sharing record for project {} was not found", idProject);
204+
// Record not found
205+
return false;
206+
}
207+
208+
LOG.info("Project {} sharing is {}", idProject, project.getActive());
209+
return project.getActive();
210+
}
211+
181212
}

src/main/java/com/parallax/server/blocklyprop/rest/RestProject.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public Response get(
145145
String endPoint = "REST:/rest/project/list/";
146146

147147
LOG.info("{} Get request received", endPoint);
148-
RestProjectUtils restProjectUtils = new RestProjectUtils();
148+
// RestProjectUtils restProjectUtils = new RestProjectUtils();
149149

150150
try {
151151
// Get the logged in user id for the current session
@@ -162,13 +162,13 @@ public Response get(
162162
//Sanity checks - is the request reasonable
163163

164164
// Sort flag evaluation
165-
if (!restProjectUtils.ValidateSortType(sort)) {
165+
if (!RestProjectUtils.ValidateSortType(sort)) {
166166
LOG.warn("{} Sort parameter failed. Defaulting to sort by project name", endPoint);
167167
sort = TableSort.name;
168168
}
169169

170170
// Sort order evaluation
171-
if (!restProjectUtils.ValidateSortOrder(order)) {
171+
if (!RestProjectUtils.ValidateSortOrder(order)) {
172172
LOG.warn("{} Sort order parameter failed. Defaulting to ascending order", endPoint);
173173
order = TableOrder.asc;
174174
}
@@ -343,12 +343,14 @@ public Response saveProjectCodeAs(
343343
result.addProperty("success", true);
344344

345345
return Response.ok(result.toString()).build();
346-
} catch (AuthorizationException ae) {
346+
}
347+
catch (AuthorizationException ae) {
347348
LOG.warn("Project code not saved. Not Authorized");
348349
return Response.status(Response.Status.UNAUTHORIZED).build();
349350
}
350351
catch (Exception ex) {
351352
LOG.error("General exception encountered. Message is: ", ex.getMessage());
353+
LOG.error("Error: {}", ex.getStackTrace().toString());
352354
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
353355
}
354356
}

src/main/java/com/parallax/server/blocklyprop/rest/RestSharedProject.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
import com.google.gson.JsonArray;
2929
import com.google.gson.JsonObject;
3030
import com.google.inject.Inject;
31+
3132
import com.parallax.server.blocklyprop.TableOrder;
3233
import com.parallax.server.blocklyprop.TableSort;
3334
import com.parallax.server.blocklyprop.utils.RestProjectUtils;
3435
import com.parallax.server.blocklyprop.converter.ProjectConverter;
3536
import com.parallax.server.blocklyprop.db.generated.tables.records.ProjectRecord;
3637
import com.parallax.server.blocklyprop.services.ProjectService;
38+
3739
import java.util.List;
3840
import javax.ws.rs.GET;
3941
import javax.ws.rs.HeaderParam;
@@ -141,19 +143,18 @@ public Response get(
141143
@QueryParam("limit") Integer limit,
142144
@QueryParam("offset") Integer offset) {
143145

144-
RestProjectUtils restProjectUtils = new RestProjectUtils();
145146

146147
String endPoint = "REST:/shared/project/list/";
147148
LOG.info("{} endpoint activated", endPoint);
148149

149150
// Sort flag evaluation
150-
if (!restProjectUtils.ValidateSortType(sort)) {
151+
if (!RestProjectUtils.ValidateSortType(sort)) {
151152
LOG.warn("{} Sort parameter failed. Defaulting to sort by project name", endPoint);
152153
sort = TableSort.name;
153154
}
154155

155156
// Sort order evaluation
156-
if (!restProjectUtils.ValidateSortOrder(order)) {
157+
if (!RestProjectUtils.ValidateSortOrder(order)) {
157158
LOG.warn("{} Sort order parameter failed. Defaulting to ascending order", endPoint);
158159
order = TableOrder.asc;
159160
}

src/main/java/com/parallax/server/blocklyprop/services/ProjectSharingService.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public interface ProjectSharingService {
2828
ProjectRecord getSharedProject(Long idProject, String shareKey);
2929

3030
// Delete a project sharing record
31-
public boolean deleteSharedProject(Long idProject);
31+
boolean deleteSharedProject(Long idProject);
32+
33+
// Get current active state of a project share link
34+
boolean isProjectShared(Long idProject);
3235

3336
}

src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectSharingServiceImpl.java

+33-3
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,34 @@ public class ProjectSharingServiceImpl implements ProjectSharingService {
3232
*/
3333
private static final Logger LOG = LoggerFactory.getLogger(ProjectSharingService.class);
3434

35+
36+
/**
37+
*
38+
*/
3539
private ProjectDao projectDao;
36-
private ProjectSharingDao projectSharingDao;
3740

38-
// Inject dao connection to the project table
41+
42+
/**
43+
* Inject dao connection to the project table
44+
* @param projectDao
45+
*/
3946
@Inject
4047
public void setProjectDao(ProjectDao projectDao) {
4148
this.projectDao = projectDao;
4249
}
4350

44-
// Inject connection to the project_sharing table
51+
52+
/**
53+
*
54+
*/
55+
private ProjectSharingDao projectSharingDao;
56+
57+
58+
/**
59+
* Inject connection to the project_sharing table
60+
*
61+
* @param projectSharingDao
62+
*/
4563
@Inject
4664
public void setProjectSharingDao(ProjectSharingDao projectSharingDao) {
4765
this.projectSharingDao = projectSharingDao;
@@ -154,4 +172,16 @@ public boolean deleteSharedProject(Long idProject) {
154172
LOG.info("Deleting project share link for project {}", idProject);
155173
return projectSharingDao.deleteProjectSharingRecord(idProject);
156174
}
175+
176+
177+
/**
178+
*
179+
* @param idProject
180+
* @return
181+
*/
182+
@Override
183+
public boolean isProjectShared(Long idProject) {
184+
LOG.info("Evaluating project {} sharing status.", idProject);
185+
return projectSharingDao.isProjectSharingActive(idProject);
186+
}
157187
}

src/main/java/com/parallax/server/blocklyprop/utils/RestProjectUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class RestProjectUtils {
3333
* @return
3434
* Return true if the provided sort is a valid item, otherwise return false
3535
*/
36-
public boolean ValidateSortType(TableSort sort) {
36+
public static boolean ValidateSortType(TableSort sort) {
3737

3838
if (sort != null) {
3939
for (TableSort t : TableSort.values()) {
@@ -46,7 +46,7 @@ public boolean ValidateSortType(TableSort sort) {
4646
return false;
4747
}
4848

49-
public boolean ValidateSortOrder(TableOrder order) {
49+
public static boolean ValidateSortOrder(TableOrder order) {
5050

5151
boolean parametersValid = false;
5252

src/main/resources/com/parallax/server/blocklyprop/internationalization/translations.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ footer.clientdownloadlink = BlocklyProp-client
2828
# Application version numbers.
2929
application.major = 1
3030
application.minor = 1
31-
application.build = 453
31+
application.build = 455
3232

3333
html.content_missing = Content missing
3434

0 commit comments

Comments
 (0)