사용자별 게시판 권한 설정 작업중.

master
강석 최 2021-12-08 18:50:38 +09:00
parent e689cdc1c5
commit 7d6aecbc7c
12 changed files with 270 additions and 20 deletions

View File

@ -1,19 +1,21 @@
package com.dbnt.kcgfilemanager.controller; package com.dbnt.kcgfilemanager.controller;
import com.dbnt.kcgfilemanager.model.BoardCategory; import com.dbnt.kcgfilemanager.model.BoardCategory;
import com.dbnt.kcgfilemanager.model.CategoryRole;
import com.dbnt.kcgfilemanager.model.CommonCode; import com.dbnt.kcgfilemanager.model.CommonCode;
import com.dbnt.kcgfilemanager.model.UserInfo; import com.dbnt.kcgfilemanager.model.UserInfo;
import com.dbnt.kcgfilemanager.service.BoardCategoryService; import com.dbnt.kcgfilemanager.service.BoardCategoryService;
import com.dbnt.kcgfilemanager.service.CategoryRoleService;
import com.dbnt.kcgfilemanager.service.CommonCodeService; import com.dbnt.kcgfilemanager.service.CommonCodeService;
import com.dbnt.kcgfilemanager.service.UserInfoService; import com.dbnt.kcgfilemanager.service.UserInfoService;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import java.util.HashMap;
import javax.servlet.http.HttpServletResponse; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Optional;
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@ -23,6 +25,7 @@ public class adminController {
private final CommonCodeService commonCodeService; private final CommonCodeService commonCodeService;
private final BoardCategoryService boardCategoryService; private final BoardCategoryService boardCategoryService;
private final UserInfoService userInfoService; private final UserInfoService userInfoService;
private final CategoryRoleService categoryRoleService;
@GetMapping("/main") @GetMapping("/main")
public ModelAndView goAdmin() { public ModelAndView goAdmin() {
@ -83,6 +86,21 @@ public class adminController {
mav.addObject("userInfo", userInfoService.selectUserInfo(userInfo)); mav.addObject("userInfo", userInfoService.selectUserInfo(userInfo));
return mav; return mav;
} }
@PostMapping("/insertCategoryRole")
@ResponseBody
public Integer insertCategoryRole(@RequestBody HashMap<String, Object> map){
List<LinkedHashMap> mapList = (List<LinkedHashMap>)map.get("categoryRoleList");
Integer userSeq = (int)map.get("userSeq");
categoryRoleService.insertCategoryRole(userSeq, mapList);
return map.size();
}
@GetMapping("/selectCategoryRole")
public ModelAndView selectUserCategoryRole(CategoryRole categoryRole){
ModelAndView mav = new ModelAndView("admin/userCategoryRole");
/*mav.addObject("userCategoryRole", userInfoService.selectUserCategoryRole(categoryRole));*/
return mav;
}
@GetMapping("/modifyRequest") @GetMapping("/modifyRequest")
public ModelAndView modifyRequest() { public ModelAndView modifyRequest() {

View File

@ -0,0 +1,29 @@
package com.dbnt.kcgfilemanager.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.*;
@Getter
@Setter
@Entity
@NoArgsConstructor
@DynamicInsert
@DynamicUpdate
@Table(name = "CATEGORY_ROLE")
@IdClass(CategoryRoleId.class)
public class CategoryRole {
@Id
@Column(name = "USER_SEQ", nullable = false)
private Integer userSeq;
@Id
@Column(name = "CATEGORY_SEQ", nullable = false)
private Integer categorySeq;
@Column(name = "CATEGORY_ROLE")
private String categoryRole;
}

View File

@ -0,0 +1,19 @@
package com.dbnt.kcgfilemanager.model;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.IdClass;
import javax.persistence.Table;
import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CategoryRoleId implements Serializable {
private Integer userSeq;
private Integer categorySeq;
}

View File

@ -0,0 +1,13 @@
package com.dbnt.kcgfilemanager.repository;
import com.dbnt.kcgfilemanager.model.CategoryRole;
import com.dbnt.kcgfilemanager.model.CategoryRoleId;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface CategoryRoleRepository extends JpaRepository<CategoryRole, CategoryRoleId> {
List<CategoryRole> findByUserSeq(Integer userSeq);
void deleteByUserSeq(Integer userSeq);
}

View File

@ -0,0 +1,33 @@
package com.dbnt.kcgfilemanager.service;
import com.dbnt.kcgfilemanager.model.CategoryRole;
import com.dbnt.kcgfilemanager.repository.CategoryRoleRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@Service
@RequiredArgsConstructor
public class CategoryRoleService {
private final CategoryRoleRepository categoryRoleRepository;
@Transactional
public void insertCategoryRole(Integer userSeq, List<LinkedHashMap> mapList) {
// List<CategoryRole> categoryRoleList = categoryRoleRepository.findByUserSeq(userSeq);
// categoryRoleRepository.deleteAll(categoryRoleList);
categoryRoleRepository.deleteByUserSeq(userSeq);
List<CategoryRole> categoryRoleList = new ArrayList<>();
for(LinkedHashMap map: mapList){
CategoryRole categoryRole = new CategoryRole();
categoryRole.setUserSeq((int)map.get("userSeq"));
categoryRole.setCategorySeq((int)map.get("categorySeq"));
categoryRole.setCategoryRole((String)map.get("categoryRole"));
categoryRoleList.add(categoryRole);
}
categoryRoleRepository.saveAll(categoryRoleList);
}
}

View File

@ -1,3 +1,4 @@
/*로그인 폼*/
.form-signin{ .form-signin{
width: 100%; width: 100%;
max-width: 330px; max-width: 330px;
@ -10,6 +11,7 @@
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
} }
/*사이드바 카테고리 트리*/
.btn-toggle:hover, .btn-toggle:focus { .btn-toggle:hover, .btn-toggle:focus {
color: rgba(0, 0, 0, .85); color: rgba(0, 0, 0, .85);
background-color: #d2f4ea; background-color: #d2f4ea;

View File

@ -1,5 +1,11 @@
$(function(){ $(function(){
setSearchCondition(); setSearchCondition();
const categorySelectModal = document.getElementById('categorySelectModal');
categorySelectModal.addEventListener('shown.bs.modal', function () {
})
$("#dateSelectorDiv").datepicker({ $("#dateSelectorDiv").datepicker({
format: "yyyy-mm-dd", format: "yyyy-mm-dd",
language: "ko" language: "ko"
@ -87,6 +93,40 @@ $(document).on('click', '#updateBtn', function (){
} }
}) })
$(document).on('change', '.parentCategory', function (){
const categorySeq = $(this).attr("data-categoryseq")
childCategoryStatusChange(categorySeq, this.checked);
})
$(document).on('click', '#saveCategoryRoleBtn', function (){
const categoryRoleList = [];
const userSeq = Number($(".userInfoCheckBox:checked").val());
$(".categoryCheckBox:checked").each(function (idx, el){
categoryRoleList.push({
userSeq : userSeq,
categorySeq : Number($(el).attr("data-categoryseq")),
categoryRole: 'T'
});
})
$.ajax({
type : 'POST',
url : "/admin/insertCategoryRole",
data : JSON.stringify({categoryRoleList: categoryRoleList, userSeq: userSeq}),
contentType: 'application/json',
beforeSend: function (xhr){
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
},
success : function(data) {
getCategoryRole($(".userInfoCheckBox:checked").val());
alert("저장되었습니다.");
$("#categorySelectModal").find(".btn-close").click();
},
error : function(xhr, status) {
}
})
})
function valueCheck(form){ function valueCheck(form){
const targetForm = $("#"+form); const targetForm = $("#"+form);
const userId = targetForm.find("#userId").val(); const userId = targetForm.find("#userId").val();
@ -151,9 +191,6 @@ function setSearchCondition(){
dateSelectorDiv.children().attr("disabled", "disabled"); dateSelectorDiv.children().attr("disabled", "disabled");
} }
} }
function formReset(){
document.getElementById('userInfoInsert').reset();
}
function getUserSeq(){ function getUserSeq(){
return $(".userInfoCheckBox:checked").val(); return $(".userInfoCheckBox:checked").val();
@ -177,17 +214,27 @@ function getUserInfo(userSeq){
} }
function getCategoryRole(userSeq){ function getCategoryRole(userSeq){
if(userSeq !== undefined){ if(userSeq !== undefined){
/*$.ajax({ $.ajax({
url: '/admin/codeValue', url: '/admin/selectCategoryRole',
data: {category: category}, data: {userSeq: userSeq},
type: 'GET', type: 'GET',
dataType:"html", dataType:"html",
success: function(data){ success: function(html){
$("#valueDiv").empty().append(data) $("#userContent").empty().append(html)
}, },
error:function(){ error:function(){
} }
});*/ });
}
}
function childCategoryStatusChange(parentCategory, flag){
const target = $("[data-parentcategory='"+parentCategory+"']");
if(target.length>0){
target.prop("checked", flag);
target.each(function(idx, el){
childCategoryStatusChange($(el).attr("data-categoryseq"), flag);
})
} }
} }

View File

@ -4,7 +4,7 @@
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}"> layout:decorate="~{layout/layout}">
<div layout:fragment="content"> <div layout:fragment="content" class="pt-3">
<h1>This is Admin Page.</h1> <h4>관리자 메인 페이지</h4>
</div> </div>
</html> </html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="p-3">
<div class="row-cols-6">
권한 목록
</div>
<div class="row justify-content-end">
<div class="col-auto">
<button class="btn btn-success" id="roleAddBtn" data-bs-toggle="modal" data-bs-target="#categorySelectModal">편집</button>
</div>
</div>
</div>
</html>

View File

@ -9,6 +9,8 @@
</th:block> </th:block>
<div layout:fragment="content"> <div layout:fragment="content">
<main class="pt-3"> <main class="pt-3">
<input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<h4>사용자 관리</h4> <h4>사용자 관리</h4>
<div class="row mx-0"> <div class="row mx-0">
<div class="col-12 card text-center"> <div class="col-12 card text-center">
@ -220,5 +222,79 @@
</div> </div>
</div> </div>
</div> </div>
<div class="modal fade" id="categorySelectModal" tabindex="-1" aria-labelledby="categorySelectModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="categorySelectModalLabel">분류 선택</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row overflow-auto flex-nowrap" id="categorySelectModalBody">
<th:block th:each="depth1:${session.categoryList}">
<div class="col-auto">
<table class="table table-striped">
<thead>
<tr>
<th>
<input type="checkbox" class="categoryCheckBox parentCategory" th:data-categoryseq="${depth1.categorySeq}">
</th>
<th colspan="3" class="text-center" th:text="${depth1.categoryName}"></th>
</tr>
<tr>
<th></th>
<th>연도</th>
<th>중분류</th>
<th>소분류</th>
</tr>
</thead>
<tbody>
<th:block th:each="depth2:${depth1.childCategoryList}">
<tr>
<td>
<input type="checkbox" class="categoryCheckBox parentCategory"
th:data-categoryseq="${depth2.categorySeq}" th:data-parentcategory="${depth2.parentCategory}">
</td>
<td th:text="${depth2.categoryName}"></td>
<td></td>
<td></td>
</tr>
<th:block th:each="depth3:${depth2.childCategoryList}">
<tr>
<td>
<input type="checkbox" class="categoryCheckBox parentCategory"
th:data-categoryseq="${depth3.categorySeq}" th:data-parentcategory="${depth3.parentCategory}">
</td>
<td></td>
<td th:text="${depth3.categoryName}"></td>
<td></td>
</tr>
<th:block th:each="depth4:${depth3.childCategoryList}">
<tr>
<td>
<input type="checkbox" class="categoryCheckBox" th:data-categoryseq="${depth4.categorySeq}"
th:data-parentcategory="${depth4.parentCategory}">
</td>
<td></td>
<td></td>
<td th:text="${depth4.categoryName}"></td>
</tr>
</th:block>
</th:block>
</th:block>
</tbody>
</table>
</div>
</th:block>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
<button type="button" class="btn btn-primary" id="saveCategoryRoleBtn">저장</button>
</div>
</div>
</div>
</div>
</div> </div>
</html> </html>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="ko" <html lang="ko"
xmlns:th="http://www.thymeleaf.org" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"> xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5" xmlns="http://www.w3.org/1999/html">
<div class="mx-2 pt-3" th:fragment="leftMenuFragment"> <div class="mx-2 pt-3" th:fragment="leftMenuFragment">
<div sec:authorize="hasRole('ROLE_ADMIN')"> <div sec:authorize="hasRole('ROLE_ADMIN')">
<div class="list-group py-2"> <div class="list-group py-2">
@ -13,10 +13,10 @@
</div> </div>
</div> </div>
<div class="d-grid gap-2"> <div class="d-grid gap-2">
<input type="button" class="btn btn-outline-primary" value="통합 검색"/> <button class="bi bi-search btn btn-outline-primary"> 통합 검색</button>
</div> </div>
<div class="d-grid gap-2"> <div class="d-grid gap-2 pt-1">
<input type="button" class="btn btn-outline-success" value="자료 등록"/> <button class="bi bi-file-earmark-plus btn btn-outline-success"> 자료 등록</button>
</div> </div>
<div sec:authorize="isAuthenticated()"> <div sec:authorize="isAuthenticated()">
<div class="flex-shrink-0 pe-3 py-3 bg-transparent"> <div class="flex-shrink-0 pe-3 py-3 bg-transparent">

View File

@ -4,7 +4,7 @@
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}"> layout:decorate="~{layout/layout}">
<div layout:fragment="content"> <div layout:fragment="content" class="pt-3">
<h1><span sec:authentication="name"></span>님 환영합니다.</h1> <h4>사용자 메인 페이지</h4>
</div> </div>
</html> </html>