Skip to content

Commit

Permalink
Merge pull request #921 from support-project/fix/issue879_survey_edit
Browse files Browse the repository at this point in the history
#879 Fix edit survey item
  • Loading branch information
koda-masaru authored Oct 21, 2017
2 parents 94dff29 + bd31174 commit 99325ba
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.support.project.knowledge.logic.activity.ActivityLogic;
import org.support.project.knowledge.vo.SurveyReport;
import org.support.project.web.bean.LabelValue;
import org.support.project.web.bean.Msg;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.config.MessageStatus;
Expand Down Expand Up @@ -146,7 +145,19 @@ public Boundary load() throws InvalidParamException {
Long id = super.getPathLong(new Long(-1));
SurveysEntity entity = SurveyLogic.get().loadSurvey(id, getLoginUserId());
if (entity == null) {
return send(new Msg("survey data is not exists."));
entity = new SurveysEntity();
entity.setDescription("");
entity.setItems(new ArrayList<>());
entity.setExist(false);
} else {
entity.setExist(true);
}
KnowledgesEntity knowledge = KnowledgeLogic.get().select(id, getLoginedUser());
List<LabelValue> editors = TargetLogic.get().selectEditorsOnKnowledgeId(id);
if (knowledge != null && KnowledgeLogic.get().isEditor(super.getLoginedUser(), knowledge, editors)) {
entity.setEditable(true);
} else {
entity.setEditable(false);
}
return send(entity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class SurveysEntity extends GenSurveysEntity {

private String knowledgeTitle;

private boolean exist = false;

/** SerialVersion */
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -90,4 +92,18 @@ public void setKnowledgeTitle(String knowledgeTitle) {
this.knowledgeTitle = knowledgeTitle;
}

/**
* @return the exist
*/
public boolean isExist() {
return exist;
}

/**
* @param exist the exist to set
*/
public void setExist(boolean exist) {
this.exist = exist;
}

}
2 changes: 1 addition & 1 deletion src/main/webapp/js/knowledge-view-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $(document).ready(function() {
url : _CONTEXT + '/protect.survey/load/' + knowledgeId
}).done(function(data) {
console.log(data);
if (data.msg) {
if (data.msg || !data.exist) {
return;
}
$('#btnAnswerSurvey').removeClass('hide');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import org.support.project.common.util.PropertyUtil;
import org.support.project.knowledge.dao.NotifyQueuesDao;
import org.support.project.knowledge.entity.NotifyQueuesEntity;
import org.support.project.knowledge.entity.SurveysEntity;
import org.support.project.knowledge.logic.KnowledgeLogic;
import org.support.project.knowledge.logic.TargetLogic;
import org.support.project.knowledge.logic.TemplateLogic;
import org.support.project.web.bean.LoginedUser;
import org.support.project.web.bean.MessageResult;
import org.support.project.web.bean.Msg;
import org.support.project.web.boundary.ForwardBoundary;
import org.support.project.web.boundary.JsonBoundary;
import org.support.project.web.common.HttpStatus;
Expand All @@ -34,6 +34,7 @@ public class IntegrationSurveyTest extends IntegrationCommon {

private static final String POST_USER = "integration-test-user-01";
private static final String ANSWER_USER = "integration-test-user-02";
private static final String OTHER_USER = "integration-test-user-03";

private static long knowledgeId;

Expand All @@ -48,6 +49,7 @@ public void testUserInsert() throws Exception {
LOG.info("ユーザ登録");
addUser(POST_USER);
addUser(ANSWER_USER);
addUser(OTHER_USER);
}

/**
Expand Down Expand Up @@ -114,14 +116,15 @@ public void testCreateSurvey() throws Exception {

request.setServletPath("protect.survey/load/" + knowledgeId);
request.setMethod("get");
DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class);
auth.setSession(POST_USER, request, response);
JsonBoundary msg = invoke(request, response, JsonBoundary.class);
Msg result = (Msg) msg.getObj();
Assert.assertEquals("survey data is not exists.", result.getMsg());
SurveysEntity result = (SurveysEntity) msg.getObj();
Assert.assertEquals("", result.getDescription());
Assert.assertEquals(true, result.isEditable());

request.setServletPath("protect.survey/save");
request.setMethod("post");
DefaultAuthenticationLogicImpl auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class);
auth.setSession(POST_USER, request, response);

String csrfToken = (String) request.getAttribute(HttpRequestCheckLogic.REQ_ID_KEY);
request.addParameter(HttpRequestCheckLogic.REQ_ID_KEY, csrfToken);
Expand Down Expand Up @@ -257,9 +260,24 @@ public void testEditAble() throws Exception {
response = new StubHttpServletResponse(request);
request.setServletPath("protect.survey/load/" + knowledgeId);
request.setMethod("get");
auth.setSession(POST_USER, request, response);
JsonBoundary msg = invoke(request, response, JsonBoundary.class);
Msg result = (Msg) msg.getObj();
Assert.assertEquals("survey data is not exists.", result.getMsg());
SurveysEntity result = (SurveysEntity) msg.getObj();
Assert.assertEquals("", result.getDescription());
Assert.assertEquals(true, result.isEditable());
Assert.assertEquals(false, result.isExist());

request = new StubHttpServletRequest();
response = new StubHttpServletResponse(request);
request.setServletPath("protect.survey/load/" + knowledgeId);
request.setMethod("get");
auth.setSession(OTHER_USER, request, response);
msg = invoke(request, response, JsonBoundary.class);
result = (SurveysEntity) msg.getObj();
Assert.assertEquals("", result.getDescription());
Assert.assertEquals(false, result.isEditable());
Assert.assertEquals(false, result.isExist());

request.setServletPath("protect.survey/save");
request.setMethod("post");
auth = org.support.project.di.Container.getComp(DefaultAuthenticationLogicImpl.class);
Expand All @@ -274,6 +292,17 @@ public void testEditAble() throws Exception {
MessageResult messageResult = (MessageResult) jsonBoundary.getObj();
LOG.info(messageResult);
Assert.assertEquals(HttpStatus.SC_200_OK, messageResult.getCode().intValue());

request = new StubHttpServletRequest();
response = new StubHttpServletResponse(request);
request.setServletPath("protect.survey/load/" + knowledgeId);
request.setMethod("get");
auth.setSession(OTHER_USER, request, response);
msg = invoke(request, response, JsonBoundary.class);
result = (SurveysEntity) msg.getObj();
Assert.assertEquals(null, result.getDescription());
Assert.assertEquals(false, result.isEditable());
Assert.assertEquals(true, result.isExist());
}


Expand Down

0 comments on commit 99325ba

Please sign in to comment.