관리자 업로드시 용량 제한을 '제한 없음'으로 표시

This commit is contained in:
conory 2019-10-05 13:26:45 +09:00
parent 111a010e72
commit 4bb380cfa8
3 changed files with 75 additions and 83 deletions

View file

@ -359,3 +359,5 @@ $lang->video = 'Video';
$lang->text = 'Text'; $lang->text = 'Text';
$lang->image_quality = 'Quality'; $lang->image_quality = 'Quality';
$lang->standard = 'Standard'; $lang->standard = 'Standard';
$lang->unlimited = 'Unlimited';
$lang->admin = 'Admin';

View file

@ -363,3 +363,5 @@ $lang->video = '동영상';
$lang->text = '텍스트'; $lang->text = '텍스트';
$lang->image_quality = '화질'; $lang->image_quality = '화질';
$lang->standard = '표준'; $lang->standard = '표준';
$lang->unlimited = '제한 없음';
$lang->admin = '관리자';

View file

@ -24,109 +24,107 @@ class fileModel extends file
*/ */
function getFileList() function getFileList()
{ {
$oModuleModel = getModel('module'); $file_list = [];
$attached_size = 0;
$mid = Context::get('mid');
$editor_sequence = Context::get('editor_sequence'); $editor_sequence = Context::get('editor_sequence');
$upload_target_srl = Context::get('upload_target_srl'); $upload_target_srl = Context::get('upload_target_srl') ?: 0;
if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl; if(!$upload_target_srl && isset($_SESSION['upload_info'][$editor_sequence]))
{
$upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl;
}
// Get uploaded files
if($upload_target_srl) if($upload_target_srl)
{ {
$oDocumentModel = getModel('document'); $oModuleModel = getModel('module');
$oCommentModel = getModel('comment'); $oCommentModel = getModel('comment');
$logged_info = Context::get('logged_info'); $oDocumentModel = getModel('document');
$oDocument = $oDocumentModel->getDocument($upload_target_srl); $oDocument = $oDocumentModel->getDocument($upload_target_srl);
// comment 권한 확인 // Check permissions of comment
if(!$oDocument->isExists()) if(!$oDocument->isExists())
{ {
$oComment = $oCommentModel->getComment($upload_target_srl); $oComment = $oCommentModel->getComment($upload_target_srl);
if($oComment->isExists() && !$oComment->isAccessible()) if($oComment->isExists())
{ {
throw new Rhymix\Framework\Exceptions\NotPermitted; if(!$oComment->isAccessible())
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$oDocument = $oDocumentModel->getDocument($oComment->get('document_srl'));
} }
$oDocument = $oDocumentModel->getDocument($oComment->get('document_srl'));
} }
// document 권한 확인 // Check permissions of document
if($oDocument->isExists() && !$oDocument->isAccessible()) if($oDocument->isExists() && !$oDocument->isAccessible())
{ {
throw new Rhymix\Framework\Exceptions\NotPermitted; throw new Rhymix\Framework\Exceptions\NotPermitted;
} }
// 모듈 권한 확인 // Check permissions of the module
if($oDocument->isExists()) if($module_srl = isset($oComment) ? $oComment->get('module_srl') : $oDocument->get('module_srl'))
{ {
$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($oDocument->get('module_srl')), $logged_info); $module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
if(empty($module_info->module_srl))
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$grant = $oModuleModel->getGrant($module_info, Context::get('logged_info'));
if(!$grant->access) if(!$grant->access)
{ {
throw new Rhymix\Framework\Exceptions\NotPermitted; throw new Rhymix\Framework\Exceptions\NotPermitted;
} }
} }
$tmp_files = $this->getFiles($upload_target_srl); // Set file list
if($tmp_files instanceof BaseObject && !$tmp_files->toBool()) return $tmp_files; foreach($this->getFiles($upload_target_srl) as $file_info)
$files = array();
foreach($tmp_files as $file_info)
{ {
if(!$file_info->file_srl)
{
continue;
}
$obj = new stdClass; $obj = new stdClass;
$obj->file_srl = $file_info->file_srl; $obj->file_srl = $file_info->file_srl;
$obj->source_filename = $file_info->source_filename; $obj->source_filename = $file_info->source_filename;
$obj->thumbnail_filename = $file_info->thumbnail_filename; $obj->thumbnail_filename = $file_info->thumbnail_filename;
$obj->type = $file_info->type;
$obj->original_type = $file_info->original_type; $obj->original_type = $file_info->original_type;
$obj->file_size = $file_info->file_size; $obj->file_size = $file_info->file_size;
$obj->disp_file_size = FileHandler::filesize($file_info->file_size); $obj->disp_file_size = FileHandler::filesize($file_info->file_size);
if($file_info->direct_download == 'N') $obj->direct_download = $file_info->direct_download;
{ $obj->cover_image = ($file_info->cover_image === 'Y') ? true : false;
$obj->download_url = $this->getDownloadUrl($file_info->file_srl, $file_info->sid, $file_info->module_srl); $obj->download_url = $file_info->download_url;
} if($obj->direct_download === 'Y')
else
{ {
$obj->download_url = $this->getDirectFileUrl($file_info->uploaded_filename); $obj->download_url = $this->getDirectFileUrl($file_info->uploaded_filename);
} }
$obj->direct_download = $file_info->direct_download;
$obj->cover_image = ($file_info->cover_image === 'Y') ? true : false; $file_list[] = $obj;
$files[] = $obj;
$attached_size += $file_info->file_size; $attached_size += $file_info->file_size;
} }
} }
// Set output
$this->add('files', $file_list);
$this->add('attached_size', FileHandler::filesize($attached_size));
$this->add('editor_sequence', $editor_sequence);
$this->add('upload_target_srl', $upload_target_srl);
// Set upload config
$upload_config = $this->getUploadConfig();
if($this->user->isAdmin())
{
$this->add('allowed_filesize', sprintf('%s (%s)', lang('common.unlimited'), lang('common.admin')));
$this->add('allowed_attach_size', sprintf('%s (%s)', lang('common.unlimited'), lang('common.admin')));
$this->add('allowed_extensions', []);
}
else else
{ {
$upload_target_srl = 0; $this->add('allowed_filesize', FileHandler::filesize($upload_config->allowed_filesize * 1024 * 1024));
$attached_size = 0; $this->add('allowed_attach_size', FileHandler::filesize($upload_config->allowed_attach_size * 1024 * 1024));
$files = array(); $this->add('allowed_extensions', $upload_config->allowed_extensions);
} }
// Display upload status
$upload_status = $this->getUploadStatus($attached_size); // for compatibility
// Check remained file size until upload complete $this->add('allowed_filetypes', $upload_config->allowed_filetypes);
//$config = $oModuleModel->getModuleInfoByMid($mid); //perhaps config varialbles not used $this->add('upload_status', $this->getUploadStatus($attached_size));
$this->add('left_size', $upload_config->allowed_attach_size * 1024 * 1024 - $attached_size);
$file_config = $this->getUploadConfig();
$left_size = $file_config->allowed_attach_size*1024*1024 - $attached_size;
// Settings of required information
$attached_size = FileHandler::filesize($attached_size);
$allowed_attach_size = FileHandler::filesize($file_config->allowed_attach_size*1024*1024);
$allowed_filesize = FileHandler::filesize($file_config->allowed_filesize*1024*1024);
$allowed_filetypes = $file_config->allowed_filetypes;
$allowed_extensions = $file_config->allowed_extensions ?: array();
$this->add("files",$files);
$this->add("editor_sequence",$editor_sequence);
$this->add("upload_target_srl",$upload_target_srl);
$this->add("upload_status",$upload_status);
$this->add("left_size",$left_size);
$this->add('attached_size', $attached_size);
$this->add('allowed_attach_size', $allowed_attach_size);
$this->add('allowed_filesize', $allowed_filesize);
$this->add('allowed_filetypes', $allowed_filetypes);
$this->add('allowed_extensions', $allowed_extensions);
} }
/** /**
@ -295,26 +293,16 @@ class fileModel extends file
*/ */
function getUploadConfig() function getUploadConfig()
{ {
$logged_info = Context::get('logged_info'); $config = $this->getFileConfig(Context::get('module_srl') ?: Context::get('current_module_info')->module_srl);
if($this->user->isAdmin())
$module_srl = Context::get('module_srl');
// Get the current module if module_srl doesn't exist
if(!$module_srl)
{ {
$current_module_info = Context::get('current_module_info'); $module_config = getModel('module')->getModuleConfig('file');
$module_srl = $current_module_info->module_srl; $config->allowed_filesize = max($config->allowed_filesize, $module_config->allowed_filesize);
$config->allowed_attach_size = max($config->allowed_attach_size, $module_config->allowed_attach_size);
$config->allowed_extensions = [];
$config->allowed_filetypes = '*.*';
} }
$file_config = $this->getFileConfig($module_srl); return $config;
if($logged_info->is_admin == 'Y')
{
$oModuleModel = getModel('module');
$module_config = $oModuleModel->getModuleConfig('file');
$file_config->allowed_filesize = max($file_config->allowed_filesize, $module_config->allowed_filesize);
$file_config->allowed_attach_size = max($file_config->allowed_attach_size, $module_config->allowed_attach_size);
$file_config->allowed_filetypes = '*.*';
}
return $file_config;
} }
/** /**