Skip to content
Snippets Groups Projects
Commit 8a4c01a1 authored by Seb Barnard's avatar Seb Barnard :speech_balloon:
Browse files

Fixed staff member validation, changed some redirects to be up to date

parent cecf7c18
No related branches found
No related tags found
3 merge requests!114LoggingService service class, new method to add a log to the "Logs" table when...,!104Branch Update,!103Issue thirty four
package com.example.clientproject.service.Utils;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.userPermissions.UserPermissions;
import com.example.clientproject.data.userPermissions.UserPermissionsRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class CheckUserOwner {
@Autowired
UserPermissionsRepo permissionsRepo;
public boolean checkOwner(int userId, int shopId){
List<UserPermissions> permissions = permissionsRepo.findByShopID(shopId);
for(UserPermissions u:permissions){
if(u.getUser().getUserId() == userId){
if(u.getAdminType().getAdminTypeId() == 2){
return true;
}
}
}return false;
}
}
...@@ -30,4 +30,22 @@ public class UserLinked { ...@@ -30,4 +30,22 @@ public class UserLinked {
} }
} return false; } return false;
} }
public boolean isAnyAdmin(int userId){
List<UserPermissions> allLinks = userPermRepo.findByUserId(userId);
for(UserPermissions u:allLinks){
if(u.getAdminType().getAdminTypeId() == 2){
return true;
}
}return false;
}
public int userAdminShopId(int userId){
List<UserPermissions> allLinks = userPermRepo.findByUserId(userId);
for(UserPermissions u:allLinks){
if(u.getAdminType().getAdminTypeId() == 2){
return (int) u.getShop().getShopId();
}
}return 0;
}
} }
...@@ -11,6 +11,7 @@ import com.example.clientproject.service.dtos.UsersDTO; ...@@ -11,6 +11,7 @@ import com.example.clientproject.service.dtos.UsersDTO;
import com.example.clientproject.service.searches.UsersSearch; import com.example.clientproject.service.searches.UsersSearch;
import com.example.clientproject.services.BusinessRegisterDTO; import com.example.clientproject.services.BusinessRegisterDTO;
import com.example.clientproject.services.BusinessRegisterSaver; import com.example.clientproject.services.BusinessRegisterSaver;
import com.example.clientproject.services.UserLinked;
import com.example.clientproject.services.UserShopLinked; import com.example.clientproject.services.UserShopLinked;
import com.example.clientproject.web.forms.BusinessRegisterForm; import com.example.clientproject.web.forms.BusinessRegisterForm;
import com.example.clientproject.web.forms.signUpAndIn.LoginForm; import com.example.clientproject.web.forms.signUpAndIn.LoginForm;
...@@ -35,20 +36,20 @@ public class SignInController { ...@@ -35,20 +36,20 @@ public class SignInController {
private JWTUtils jwtUtils; private JWTUtils jwtUtils;
private UserShopLinked userShopLinked; private UserLinked userLinked;
private UserPermissionsRepo userPermissionsRepo; private UserPermissionsRepo userPermissionsRepo;
private CategoriesRepo catRepo; private CategoriesRepo catRepo;
public SignInController(UsersSearch aUsersSearch, BusinessRegisterSaver sBusiness, JWTUtils ajwtUtils, public SignInController(UsersSearch aUsersSearch, BusinessRegisterSaver sBusiness, JWTUtils ajwtUtils,
UserShopLinked aUserShopLinked, UserLinked aUserShopLinked,
UserPermissionsRepo aUserPermissionsRepo, UserPermissionsRepo aUserPermissionsRepo,
CategoriesRepo aCatRepo) { CategoriesRepo aCatRepo) {
usersSearch = aUsersSearch; usersSearch = aUsersSearch;
saveBusiness = sBusiness; saveBusiness = sBusiness;
jwtUtils = ajwtUtils; jwtUtils = ajwtUtils;
userShopLinked = aUserShopLinked; userLinked = aUserShopLinked;
userPermissionsRepo = aUserPermissionsRepo; userPermissionsRepo = aUserPermissionsRepo;
catRepo = aCatRepo; catRepo = aCatRepo;
} }
...@@ -72,12 +73,10 @@ public class SignInController { ...@@ -72,12 +73,10 @@ public class SignInController {
} }
//System.out.println(userShopLinked.hasShop(jwtUtils.getLoggedInUserId(session).get())); //System.out.println(userShopLinked.hasShop(jwtUtils.getLoggedInUserId(session).get()));
if(userShopLinked.hasShop(jwtUtils.getLoggedInUserId(session).get())){ if(userLinked.isAnyAdmin(jwtUtils.getLoggedInUserId(session).get())){
long userId = jwtUtils.getLoggedInUserId(session).get();
long shopId = userPermissionsRepo.findByUserId(userId).get(0).getShop().getShopId(); int shopId = userLinked.userAdminShopId(jwtUtils.getLoggedInUserId(session).get());
if(shopId == 1){
shopId = userPermissionsRepo.findByUserId(userId).get(1).getShop().getShopId();
}
return "redirect:/redirect?url=businessDetails?shopId="+shopId; return "redirect:/redirect?url=businessDetails?shopId="+shopId;
} }
List<Categories> categories = catRepo.findAll(); List<Categories> categories = catRepo.findAll();
......
...@@ -10,6 +10,8 @@ function submit(shopId, email={"value":""}){ ...@@ -10,6 +10,8 @@ function submit(shopId, email={"value":""}){
document.getElementsByName("staffEmail").forEach(x => emailArray.push(x.innerHTML)) document.getElementsByName("staffEmail").forEach(x => emailArray.push(x.innerHTML))
console.log(emailArray)
if(emailArray.includes(emailValue)){ if(emailArray.includes(emailValue)){
document.getElementById("emailErrorField").innerHTML = "User already added" document.getElementById("emailErrorField").innerHTML = "User already added"
return return
...@@ -42,7 +44,7 @@ function submit(shopId, email={"value":""}){ ...@@ -42,7 +44,7 @@ function submit(shopId, email={"value":""}){
document.getElementById("staffManagement").innerHTML+= document.getElementById("staffManagement").innerHTML+=
`<div id="staffManagement"> `<div id="staffManagement">
<div class="staffManagementContainer"> <div class="staffManagementContainer">
<p class="subtitle is-6" style="width:50%; margin-bottom: 0">${emailValue}</p> <p class="subtitle is-6" name="staffEmail" style="width:50%; margin-bottom: 0">${emailValue}</p>
<button class="button is-danger is-outlined" style="border-bottom: 1px solid" <button class="button is-danger is-outlined" style="border-bottom: 1px solid"
onclick="submit(${document.getElementById("shopId").value},this);"> onclick="submit(${document.getElementById("shopId").value},this);">
<span class="icon is-small"> <span class="icon is-small">
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
<div th:replace="fragments/businessInformation :: keyInformation"></div> <div th:replace="fragments/businessInformation :: keyInformation"></div>
<div th:replace="fragments/userSocials.html :: userSocial"/> <div th:replace="fragments/userSocials.html :: userSocial"/>
<br> <br>
<th:block th:if="${highestShopLevel>=2}"> <th:block th:if="${@checkUserOwner.checkOwner(loggedInUser.userId, shop.shopId)}">
<div th:replace="fragments/manageStaff.html :: manageStaffMembers"/> <div th:replace="fragments/manageStaff.html :: manageStaffMembers"/>
<div th:replace="fragments/deleteShop.html :: deleteShop"/> <div th:replace="fragments/deleteShop.html :: deleteShop"/>
<div th:replace="fragments/toggleShop.html :: toggleShop"/> <div th:replace="fragments/toggleShop.html :: toggleShop"/>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<input type="text" th:value="${shop.shopName}" id="nameInput" class="input"> <input type="text" th:value="${shop.shopName}" id="nameInput" class="input">
<p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Description</p> <p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Description</p>
<textarea class="textarea" id="descriptionInput" th:text="${shop.shopDescription}" cols="30" rows="10"></textarea> <textarea class="textarea" id="descriptionInput" maxlength="250" th:text="${shop.shopDescription}" cols="30" rows="10"></textarea>
<p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Banner</p> <p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Banner</p>
<img class="mb-3" id="bannerPreview" th:src="${shop.shopBanner}" style="margin-top: 5px; max-height: 100px"> <img class="mb-3" id="bannerPreview" th:src="${shop.shopBanner}" style="margin-top: 5px; max-height: 100px">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment