Skip to content

Commit

Permalink
🐛 permission fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pbc1017 committed Mar 18, 2024
1 parent e8d3b3c commit 41ebcd3
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 105 deletions.
17 changes: 10 additions & 7 deletions back/routes/club.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,16 @@ router.get("/division_clubs", async (req, res) => {
},
});

const registrationState = await RegistrationMember.findOne({
where: {
club_id: club.id,
semester_id: currentSemester.id,
student_id: req.session.user.student_id,
},
});
let registrationState = null;
if (!!req.session.user) {
registrationState = await RegistrationMember.findOne({
where: {
club_id: club.id,
semester_id: currentSemester.id,
student_id: req.session.user.student_id,
},
});
}

return {
id: club.id,
Expand Down
14 changes: 7 additions & 7 deletions back/routes/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ router.get("/list", async (req, res) => {

// Authorization check for users with club representative or executive permissions
const clubId = req.query.club_id; // Assuming club_id is provided as a query parameter
const authorized = await checkPermission(req, res, [
{ club_rep: 4, club_id: clubId },
{ executive: 4 },
]);
if (!authorized) {
return res.status(403).send({ message: "권한이 없습니다." });
}
// const authorized = await checkPermission(req, res, [
// { club_rep: 4, club_id: clubId },
// { executive: 4 },
// ]);
// if (!authorized) {
// return res.status(403).send({ message: "권한이 없습니다." });
// }

// Calculate the current time in Korea Time Zone
const now = new Date(
Expand Down
4 changes: 3 additions & 1 deletion front/src/pages/club/ClubList/ClubList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { UnderBar } from "components/home/UnderBar";
import "./ClubList.css";
import { getRequest, postRequest } from "utils/api";
import { useMemberDuration } from "hooks/useReportDurationStatus";
import { useAuth } from "contexts/authContext";

type DivisionType = {
id: number;
Expand All @@ -19,6 +20,7 @@ export const ClubList = (): JSX.Element => {
const [divisions, setDivisions] = useState<DivisionType[]>([]);

const clubListRef = useRef<HTMLDivElement>(null);
const { user } = useAuth(); // authContext에서 user 정보 가져오기

const { status } = useMemberDuration(true);

Expand Down Expand Up @@ -171,7 +173,7 @@ export const ClubList = (): JSX.Element => {
president={club.clubPresident}
advisor={club.advisor}
totalNumbers={club.totalMembers}
isRegistration={status === 1}
isRegistration={status === 1 && user}
registrationState={club.registrationState}
onRegistrationClick={() =>
handleRegister(
Expand Down
182 changes: 92 additions & 90 deletions front/src/pages/club/ClubManage/ClubManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,102 +421,104 @@ export const ClubManage = (): JSX.Element => {
</div>
</div>
)}
<div className="frame-13">
<SubTitle
className="sub-title-instance"
divClassName="design-component-instance-node"
text={`${currentClubInfo.clubName} 회원 신청`}
/>
<div className="frame-22">
<Activity
property1="variant-2"
isRegistration={5}
activityStateProperty1={2}
id={0}
{status.typeId < 4 && (
<div className="frame-13">
<SubTitle
className="sub-title-instance"
divClassName="design-component-instance-node"
text={`${currentClubInfo.clubName} 회원 신청`}
/>
{applyLists[status.clubId]?.map((member, index) => (
<div className="frame-22">
<Activity
key={index}
index={index + 1}
name={`${member.studentId} ${member.name}`}
type={member.email}
start_date={member.startDate}
activityStateProperty1={member.feedbackType}
property1="variant-2"
isRegistration={5}
handleRegistration={() => {
if (member.feedbackType === 1) {
const isConfirmed = window.confirm(
`${member.name}의 가입을 승인하시겠습니까? ('확인'을 누르면 승인, '취소'를 누르면 반려됩니다.)`
);

// Approval case
if (isConfirmed) {
postRequest(
`member/approve?student_id=${member.studentId}&club_id=${status.clubId}`,
{},
() => {
// Update feedbackType to approved
const updatedApplies = applyLists[
status.clubId
].map(
(appl) =>
appl.studentId === member.studentId
? { ...appl, feedbackType: 2 }
: appl // Assuming feedbackType 2 means approved
);
setApplyLists({
...applyLists,
[status.clubId]: updatedApplies,
});
// alert(
// `${member.name}의 가입이 승인되었습니다.`
// );
},
(error) => {
console.error(
"Error approving member:",
error
);
}
);
} else {
// Disapproval case
postRequest(
`member/disapprove?student_id=${member.studentId}&club_id=${status.clubId}`,
{},
() => {
// Update feedbackType to disapproved
const updatedApplies = applyLists[
status.clubId
].map(
(appl) =>
appl.studentId === member.studentId
? { ...appl, feedbackType: 3 }
: appl // Assuming feedbackType 3 means disapproved
);
setApplyLists({
...applyLists,
[status.clubId]: updatedApplies,
});
// alert(
// `${member.name}의 가입이 거절되었습니다.`
// );
},
(error) => {
console.error(
"Error disapproving member:",
error
);
}
activityStateProperty1={2}
id={0}
/>
{applyLists[status.clubId]?.map((member, index) => (
<Activity
key={index}
index={index + 1}
name={`${member.studentId} ${member.name}`}
type={member.email}
start_date={member.startDate}
activityStateProperty1={member.feedbackType}
isRegistration={5}
handleRegistration={() => {
if (member.feedbackType === 1) {
const isConfirmed = window.confirm(
`${member.name}의 가입을 승인하시겠습니까? ('확인'을 누르면 승인, '취소'를 누르면 반려됩니다.)`
);

// Approval case
if (isConfirmed) {
postRequest(
`member/approve?student_id=${member.studentId}&club_id=${status.clubId}`,
{},
() => {
// Update feedbackType to approved
const updatedApplies = applyLists[
status.clubId
].map(
(appl) =>
appl.studentId === member.studentId
? { ...appl, feedbackType: 2 }
: appl // Assuming feedbackType 2 means approved
);
setApplyLists({
...applyLists,
[status.clubId]: updatedApplies,
});
// alert(
// `${member.name}의 가입이 승인되었습니다.`
// );
},
(error) => {
console.error(
"Error approving member:",
error
);
}
);
} else {
// Disapproval case
postRequest(
`member/disapprove?student_id=${member.studentId}&club_id=${status.clubId}`,
{},
() => {
// Update feedbackType to disapproved
const updatedApplies = applyLists[
status.clubId
].map(
(appl) =>
appl.studentId === member.studentId
? { ...appl, feedbackType: 3 }
: appl // Assuming feedbackType 3 means disapproved
);
setApplyLists({
...applyLists,
[status.clubId]: updatedApplies,
});
// alert(
// `${member.name}의 가입이 거절되었습니다.`
// );
},
(error) => {
console.error(
"Error disapproving member:",
error
);
}
);
}
}
}
}}
id={member.studentId}
/>
))}
}}
id={member.studentId}
/>
))}
</div>
</div>
</div>
)}
<div className="frame-16">
<div className="frame-21" style={{ marginBottom: "80px" }}>
<div className="frame-13">
Expand Down

0 comments on commit 41ebcd3

Please sign in to comment.