@@ -155,6 +155,14 @@ public function copy()
155155 $ templateID = $ this ->input ->getInt ('id ' , 0 );
156156 $ file = $ this ->input ->get ('file ' );
157157
158+ // Access check.
159+ if (!$ this ->allowEdit ())
160+ {
161+ $ app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
162+
163+ return false ;
164+ }
165+
158166 $ this ->setRedirect ('index.php?option=com_templates&view=template&id= ' . $ templateID . '&file= ' . $ file );
159167
160168 /* @var \Joomla\Component\Templates\Administrator\Model\TemplateModel $model */
@@ -260,19 +268,7 @@ public function getModel($name = 'Template', $prefix = 'Administrator', $config
260268 */
261269 protected function allowEdit ()
262270 {
263- return $ this ->app ->getIdentity ()->authorise ('core.edit ' , 'com_templates ' );
264- }
265-
266- /**
267- * Method to check if you can save a new or existing record.
268- *
269- * @return boolean
270- *
271- * @since 3.2
272- */
273- protected function allowSave ()
274- {
275- return $ this ->allowEdit ();
271+ return $ this ->app ->getIdentity ()->authorise ('core.admin ' );
276272 }
277273
278274 /**
@@ -296,7 +292,7 @@ public function save()
296292 $ explodeArray = explode (': ' , base64_decode ($ fileName ));
297293
298294 // Access check.
299- if (!$ this ->allowSave ())
295+ if (!$ this ->allowEdit ())
300296 {
301297 $ this ->setMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
302298
@@ -411,6 +407,14 @@ public function overrides()
411407 $ override = base64_decode ($ this ->input ->get ('folder ' ));
412408 $ id = $ this ->input ->get ('id ' );
413409
410+ // Access check.
411+ if (!$ this ->allowEdit ())
412+ {
413+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
414+
415+ return ;
416+ }
417+
414418 if ($ model ->createOverride ($ override ))
415419 {
416420 $ this ->setMessage (Text::_ ('COM_TEMPLATES_OVERRIDE_SUCCESS ' ));
@@ -438,6 +442,14 @@ public function delete()
438442 $ id = $ this ->input ->get ('id ' );
439443 $ file = $ this ->input ->get ('file ' );
440444
445+ // Access check.
446+ if (!$ this ->allowEdit ())
447+ {
448+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
449+
450+ return ;
451+ }
452+
441453 if (base64_decode (urldecode ($ file )) == '/index.php ' )
442454 {
443455 $ this ->setMessage (Text::_ ('COM_TEMPLATES_ERROR_INDEX_DELETE ' ), 'warning ' );
@@ -479,6 +491,14 @@ public function createFile()
479491 $ location = base64_decode ($ this ->input ->get ('address ' ));
480492 $ type = $ this ->input ->get ('type ' );
481493
494+ // Access check.
495+ if (!$ this ->allowEdit ())
496+ {
497+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
498+
499+ return ;
500+ }
501+
482502 if ($ type == 'null ' )
483503 {
484504 $ this ->setMessage (Text::_ ('COM_TEMPLATES_INVALID_FILE_TYPE ' ), 'error ' );
@@ -525,6 +545,14 @@ public function uploadFile()
525545 $ upload = $ this ->input ->files ->get ('files ' );
526546 $ location = base64_decode ($ this ->input ->get ('address ' ));
527547
548+ // Access check.
549+ if (!$ this ->allowEdit ())
550+ {
551+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
552+
553+ return ;
554+ }
555+
528556 if ($ return = $ model ->uploadFile ($ upload , $ location ))
529557 {
530558 $ this ->setMessage (Text::_ ('COM_TEMPLATES_FILE_UPLOAD_SUCCESS ' ) . $ upload ['name ' ]);
@@ -559,6 +587,14 @@ public function createFolder()
559587 $ name = $ this ->input ->get ('name ' );
560588 $ location = base64_decode ($ this ->input ->get ('address ' ));
561589
590+ // Access check.
591+ if (!$ this ->allowEdit ())
592+ {
593+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
594+
595+ return ;
596+ }
597+
562598 if (!preg_match ('/^[a-zA-Z0-9-_.]+$/ ' , $ name ))
563599 {
564600 $ this ->setMessage (Text::_ ('COM_TEMPLATES_INVALID_FOLDER_NAME ' ), 'error ' );
@@ -597,6 +633,14 @@ public function deleteFolder()
597633 $ file = $ this ->input ->get ('file ' );
598634 $ location = base64_decode ($ this ->input ->get ('address ' ));
599635
636+ // Access check.
637+ if (!$ this ->allowEdit ())
638+ {
639+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
640+
641+ return ;
642+ }
643+
600644 if (empty ($ location ))
601645 {
602646 $ this ->setMessage (Text::_ ('COM_TEMPLATES_ERROR_ROOT_DELETE ' ), 'warning ' );
@@ -641,6 +685,14 @@ public function renameFile()
641685 $ file = $ this ->input ->get ('file ' );
642686 $ newName = $ this ->input ->get ('new_name ' );
643687
688+ // Access check.
689+ if (!$ this ->allowEdit ())
690+ {
691+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
692+
693+ return ;
694+ }
695+
644696 if (base64_decode (urldecode ($ file )) == '/index.php ' )
645697 {
646698 $ this ->setMessage (Text::_ ('COM_TEMPLATES_ERROR_RENAME_INDEX ' ), 'warning ' );
@@ -676,6 +728,9 @@ public function renameFile()
676728 */
677729 public function cropImage ()
678730 {
731+ // Check for request forgeries
732+ $ this ->checkToken ();
733+
679734 $ id = $ this ->input ->get ('id ' );
680735 $ file = $ this ->input ->get ('file ' );
681736 $ x = $ this ->input ->get ('x ' );
@@ -686,6 +741,14 @@ public function cropImage()
686741 /** @var \Joomla\Component\Templates\Administrator\Model\TemplateModel $model */
687742 $ model = $ this ->getModel ();
688743
744+ // Access check.
745+ if (!$ this ->allowEdit ())
746+ {
747+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
748+
749+ return ;
750+ }
751+
689752 if (empty ($ w ) && empty ($ h ) && empty ($ x ) && empty ($ y ))
690753 {
691754 $ this ->setMessage (Text::_ ('COM_TEMPLATES_CROP_AREA_ERROR ' ), 'error ' );
@@ -715,6 +778,9 @@ public function cropImage()
715778 */
716779 public function resizeImage ()
717780 {
781+ // Check for request forgeries
782+ $ this ->checkToken ();
783+
718784 $ id = $ this ->input ->get ('id ' );
719785 $ file = $ this ->input ->get ('file ' );
720786 $ width = $ this ->input ->get ('width ' );
@@ -723,6 +789,14 @@ public function resizeImage()
723789 /** @var \Joomla\Component\Templates\Administrator\Model\TemplateModel $model */
724790 $ model = $ this ->getModel ();
725791
792+ // Access check.
793+ if (!$ this ->allowEdit ())
794+ {
795+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
796+
797+ return ;
798+ }
799+
726800 if ($ model ->resizeImage ($ file , $ width , $ height ))
727801 {
728802 $ this ->setMessage (Text::_ ('COM_TEMPLATES_FILE_RESIZE_SUCCESS ' ));
@@ -757,6 +831,14 @@ public function copyFile()
757831 /** @var \Joomla\Component\Templates\Administrator\Model\TemplateModel $model */
758832 $ model = $ this ->getModel ();
759833
834+ // Access check.
835+ if (!$ this ->allowEdit ())
836+ {
837+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
838+
839+ return ;
840+ }
841+
760842 if (!preg_match ('/^[a-zA-Z0-9-_]+$/ ' , $ newName ))
761843 {
762844 $ this ->setMessage (Text::_ ('COM_TEMPLATES_INVALID_FILE_NAME ' ), 'error ' );
@@ -794,6 +876,14 @@ public function extractArchive()
794876 /** @var \Joomla\Component\Templates\Administrator\Model\TemplateModel $model */
795877 $ model = $ this ->getModel ();
796878
879+ // Access check.
880+ if (!$ this ->allowEdit ())
881+ {
882+ $ this ->app ->enqueueMessage (Text::_ ('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED ' ), 'error ' );
883+
884+ return ;
885+ }
886+
797887 if ($ model ->extractArchive ($ file ))
798888 {
799889 $ this ->setMessage (Text::_ ('COM_TEMPLATES_FILE_ARCHIVE_EXTRACT_SUCCESS ' ));
0 commit comments