Skip to content

Commit

Permalink
#952 Enable stealth access to articles
Browse files Browse the repository at this point in the history
  • Loading branch information
koda-masaru committed Nov 13, 2017
1 parent 83ba1db commit 643e1a7
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class UserConfig {
public static final String THEMA = "THEMA";
public static final String HIGHLIGHT = "HIGHLIGHT";

public static final String STEALTH_ACCESS = "STEALTH_ACCESS";

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import java.util.Map;

import org.support.project.common.bean.ValidateError;
import org.support.project.common.config.INT_FLAG;
import org.support.project.common.util.PropertyUtil;
import org.support.project.common.util.StringUtils;
import org.support.project.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.SystemConfig;
import org.support.project.knowledge.config.UserConfig;
import org.support.project.knowledge.control.Control;
import org.support.project.knowledge.logic.MailLogic;
import org.support.project.knowledge.logic.UserLogicEx;
Expand All @@ -25,10 +27,12 @@
import org.support.project.web.dao.ProvisionalRegistrationsDao;
import org.support.project.web.dao.RolesDao;
import org.support.project.web.dao.SystemConfigsDao;
import org.support.project.web.dao.UserConfigsDao;
import org.support.project.web.dao.UsersDao;
import org.support.project.web.entity.ProvisionalRegistrationsEntity;
import org.support.project.web.entity.RolesEntity;
import org.support.project.web.entity.SystemConfigsEntity;
import org.support.project.web.entity.UserConfigsEntity;
import org.support.project.web.entity.UsersEntity;
import org.support.project.web.exception.InvalidParamException;

Expand Down Expand Up @@ -169,10 +173,22 @@ public Boundary view_edit() throws InvalidParamException {

// 登録されているロールをセット
setSystemRoles(user);

// 保存されているユーザの設定情報をセット
setUserConfigs(user);

return forward("view_edit.jsp");
}

private void setUserConfigs(UsersEntity user) {
UserConfigsEntity stealth = UserConfigsDao.get().selectOnKey(UserConfig.STEALTH_ACCESS, AppConfig.get().getSystemName(), user.getUserId());
if (stealth != null) {
setAttribute(UserConfig.STEALTH_ACCESS, stealth.getConfigValue());
} else {
setAttribute(UserConfig.STEALTH_ACCESS, String.valueOf(INT_FLAG.OFF.getValue()));
}
}

/**
* ユーザを追加
*
Expand Down Expand Up @@ -213,6 +229,18 @@ public Boundary create() {
user = UserLogicEx.get().insert(user, roles);
setAttributeOnProperty(user);

String stealth = getParam("STEALTH_ACCESS");
if ("1".equals(stealth)) {
UserConfigsEntity config = new UserConfigsEntity(UserConfig.STEALTH_ACCESS, AppConfig.get().getSystemName(), user.getUserId());
config.setConfigValue("1");
UserConfigsDao.get().save(config);
} else {
UserConfigsEntity config = UserConfigsDao.get().selectOnKey(UserConfig.STEALTH_ACCESS, AppConfig.get().getSystemName(), user.getUserId());
if (stealth != null) {
UserConfigsDao.get().physicalDelete(config);
}
}

// 登録されているロールをセット
setSystemRoles(user);

Expand Down Expand Up @@ -280,6 +308,18 @@ public Boundary save() {
user = UserLogicEx.get().update(user, roles, getLoginedUser());
setAttributeOnProperty(user);

String stealth = getParam("STEALTH_ACCESS");
if ("1".equals(stealth)) {
UserConfigsEntity config = new UserConfigsEntity(UserConfig.STEALTH_ACCESS, AppConfig.get().getSystemName(), user.getUserId());
config.setConfigValue("1");
UserConfigsDao.get().save(config);
} else {
UserConfigsEntity config = UserConfigsDao.get().selectOnKey(UserConfig.STEALTH_ACCESS, AppConfig.get().getSystemName(), user.getUserId());
if (stealth != null) {
UserConfigsDao.get().physicalDelete(config);
}
}

// 登録されているロールをセット
setSystemRoles(user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.support.project.di.Instance;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.SystemConfig;
import org.support.project.knowledge.config.UserConfig;
import org.support.project.knowledge.control.KnowledgeControlBase;
import org.support.project.knowledge.dao.CommentsDao;
import org.support.project.knowledge.dao.DraftItemValuesDao;
Expand Down Expand Up @@ -77,7 +78,6 @@
import org.support.project.web.entity.UserConfigsEntity;
import org.support.project.web.entity.UsersEntity;
import org.support.project.web.exception.InvalidParamException;
import org.support.project.web.logic.UserLogic;

/**
* ナレッジ操作のコントロール
Expand Down Expand Up @@ -225,7 +225,10 @@ public Boundary view() throws InvalidParamException, ParseException {
List<StocksEntity> stocks = StocksDao.get().selectStockOnKnowledge(entity, loginedUser);
setAttribute("stocks", stocks);

ActivityLogic.get().processActivity(Activity.KNOWLEDGE_SHOW, getLoginedUser(), DateUtils.now(), entity);
UserConfigsEntity stealth = UserConfigsDao.get().selectOnKey(UserConfig.STEALTH_ACCESS, AppConfig.get().getSystemName(), getLoginUserId());
if (stealth == null || !"1".equals(stealth.getConfigValue())) {
ActivityLogic.get().processActivity(Activity.KNOWLEDGE_SHOW, getLoginedUser(), DateUtils.now(), entity);
}
long point = KnowledgesDao.get().selectPoint(entity.getKnowledgeId());
setAttribute("point", point);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.support.project.aop.Aspect;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/appresource.properties
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ knowledge.user.add.title=Add User
knowledge.user.edit.title=Edit User
knowledge.user.invalid.same.password=Password and Confirm Password has a different
knowledge.user.mail.exist=The Email Address already registered
knowledge.user.stealth.access=Stealth Access to article

knowledge.group.view.title=View Group
knowledge.group.view.label.groupname=Group name
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/appresource_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ knowledge.user.add.title=ユーザの追加
knowledge.user.edit.title=ユーザの更新
knowledge.user.invalid.same.password=PasswordとConfirm Passwordが違っています
knowledge.user.mail.exist=既に登録されているEmail Addressです
knowledge.user.stealth.access=記事へアクセスした履歴を通知しない

knowledge.group.view.title=グループ表示
knowledge.group.view.label.groupname=グループ名
Expand Down
98 changes: 53 additions & 45 deletions src/main/webapp/WEB-INF/views/admin/users/view_add.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,62 @@

<form action="<%= request.getContextPath()%>/admin.users/create" method="post" role="form">
<div class="alert alert-info alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Information</strong><br/>
- <%= jspUtil.label("knowledge.account.id.info1") %><br/>
- <%= jspUtil.label("knowledge.account.id.info2") %>
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Information</strong><br/>
- <%= jspUtil.label("knowledge.account.id.info1") %><br/>
- <%= jspUtil.label("knowledge.account.id.info2") %>
</div>


<div class="form-group">
<label for="userKey"><%= jspUtil.label("knowledge.signup.label.mail") %></label>
<input type="text" class="form-control" name="userKey" id="userKey" placeholder="Mail Address" value="<%= jspUtil.out("userKey") %>" />
</div>
<div class="form-group">
<label for="userName"><%= jspUtil.label("knowledge.signup.label.name") %></label>
<input type="text" class="form-control" name="userName" id="userName" placeholder="User Name" value="<%= jspUtil.out("userName") %>" />
</div>

<div class="form-group">
<label for="password"><%= jspUtil.label("knowledge.signup.label.password") %></label>
<input type="password" class="form-control" name="password" id="password" placeholder="Password" value="<%= jspUtil.out("password") %>" />
</div>
<div class="form-group">
<label for="confirm_password"><%= jspUtil.label("knowledge.signup.label.confirm.password") %></label>
<input type="password" class="form-control" name="confirm_password" id="confirm_password"
placeholder="Confirm Password" value="<%= jspUtil.out("confirm_password") %>" />
</div>

<div class="form-group">
<label for="role_${role.roleId}"><%= jspUtil.label("label.role") %></label><br/>
<c:forEach var="role" items="${systemRoles}" varStatus="status">
<label class="radio-inline">
<input type="checkbox" value="<%= jspUtil.out("role.roleKey") %>" name="roles"
id="role_${role.roleId}" <%
if (jspUtil.getValue("role", Roles.class).isChecked()) {
out.write("checked=\"checked\"");
}
%>/>
<%= jspUtil.out("role.roleName") %>
</label>
</c:forEach>
</div>

<input type="hidden" name="offset" value="<%= jspUtil.out("offset") %>" />


<button type="submit" class="btn btn-primary"><i class="fa fa-save"></i>&nbsp;<%= jspUtil.label("label.registration") %></button>
<a href="<%= request.getContextPath() %>/admin.users/list/<%= jspUtil.out("offset") %>"
class="btn btn-success" role="button"><i class="fa fa-list-ul"></i>&nbsp;<%= jspUtil.label("label.backlist") %></a>

<div class="form-group">
<label for="userKey"><%= jspUtil.label("knowledge.signup.label.mail") %></label>
<input type="text" class="form-control" name="userKey" id="userKey" placeholder="Mail Address" value="<%= jspUtil.out("userKey") %>" />
</div>
<div class="form-group">
<label for="userName"><%= jspUtil.label("knowledge.signup.label.name") %></label>
<input type="text" class="form-control" name="userName" id="userName" placeholder="User Name" value="<%= jspUtil.out("userName") %>" />
</div>

<div class="form-group">
<label for="password"><%= jspUtil.label("knowledge.signup.label.password") %></label>
<input type="password" class="form-control" name="password" id="password" placeholder="Password" value="<%= jspUtil.out("password") %>" />
</div>
<div class="form-group">
<label for="confirm_password"><%= jspUtil.label("knowledge.signup.label.confirm.password") %></label>
<input type="password" class="form-control" name="confirm_password" id="confirm_password"
placeholder="Confirm Password" value="<%= jspUtil.out("confirm_password") %>" />
</div>

<div class="form-group">
<label for="role_${role.roleId}"><%= jspUtil.label("label.role") %></label><br/>
<c:forEach var="role" items="${systemRoles}" varStatus="status">
<label class="radio-inline">
<input type="checkbox" value="<%= jspUtil.out("role.roleKey") %>" name="roles"
id="role_${role.roleId}" <%
if (jspUtil.getValue("role", Roles.class).isChecked()) {
out.write("checked=\"checked\"");
}
%>/>
<%= jspUtil.out("role.roleName") %>
</label>
</c:forEach>
</div>

<div class="form-group">
<label><%= jspUtil.label("knowledge.user.stealth.access") %></label><br/>
<label class="radio-inline">
<input type="checkbox" value="1" name="STEALTH_ACCESS" <%= jspUtil.checked("1", "STEALTH_ACCESS", false) %> />
ON
</label>
</div>


<input type="hidden" name="offset" value="<%= jspUtil.out("offset") %>" />

<button type="submit" class="btn btn-primary"><i class="fa fa-save"></i>&nbsp;<%= jspUtil.label("label.registration") %></button>
<a href="<%= request.getContextPath() %>/admin.users/list/<%= jspUtil.out("offset") %>"
class="btn btn-success" role="button"><i class="fa fa-list-ul"></i>&nbsp;<%= jspUtil.label("label.backlist") %></a>

</form>


Expand Down
8 changes: 8 additions & 0 deletions src/main/webapp/WEB-INF/views/admin/users/view_edit.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ function deleteUser() {
</c:forEach>
</div>

<div class="form-group">
<label><%= jspUtil.label("knowledge.user.stealth.access") %></label><br/>
<label class="radio-inline">
<input type="checkbox" value="1" name="STEALTH_ACCESS" <%= jspUtil.checked("1", "STEALTH_ACCESS", false) %> />
ON
</label>
</div>

<div class="form-group">
<label for="input_no"><%= jspUtil.label("label.regist.datetime") %> / <%= jspUtil.label("label.update.datetime") %></label>
<p class="form-control-static">
Expand Down

0 comments on commit 643e1a7

Please sign in to comment.