Check vote log before allowing cancellation

This commit is contained in:
Kijin Sung 2018-11-30 16:04:50 +09:00
parent e7b272f7af
commit 75a468552d
9 changed files with 46 additions and 8 deletions

View file

@ -268,7 +268,9 @@ $lang->fail_to_update = 'Fail to update.';
$lang->fail_to_delete = 'Failed to delete.';
$lang->fail_to_move = 'Failed to move.';
$lang->failed_voted = 'No permission to upvote.';
$lang->failed_voted_canceled = 'You cannot cancel an upvote that you did\'t make.';
$lang->failed_blamed = 'No permission to downvote.';
$lang->failed_blamed_canceled = 'You cannot cancel a downvote that you did\'t make.';
$lang->failed_declared = 'No permission to Report.';
$lang->fail_to_delete_have_children = 'Cannot delete the article with comments.';
$lang->confirm_submit = 'Are you sure you want to submit?';

View file

@ -268,7 +268,9 @@ $lang->fail_to_update = '수정하지 못했습니다.';
$lang->fail_to_delete = '삭제 실패했습니다.';
$lang->fail_to_move = '이동 실패했습니다.';
$lang->failed_voted = '추천할 수 없습니다.';
$lang->failed_voted_canceled = '추천한 적이 없으므로 취소할 수 없습니다.';
$lang->failed_blamed = '비추천할 수 없습니다.';
$lang->failed_blamed_canceled = '비추천한 적이 없으므로 취소할 수 없습니다.';
$lang->failed_declared = '신고할 수 없습니다.';
$lang->fail_to_delete_have_children = '댓글이 있어서 삭제할 수 없습니다.';
$lang->confirm_submit = '등록하시겠습니까?';

View file

@ -79,7 +79,7 @@ class commentController extends comment
$oComment = $oCommentModel->getComment($comment_srl, FALSE, FALSE);
if($oComment->get('voted_count') <= 0)
{
throw new Rhymix\Framework\Exception('msg_comment_voted_cancel_not');
throw new Rhymix\Framework\Exception('failed_voted_canceled');
}
$point = 1;
$output = $this->updateVotedCountCancel($comment_srl, $oComment, $point);
@ -149,7 +149,7 @@ class commentController extends comment
$oComment = $oCommentModel->getComment($comment_srl, FALSE, FALSE);
if($oComment->get('blamed_count') >= 0)
{
throw new Rhymix\Framework\Exception('msg_comment_blamed_cancel_not');
throw new Rhymix\Framework\Exception('failed_blamed_canceled');
}
$point = -1;
$output = $this->updateVotedCountCancel($comment_srl, $oComment, $point);
@ -163,6 +163,24 @@ class commentController extends comment
function updateVotedCountCancel($comment_srl, $oComment, $point)
{
$logged_info = Context::get('logged_info');
// Check if the current user has voted previously.
$args = new stdClass;
$args->comment_srl = $comment_srl;
$args->point = $point;
if($logged_info->member_srl)
{
$args->member_srl = $logged_info->member_srl;
}
else
{
$args->ipaddress = $_SERVER['REMOTE_ADDR'];
}
$output = executeQuery('comment.getCommentVotedLogInfo', $args);
if(!$output->data->count)
{
return new BaseObject(-1, $point > 0 ? 'failed_voted_canceled' : 'failed_blamed_canceled');
}
// Call a trigger (before)
$trigger_obj = new stdClass;

View file

@ -7,8 +7,6 @@ $lang->trash = '휴지통';
$lang->cmd_trash = '휴지통으로 이동';
$lang->comment_count = '댓글 수';
$lang->about_comment_count = '댓글을 정해진 수 만큼만 표시하고, 그 이상일 경우 페이지 번호를 표시해서 이동할 수 있게 합니다.';
$lang->msg_comment_voted_cancel_not = '추천수가 0이하일 경우 추천캔슬을 사용할 수 없습니다.';
$lang->msg_comment_blamed_cancel_not = '추천수가 0이하일 경우 비추천캔슬을 사용할 수 없습니다.';
$lang->msg_cart_is_null = '삭제할 글을 선택해주세요.';
$lang->msg_checked_comment_is_deleted = '%d개의 댓글을 삭제했습니다.';
$lang->search_target_list['content'] = '내용';

View file

@ -7,6 +7,7 @@
</columns>
<conditions>
<condition operation="equal" column="comment_srl" var="comment_srl" filter="number" notnull="notnull" />
<condition operation="equal" column="point" var="point" filter="number" />
<group pipe="and">
<condition operation="equal" column="member_srl" var="member_srl" filter="number" pipe="and" />
<condition operation="equal" column="ipaddress" var="ipaddress" pipe="and" />

View file

@ -71,7 +71,7 @@ class documentController extends document
$oDocument = $oDocumentModel->getDocument($document_srl, false, false);
if($oDocument->get('voted_count') <= 0)
{
throw new Rhymix\Framework\Exception('msg_document_voted_cancel_not');
throw new Rhymix\Framework\Exception('failed_voted_canceled');
}
$point = 1;
$output = $this->updateVotedCountCancel($document_srl, $oDocument, $point);
@ -157,7 +157,7 @@ class documentController extends document
$oDocument = $oDocumentModel->getDocument($document_srl, false, false);
if($oDocument->get('blamed_count') >= 0)
{
throw new Rhymix\Framework\Exception('msg_document_voted_cancel_not');
throw new Rhymix\Framework\Exception('failed_blamed_canceled');
}
$point = -1;
$output = $this->updateVotedCountCancel($document_srl, $oDocument, $point);
@ -181,6 +181,24 @@ class documentController extends document
function updateVotedCountCancel($document_srl, $oDocument, $point)
{
$logged_info = Context::get('logged_info');
// Check if the current user has voted previously.
$args = new stdClass;
$args->document_srl = $document_srl;
$args->point = $point;
if($logged_info->member_srl)
{
$args->member_srl = $logged_info->member_srl;
}
else
{
$args->ipaddress = $_SERVER['REMOTE_ADDR'];
}
$output = executeQuery('document.getDocumentVotedLogInfo', $args);
if(!$output->data->count)
{
return new BaseObject(-1, $point > 0 ? 'failed_voted_canceled' : 'failed_blamed_canceled');
}
// Call a trigger (before)
$trigger_obj = new stdClass;

View file

@ -28,7 +28,6 @@ $lang->msg_category_not_moved = 'Could not be moved';
$lang->msg_is_secret = 'This is a secret article.';
$lang->msg_checked_document_is_deleted = '%d article(s) was(were) deleted.';
$lang->msg_document_is_admin_not_permitted = 'You don\'t have permission to delete the posts of Top Admin.';
$lang->msg_document_voted_cancel_not = '';
$lang->move_target_module = 'Target module ';
$lang->search_target_list['title'] = 'Subject';
$lang->search_target_list['content'] = 'Content';

View file

@ -36,7 +36,6 @@ $lang->msg_category_not_moved = '이동할 수 없습니다.';
$lang->msg_is_secret = '비밀글입니다.';
$lang->msg_checked_document_is_deleted = '%d개의 글이 삭제되었습니다.';
$lang->msg_document_is_admin_not_permitted = '최고 관리자의 게시글을 삭제할 권한이 없습니다.';
$lang->msg_document_voted_cancel_not = '추천 수가 0 이하일 경우 추천 취소를 사용할 수 없습니다.';
$lang->move_target_module = '대상 페이지';
$lang->search_target_list['title'] = '제목';
$lang->search_target_list['content'] = '내용';

View file

@ -7,6 +7,7 @@
</columns>
<conditions>
<condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" />
<condition operation="equal" column="point" var="point" filter="number" />
<group pipe="and">
<condition operation="equal" column="member_srl" var="member_srl" filter="number" pipe="and" />
<condition operation="equal" column="ipaddress" var="ipaddress" pipe="and" />