Skip to content

Commit

Permalink
Merge pull request #1647 from zfi/PR-1500
Browse files Browse the repository at this point in the history
Address corner use case on issue #1500
  • Loading branch information
zfi authored Feb 7, 2019
2 parents 1590774 + 4cd0ebc commit 8dbd7e9
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package com.parallax.server.blocklyprop.db.dao;

import com.parallax.server.blocklyprop.db.generated.tables.ProjectSharing;
import com.parallax.server.blocklyprop.db.generated.tables.records.ProjectSharingRecord;
import java.util.List;

Expand All @@ -14,17 +15,64 @@
*/
public interface ProjectSharingDao {

/**
* Retrieve a project
* @param idProject
* @param accessKey
* @return
*/
ProjectSharingRecord getProject(Long idProject, String accessKey);


/**
* Share an existing project
* @param idProject
* @param shareKey
* @return
*/
ProjectSharingRecord shareProject(Long idProject, String shareKey);


/**
* Disable the shared link to a project
* @param idProject
* @return
*/
int revokeSharing(Long idProject);

public List<ProjectSharingRecord> getSharingInfo(Long idProject);

/**
* Get a project sharing record
* @param idProject
* @return
*/
List<ProjectSharingRecord> getSharingInfo(Long idProject);

// Set the active flag in an existing shared project record
public ProjectSharingRecord activateProject(Long idProject);

/**
* Enable the project sharing link
*
* @param idProject
* @return
*/
ProjectSharingRecord activateProject(Long idProject);

// Remove a project sharing link record
public boolean deleteProjectSharingRecord(Long idProject);

/**
* Delete a project sharing record
*
* @param idProject
* @return
*/
boolean deleteProjectSharingRecord(Long idProject);


/**
* Is the project sharing feature enabled for a project
* @param idProject
* @return
*/
boolean isProjectSharingActive(Long idProject);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
import com.parallax.server.blocklyprop.db.generated.tables.records.ProjectRecord;
import com.parallax.server.blocklyprop.security.BlocklyPropSecurityUtils;

//import com.parallax.server.blocklyprop.services.impl.ProjectSharingServiceImpl;
import com.parallax.server.blocklyprop.services.ProjectSharingService;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.GregorianCalendar;
import java.util.List;

import org.apache.shiro.authz.UnauthorizedException;
import org.jooq.Condition;
import org.jooq.DSLContext;
Expand Down Expand Up @@ -72,7 +76,15 @@ public void setDSLContext(DSLContext dsl) {
this.create = dsl;
}



private ProjectSharingService projectSharingService;

@Inject
public void setProjectSharingContext(ProjectSharingService projectSharingService) {
this.projectSharingService = projectSharingService;
}


/**
*
* Retrieve a new project record based from an existing project.
Expand Down Expand Up @@ -674,7 +686,12 @@ public ProjectRecord saveProjectCodeAs(Long idProject, String code, String newNa
// by the current user OR if the source project is designated as a
// shared or community project
// --------------------------------------------------------------------
if (original.getIdUser().equals(idUser) || original.getShared()) {
boolean sharedStatus = projectSharingService.isProjectShared(idProject);
LOG.info("Project shared status: {}", sharedStatus);

if (original.getIdUser().equals(idUser) || // Project is owned by currently logged in user
sharedStatus || // Project is shared
(!original.getPrivate())) { // Project is public

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

if (cloned == null) {
LOG.warn("Unable to create a copy og the project.");
LOG.warn("Unable to create a copy of the project.");
}
return cloned;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import com.google.inject.Inject;
import com.google.inject.Singleton;

import com.parallax.server.blocklyprop.db.dao.ProjectSharingDao;
import com.parallax.server.blocklyprop.db.generated.Tables;
import com.parallax.server.blocklyprop.db.generated.tables.records.ProjectSharingRecord;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -61,7 +63,8 @@ public ProjectSharingRecord getProject(Long idProject, String accessKey) {


/**
*
* Create a project sharing record
*
* @param idProject
* @param shareKey
* @return
Expand Down Expand Up @@ -178,4 +181,32 @@ public boolean deleteProjectSharingRecord(Long idProject) {

}


/**
* Determine the on/off state of the project's shared link URL
*
* @param idProject
* @return
*/
@Override
public boolean isProjectSharingActive(Long idProject) {

LOG.info("Retrieving sharing record for project {}", idProject);

ProjectSharingRecord project = create
.selectFrom(Tables.PROJECT_SHARING)
.where((Tables.PROJECT_SHARING.ID_PROJECT
.equal(idProject)))
.fetchOne();

if (project == null) {
LOG.info("The sharing record for project {} was not found", idProject);
// Record not found
return false;
}

LOG.info("Project {} sharing is {}", idProject, project.getActive());
return project.getActive();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Response get(
String endPoint = "REST:/rest/project/list/";

LOG.info("{} Get request received", endPoint);
RestProjectUtils restProjectUtils = new RestProjectUtils();
// RestProjectUtils restProjectUtils = new RestProjectUtils();

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

// Sort flag evaluation
if (!restProjectUtils.ValidateSortType(sort)) {
if (!RestProjectUtils.ValidateSortType(sort)) {
LOG.warn("{} Sort parameter failed. Defaulting to sort by project name", endPoint);
sort = TableSort.name;
}

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

return Response.ok(result.toString()).build();
} catch (AuthorizationException ae) {
}
catch (AuthorizationException ae) {
LOG.warn("Project code not saved. Not Authorized");
return Response.status(Response.Status.UNAUTHORIZED).build();
}
catch (Exception ex) {
LOG.error("General exception encountered. Message is: ", ex.getMessage());
LOG.error("Error: {}", ex.getStackTrace().toString());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.inject.Inject;

import com.parallax.server.blocklyprop.TableOrder;
import com.parallax.server.blocklyprop.TableSort;
import com.parallax.server.blocklyprop.utils.RestProjectUtils;
import com.parallax.server.blocklyprop.converter.ProjectConverter;
import com.parallax.server.blocklyprop.db.generated.tables.records.ProjectRecord;
import com.parallax.server.blocklyprop.services.ProjectService;

import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
Expand Down Expand Up @@ -141,19 +143,18 @@ public Response get(
@QueryParam("limit") Integer limit,
@QueryParam("offset") Integer offset) {

RestProjectUtils restProjectUtils = new RestProjectUtils();

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

// Sort flag evaluation
if (!restProjectUtils.ValidateSortType(sort)) {
if (!RestProjectUtils.ValidateSortType(sort)) {
LOG.warn("{} Sort parameter failed. Defaulting to sort by project name", endPoint);
sort = TableSort.name;
}

// Sort order evaluation
if (!restProjectUtils.ValidateSortOrder(order)) {
if (!RestProjectUtils.ValidateSortOrder(order)) {
LOG.warn("{} Sort order parameter failed. Defaulting to ascending order", endPoint);
order = TableOrder.asc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public interface ProjectSharingService {
ProjectRecord getSharedProject(Long idProject, String shareKey);

// Delete a project sharing record
public boolean deleteSharedProject(Long idProject);
boolean deleteSharedProject(Long idProject);

// Get current active state of a project share link
boolean isProjectShared(Long idProject);

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,34 @@ public class ProjectSharingServiceImpl implements ProjectSharingService {
*/
private static final Logger LOG = LoggerFactory.getLogger(ProjectSharingService.class);


/**
*
*/
private ProjectDao projectDao;
private ProjectSharingDao projectSharingDao;

// Inject dao connection to the project table

/**
* Inject dao connection to the project table
* @param projectDao
*/
@Inject
public void setProjectDao(ProjectDao projectDao) {
this.projectDao = projectDao;
}

// Inject connection to the project_sharing table

/**
*
*/
private ProjectSharingDao projectSharingDao;


/**
* Inject connection to the project_sharing table
*
* @param projectSharingDao
*/
@Inject
public void setProjectSharingDao(ProjectSharingDao projectSharingDao) {
this.projectSharingDao = projectSharingDao;
Expand Down Expand Up @@ -154,4 +172,16 @@ public boolean deleteSharedProject(Long idProject) {
LOG.info("Deleting project share link for project {}", idProject);
return projectSharingDao.deleteProjectSharingRecord(idProject);
}


/**
*
* @param idProject
* @return
*/
@Override
public boolean isProjectShared(Long idProject) {
LOG.info("Evaluating project {} sharing status.", idProject);
return projectSharingDao.isProjectSharingActive(idProject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RestProjectUtils {
* @return
* Return true if the provided sort is a valid item, otherwise return false
*/
public boolean ValidateSortType(TableSort sort) {
public static boolean ValidateSortType(TableSort sort) {

if (sort != null) {
for (TableSort t : TableSort.values()) {
Expand All @@ -46,7 +46,7 @@ public boolean ValidateSortType(TableSort sort) {
return false;
}

public boolean ValidateSortOrder(TableOrder order) {
public static boolean ValidateSortOrder(TableOrder order) {

boolean parametersValid = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ footer.clientdownloadlink = BlocklyProp-client
# Application version numbers.
application.major = 1
application.minor = 1
application.build = 453
application.build = 455

html.content_missing = Content missing

Expand Down

0 comments on commit 8dbd7e9

Please sign in to comment.