Skip to content
Snippets Groups Projects
Commit a94ea14d authored by Ethan Allen-Harris's avatar Ethan Allen-Harris
Browse files

Merge branch 'issueThirtySix' into 'develop'

mering super admin

See merge request !109
parents 52fc43ff fe63e6bc
No related branches found
No related tags found
2 merge requests!114LoggingService service class, new method to add a log to the "Logs" table when...,!109mering super admin
......@@ -40,4 +40,5 @@ public interface UserPermissionsRepo extends JpaRepository<UserPermissions, Long
*/
@Query("select u from UserPermissions u where u.adminType.adminTypeId = ?1")
List<UserPermissions> findByAdminTypeId(long adminTypeId);
}
package com.example.clientproject.service.customObjects;
public class shopAdminObject {
int userId;
String shopName, userName;
public shopAdminObject() {
this.userId = 0;
this.shopName = "";
this.userName = "";
}
public String getShopName(){
return this.shopName;
}
public String getUserName(){
return this.userName;
}
public int getUserId(){
return this.userId;
}
public shopAdminObject(int userId, String shopName, String userName) {
this.userId = userId;
this.shopName = shopName;
this.userName = userName;
}
}
......@@ -9,6 +9,7 @@ import com.example.clientproject.data.stampBoards.StampBoards;
import com.example.clientproject.data.stampBoards.StampBoardsRepo;
import com.example.clientproject.data.userPermissions.UserPermissions;
import com.example.clientproject.data.userPermissions.UserPermissionsRepo;
import com.example.clientproject.service.customObjects.shopAdminObject;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.service.Utils.JWTUtils;
import com.example.clientproject.services.ShopDeleter;
......@@ -22,6 +23,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.util.stream.Collectors;
......@@ -75,7 +77,7 @@ public class AdminController {
model.addAttribute("linkedShop", false);
//Get Shops the user is associated with
if(highestPerm > 1 || userShopLinked.hasShop(user.get().getUserId())){
if(highestPerm == 2 || userShopLinked.hasShop(user.get().getUserId())){
List<Integer> shops = userShopLinked.getByUserId(user.get().getUserId());
//Check if user has defined a shop to look at in the url
Shops shop;
......@@ -99,7 +101,6 @@ public class AdminController {
//userPermissionsRepo.findAll().forEach(x -> System.out.println(x.getUser().getUserId() +":"+ x.getShop().getShopId()));
for(UserPermissions u:linkedList){
if(u.getUser().getUserEmail().equalsIgnoreCase(user.get().getUserEmail())){
continue;
......@@ -147,6 +148,22 @@ public class AdminController {
}
}
List<shopAdminObject> allInfoList = new ArrayList<>();
List<UserPermissions> allUsersPerms = userPermissionsRepo.findByAdminTypeId(2);
for(UserPermissions Owners : allUsersPerms){
Users businessOwner = Owners.getUser();
int businessOwnerId = (int) businessOwner.getUserId();
String businessOwnerName = businessOwner.getUserFirstName();
businessOwnerName = businessOwnerName + " " + businessOwner.getUserLastName();
shopAdminObject allInfo = new shopAdminObject(businessOwnerId, Owners.getShop().getShopName(), businessOwnerName);
//System.out.println(allInfo.getShopName() + allInfo.getUserName() + allInfo.getUserId());
allInfoList.add(allInfo);
}
model.addAttribute("allShopOwners",allInfoList);
model.addAttribute("adminOfByCategory",filteredCategorySortedShops);
model.addAttribute("linkedShop", userShopLinked.hasShop(user.get().getUserId()));
......@@ -201,4 +218,18 @@ public class AdminController {
}
return "redirect:/settings";
}
@PostMapping("/changeAccount")
public String changeAccount (@RequestParam(name="userId", required = true) Integer userId, HttpSession session){
List<UserPermissions> allUserPerms = userPermissionsRepo.findAll();
for (UserPermissions u : allUserPerms) { //loops through userPermissions and checks if curren user is super admin
if (u.getUser().getUserId() == jwtUtils.getLoggedInUserId(session).get()) {
if (u.getAdminType().getAdminTypeId() == 3){
jwtUtils.makeUserJWT(userId, session);
return "redirect:/";
}
}
}
return "redirect:/";
}
}
......@@ -10,7 +10,8 @@ INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, U
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('deanne','aqib','deanneaqib@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',1);
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('kian','chesler','kianchesler@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',2);
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('freddie','lachy','freddielachy@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',2);
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (1,1,1);
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('kerra','oneypenny','kerraoneypenny@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',1);
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (1,1,3);
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (2,1,1);
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (3,1,1);
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (4,1,1);
......@@ -23,8 +24,10 @@ INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (10,1,1);
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('keeganjack','hieb','keeganjackhieb@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',2);
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('faren','krosschell','farenkrosschell@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',1);
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (11,1,2);
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (12,1,2);
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (11,2,2);
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (12,3,2);
SET FOREIGN_KEY_CHECKS=1;
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('aimen','enifer','aimenenifer@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',1);
INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (13,1,3);
......
.text-align-center{
text-align: center;
}
.custom-panel{
width: 600px !important;
}
.custom-record{
display: flex !important;
flex-direction: row !important;
justify-content: space-between !important;
align-items: baseline;
}
.field{
margin-top: 4px;
width: 200px;
}
a.panel-block, label.panel-block {
cursor: default !important;
}
a {
cursor: default !important;
}
.vertScrollbarIfOverflow{
max-height: 300px;
overflow-y: auto;
}
.custom-record.hidden{
display: none !important;
}
......@@ -2,7 +2,8 @@
var isShopSelectOpen = {
"profile":false,
"shop-setup":true,
"shop-rewards":true
"shop-rewards":true,
"super-admin":true
}
function toggle_tab(tab){
......
function changeAccount(userId){
let params="userId=" + userId;
var xhttp = new XMLHttpRequest();
xhttp.open("POST", '/changeAccount', true); // true is asynchronous
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.onload = function () {
if (xhttp.readyState === 4 && xhttp.status === 200) {
console.log(xhttp.responseText);
window.location.href="/";
}
};
xhttp.onerror = function () {
alert("There was an error. Please try again later.");
}
xhttp.send(params);
return false;
}
function searchBusinessOwners(event){
var searchString = event.target.value.toLowerCase();
console.log(event);
for(let row of document.getElementsByClassName("custom-record")){
var record = row.children[0].innerText.toLowerCase() + row.children[1].innerText.toLowerCase();
if(record.includes(searchString)){
row.classList.remove("hidden");
} else {
row.classList.add("hidden");
}
}
}
\ No newline at end of file
......@@ -8,6 +8,8 @@
<link th:replace="fragments/userSocials.html :: socialCss">
<link th:replace="fragments/userSocials.html :: socialJs">
<link th:replace="fragments/deleteShop.html :: delShopCSS">
<link th:replace="fragments/superAdmin.html :: superAdminCSS">
<link th:replace="fragments/superAdmin.html :: superAdminJs">
<link th:replace="fragments/deleteShop.html :: delShopJS">
<link th:replace="fragments/toggleShop.html :: toggleShopJS">
<link th:replace="fragments/businessInformation.html :: infoJs">
......@@ -44,6 +46,12 @@
</div>
<p>Shop Rewards</p>
</div>
<div th:if="${highestPerm == 3}" class="admin-tab" onclick="toggle_tab('super-admin')" id="super-admin-tab">
<div class="baseIcon">
<i class="fab fa-angular fa-lg"></i>
</div>
<p>Super Admin</p>
</div>
</div>
<div class="sidebar closed" id="side_shop_select" th:if="${highestPerm > 1 || linkedShop}">
<th:block th:each="category: ${adminOfByCategory.entrySet()}">
......@@ -79,12 +87,13 @@
<div th:replace="fragments/toggleShop.html :: toggleShop"/>
</th:block>
</section>
<section id="shop-rewards-section" class="admin-section">
<h1 class="title" th:text="'Shop Rewards ('+ ${shop.getShopName()} +')'"></h1>
<div th:replace="fragments/shop_rewards_settings_page.html :: rewards"/>
</section>
<section th:if="${highestPerm == 3}" id="super-admin-section" class="admin-section">
<div th:replace="fragments/superAdmin.html :: super-admin-page"/>
</section>
</main>
<main th:unless="${highestPerm > 1 || linkedShop}">
<section class="admin-section active">
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link th:replace="fragments/libs.html :: bulma"/>
<link th:replace="fragments/libs.html :: fa"/>
<link th:replace="fragments/nav.html :: nav-css"/>
<link th:fragment="superAdminCSS" rel="stylesheet" type="text/css" href="css/superAdmin.css">
<script th:fragment="superAdminJs" src="js/superAdmin.js"></script>
<title>Super Admin</title>
</head>
<body th:fragment="super-admin-page">
<article class="panel is-info custom-panel">
<p class="panel-heading text-align-center">
Swap to shop admin account
</p>
<div class="panel-block">
<p class="control has-icons-left">
<input class="input is-info" type="text" placeholder="Search" oninput="searchBusinessOwners(event)" id="superAdminSearch">
<span class="icon is-left">
<i class="fas fa-search" aria-hidden="true"></i>
</span>
</p>
</div>
<div class="vertScrollbarIfOverflow">
<a th:each="record : ${allShopOwners}" class="panel-block custom-record">
<div class="field" th:text="${record.getShopName}">
<span class="panel-icon">
<i class="fas fa-shopping-cart" style="margin-top: 5px;"></i>
</span>
</div>
<div class="field" th:text="${record.getUserName}">Ethan Allen-Harris</div>
<button class="button is-success is-small is-rounded" th:onclick="changeAccount([[${record.getUserId}]])">Swap</button>
</a>
</div>
</article>
</body>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment