Commit 9755cb5953e69fec2468bc5f2235b51838793fd0

Authored by Mihail
1 parent 07a132f4

fixed permissions (rules) in controllers

backend/controllers/CartController.php
... ... @@ -8,7 +8,6 @@ use common\models\CartBillsSearch;
8 8 use backend\components\base\BaseController;
9 9 use yii\web\NotFoundHttpException;
10 10 use yii\filters\VerbFilter;
11   -use yii\filters\AccessControl;
12 11  
13 12 /**
14 13 * CartController implements the CRUD actions for CartBills model.
... ... @@ -16,34 +15,7 @@ use yii\filters\AccessControl;
16 15 class CartController extends BaseController
17 16 {
18 17 public $layout = "/column";
19   - /**
20   - * @inheritdoc
21   - */
22   - public function behaviors()
23   - {
24   - return [
25   - 'access' => [
26   - 'class' => AccessControl::className(),
27   - 'rules' => [
28   - [
29   - 'actions' => ['login', 'error', 'download-photo','delete-image' ],
30   - 'allow' => true,
31   - ],
32   - [
33   - 'actions' => ['logout', 'index','create','update','view','delete',],
34   - 'allow' => true,
35   - 'roles' => ['@'],
36   - ],
37   - ],
38   - ],
39   - 'verbs' => [
40   - 'class' => VerbFilter::className(),
41   - 'actions' => [
42   - 'logout' => ['post'],
43   - ],
44   - ],
45   - ];
46   - }
  18 +
47 19 /**
48 20 * Lists all CartBills models.
49 21 * @return mixed
... ...
backend/controllers/CrossingUploadController.php
... ... @@ -8,10 +8,13 @@
8 8  
9 9 namespace backend\controllers;
10 10  
  11 +use backend\components\base\BaseActiveRecord;
11 12 use backend\components\base\BaseController;
12 13 use common\components\CustomArrayHelper;
13 14 use common\components\CustomVarDamp;
  15 +use yii\base\Model;
14 16 use yii\data\ArrayDataProvider;
  17 +use yii\db\ActiveRecord;
15 18 use yii\filters\VerbFilter;
16 19 use yii\filters\AccessControl;
17 20 use backend\models\UploadFileCrossingForm;
... ... @@ -82,7 +85,7 @@ class CrossingUploadController extends BaseController
82 85 //ะทะฐะฟัƒัะบะฐะตะผ ะฟะฐั€ัะธะฝะณ
83 86 $data = $model->readFile();
84 87 // ัะพั…ั€ะฐะฝัะตะผ ะฒ ะบะตัˆ ะพั‚ะฟะฐั€ัะตะฝะฝั‹ะต ะดะฐะฝั‹ะต
85   - $this->cacheHandler( true, $data, $model );
  88 + $this->cacheHandler( 1, $data, $model );
86 89 } else if (Yii::$app->getCache()->get('parser_data')) {
87 90 $data = json_decode(Yii::$app->getCache()->get('parser_data'), true);
88 91 }
... ... @@ -128,7 +131,7 @@ class CrossingUploadController extends BaseController
128 131 $arr = $model->toArray();
129 132  
130 133 // ะฟะพะปัƒั‡ะธะผ ะดะฐะฝะฝั‹ะต ะธะท ะบะตัˆะฐ
131   - $this->cacheHandler( false, $data, $configuration );
  134 + $this->cacheHandler( 0, $data, $configuration );
132 135  
133 136 // ัะพะพั‚ะฝะตัะตะผ ะพั‚ะฟะฐั€ัะตะฝะฝั‹ะต ะดะฐะฝะฝั‹ะต ั ัะพะพั‚ะฒะตั‚ัั‚ะฒะธะตะผ ะฟะพะปัƒั‡ะตะฝะฝั‹ะผ ะพั‚ ะฟะพะปัŒะทะพะฒะฐั‚ะตะปั
134 137 // ะดะปั ัั‚ะพะณะพ ะฟั€ะตะพะฑั€ะฐะทัƒะตะผ ะผะฐััะธะฒ ะพั‚ะฟะฐั€ัะตะฝะฝั‹ั… ะดะฐะฝะฝั‹ั… - ะฝะฐะทะฝะฐั‡ะธะผ ะบะปัŽั‡ะธ ัะพะณะปะฐัะฝะพ ัะพะพั‚ะฒะตั‚ัั‚ะฒะธัŽ
... ... @@ -138,16 +141,20 @@ class CrossingUploadController extends BaseController
138 141 $data = $this->convertDataByConfiguration( $data, $configuration );
139 142  
140 143 $crosses_model = new DetailsCrosses();
141   - $crosses_model->ManualInsertWithIgnore($data);
142 144  
143   - Yii::$app->session->setFlash('success', 'ะคะฐะนะป ะบั€ะพััะพะฒ ัƒัะฟะตัˆะฝะพ ะทะฐะณั€ัƒะถะตะฝ');
144   - // ะฒัะต ะฟั€ะพัˆะปะพ ัƒัะฟะตัˆะฝะพ - ะพั‡ะธั‰ะฐะตะผ ะบะตัˆ
145   - Yii::$app->getCache()->delete('parser_data');
146   - Yii::$app->getCache()->delete('parser_configuration');
  145 + if ( $this->validateModel( $crosses_model , $data ) && $crosses_model->ManualInsertWithIgnore( $data ) ) {
  146 +
  147 + Yii::$app->session->setFlash('success', 'ะคะฐะนะป ะบั€ะพััะพะฒ ัƒัะฟะตัˆะฝะพ ะทะฐะณั€ัƒะถะตะฝ');
  148 +
  149 + // ะพั‡ะธัั‚ะธะผ ะบะตัˆ
  150 + $this->cacheHandler( 2 );
  151 +
  152 + if (file_exists($configuration['file_path']))
  153 + unlink($configuration['file_path']);
  154 + return $this->render('index', ['model' => $configuration]);
  155 +
  156 + }
147 157  
148   - if (file_exists($configuration['file_path']))
149   - unlink($configuration['file_path']);
150   - return $this->render('index', ['model' => $configuration]);
151 158  
152 159 } else {
153 160 // ะฝะต ะฟั€ะพัˆะปะฐ ะฒะฐะปะธะดะฐั†ะธั ั„ะพั€ะผะฐ ะทะฐะณั€ัƒะทะบะธ ั„ะฐะนะปะพะฒ
... ... @@ -188,8 +195,8 @@ class CrossingUploadController extends BaseController
188 195 $options ['configuration'] = ["string" => ['ARTICLE', 'CROSS_ARTICLE'],];
189 196 }
190 197  
191   - foreach ($data as &$row) {
192   - $row = Yii::$app->converter->convertByConfiguration($row, $options);
  198 + foreach ( $data as &$row ) {
  199 + $row = Yii::$app->converter->convertByConfiguration( $row, $options );
193 200 }
194 201  
195 202 return $data;
... ... @@ -197,30 +204,47 @@ class CrossingUploadController extends BaseController
197 204 }
198 205  
199 206 /**
200   - * @param $mode - bool - true - put in cache, otherwise - fetch from cache
  207 + * @param $mode - int: 0 - fetch from cache, - 1 - put in cache, <2 - delete from cache
201 208 * @param $data - array
202 209 * @param $configuration - array
203 210 * @throws \ErrorException
204 211 */
205   - protected function cacheHandler( $mode, &$data, &$configuration ){
206   -
207   - if ( $mode ) {
208   -
209   - Yii::$app->getCache()->set('parser_data', json_encode($data), 1800);
210   - // ัะพั…ั€ะฐะฝัะตะผ ะฒ ะบะตัˆ ะผะพะดะตะปัŒ - ะฒ ะฝะตะน ะฝะฐัั‚ั€ะพะนะบะธ ะดะปั ะดะฐะปัŒะฝะตะนัˆะตะน ะพะฑั€ะฐะฑะพั‚ะบะธ ะดะฐะฝะฝั‹ั…
211   - Yii::$app->getCache()->set('parser_configuration', serialize($configuration), 1800);
  212 + protected function cacheHandler( $mode, &$data = [], &$configuration = [] ){
  213 + switch ( $mode ) {
  214 + case 0:
  215 + if (Yii::$app->getCache()->get('parser_data') && Yii::$app->getCache()->get('parser_configuration')) {
  216 + $data = json_decode(Yii::$app->getCache()->get('parser_data'), true);
  217 + $configuration = unserialize(Yii::$app->getCache()->get('parser_configuration'));
  218 + } else {
  219 + throw new \ErrorException('ะžัˆะธะฑะบะฐ ะบะตัˆะฐ');
  220 + }
  221 + break;
  222 +
  223 + case 1:
  224 + Yii::$app->getCache()->set('parser_data', json_encode($data), 1800);
  225 + // ัะพั…ั€ะฐะฝัะตะผ ะฒ ะบะตัˆ ะผะพะดะตะปัŒ - ะฒ ะฝะตะน ะฝะฐัั‚ั€ะพะนะบะธ ะดะปั ะดะฐะปัŒะฝะตะนัˆะตะน ะพะฑั€ะฐะฑะพั‚ะบะธ ะดะฐะฝะฝั‹ั…
  226 + Yii::$app->getCache()->set('parser_configuration', serialize($configuration), 1800);
  227 + break;
  228 +
  229 + default:
  230 + if( Yii::$app->getCache()->exists('parser_data') )
  231 + Yii::$app->getCache()->delete('parser_data');
  232 +
  233 + if( Yii::$app->getCache()->exists('parser_configuration') )
  234 + Yii::$app->getCache()->delete('parser_configuration');
  235 + }
212 236  
213   - } else {
  237 + }
214 238  
215   - if (Yii::$app->getCache()->get('parser_data') && Yii::$app->getCache()->get('parser_configuration')) {
216   - $data = json_decode(Yii::$app->getCache()->get('parser_data'), true);
217   - $configuration = unserialize(Yii::$app->getCache()->get('parser_configuration'));
218   - } else {
219   - throw new \ErrorException('ะžัˆะธะฑะบะฐ ะบะตัˆะฐ');
220   - }
  239 + protected function validateModel( BaseActiveRecord $model, array $data ){
221 240  
  241 + foreach ( $data as $row ) {
  242 + if ( !$model->validate( $row ) ) {
  243 + $model->throwStringErrorException( key( $data ) );
  244 + };
222 245 }
223 246  
  247 + return true;
224 248  
225 249 }
226 250 }
227 251 \ No newline at end of file
... ...
backend/controllers/DetailsDescriptionController.php
... ... @@ -11,7 +11,6 @@ use yii\data\ActiveDataProvider;
11 11 use yii\web\HttpException;
12 12 use yii\web\NotFoundHttpException;
13 13 use yii\filters\VerbFilter;
14   -use yii\filters\AccessControl;
15 14  
16 15 /**
17 16 * DetailsDescriptionController implements the CRUD actions for DetailsDescription model.
... ... @@ -20,30 +19,13 @@ class DetailsDescriptionController extends BaseController
20 19 {
21 20 public $layout = "/column";
22 21  
23   - /**
24   - * @inheritdoc
25   - */
26 22 public function behaviors()
27 23 {
28 24 return [
29   - 'access' => [
30   - 'class' => AccessControl::className(),
31   - 'rules' => [
32   - [
33   - 'actions' => ['login', 'error', 'download-photo','delete-image' ],
34   - 'allow' => true,
35   - ],
36   - [
37   - 'actions' => ['logout', 'index','create','update','view','delete',],
38   - 'allow' => true,
39   - 'roles' => ['@'],
40   - ],
41   - ],
42   - ],
43 25 'verbs' => [
44 26 'class' => VerbFilter::className(),
45 27 'actions' => [
46   - 'logout' => ['post'],
  28 + 'delete' => ['post'],
47 29 ],
48 30 ],
49 31 ];
... ...
backend/controllers/ParserController.php
... ... @@ -38,22 +38,17 @@ class ParserController extends BaseController
38 38 'class' => AccessControl::className(),
39 39 'rules' => [
40 40 [
41   - 'actions' => ['login', 'error', 'download-photo','delete-image' ],
42   - 'allow' => true,
43   - ],
44   - [
45   - 'actions' => ['logout', 'index','create','update','view','delete',],
46 41 'allow' => true,
47 42 'roles' => ['@'],
48 43 ],
49 44 ],
50 45 ],
51   - 'verbs' => [
52   - 'class' => VerbFilter::className(),
53   - 'actions' => [
54   - 'logout' => ['post'],
55   - ],
56   - ],
  46 +// 'verbs' => [
  47 +// 'class' => VerbFilter::className(),
  48 +// 'actions' => [
  49 +// 'logout' => ['post'],
  50 +// ],
  51 +// ],
57 52 ];
58 53 }
59 54  
... ...
backend/controllers/RgGrupController.php
... ... @@ -14,7 +14,6 @@ use common\components\CustomVarDamp;
14 14 use common\components\parsers\MailAttachmentsSaver;
15 15 use common\models\Margins;
16 16 use common\models\MarginsGroups;
17   -use yii\filters\VerbFilter;
18 17 use yii\filters\AccessControl;
19 18 use Yii;
20 19 use yii\web\UploadedFile;
... ... @@ -36,22 +35,17 @@ class RgGrupController extends BaseController
36 35 'class' => AccessControl::className(),
37 36 'rules' => [
38 37 [
39   - 'actions' => ['login', 'error', 'download-photo','delete-image' ],
40   - 'allow' => true,
41   - ],
42   - [
43   - 'actions' => ['logout', 'index','create','update','view','delete',],
44 38 'allow' => true,
45 39 'roles' => ['@'],
46 40 ],
47 41 ],
48 42 ],
49   - 'verbs' => [
50   - 'class' => VerbFilter::className(),
51   - 'actions' => [
52   - 'logout' => ['post'],
53   - ],
54   - ],
  43 +// 'verbs' => [
  44 +// 'class' => VerbFilter::className(),
  45 +// 'actions' => [
  46 +// 'logout' => ['post'],
  47 +// ],
  48 +// ],
55 49 ];
56 50 }
57 51  
... ...
backend/models/DetailsCrosses.php
... ... @@ -78,8 +78,16 @@ class DetailsCrosses extends \backend\components\base\BaseActiveRecord
78 78 $query = Yii::$app->db->createCommand()->batchInsert($table_name, $keys_arr, $current_batch_array)->sql;
79 79 // ะดะพะฑะฐะฒะธะผ ะบะปัŽั‡ะตะฒะพะต ัะปะพะฒะพ - ignore
80 80 $query = preg_replace('/INSERT/','INSERT IGNORE', $query);
81   - Yii::$app->db->createCommand($query)->execute();
  81 + $rows = Yii::$app->db->createCommand($query)->execute();
  82 +
  83 + // ะตัะปะธ ะฝะตั‚ ั€ะตะทัƒะปัŒั‚ะฐั‚ะฐ ะฒะตั€ะฝะตะผัั ั ะพัˆะธะฑะบะพะน
  84 + if ( $rows == 0 ) {
  85 + return false;
  86 + }
82 87  
83 88 }
  89 +
  90 + return true;
  91 +
84 92 }
85 93 }
... ...
tests/_support/_generated/UnitTesterActions.php
1   -<?php //[STAMP] 76e040407b5f5ec0a4bfcf45c4064e51
  1 +<?php //[STAMP] 6943f83782f0ac615ed36fefe0f4d3a8
2 2 namespace _generated;
3 3  
4 4 // This class was automatically generated by build task
... ...
tests/unit/BaseConverterTest.php
... ... @@ -21,18 +21,19 @@ class BaseConverterTest extends \Codeception\TestCase\Test
21 21 {
22 22 $this->converter = new Converter();
23 23  
24   - $this->configuration = ['configuration' =>
25   - ["encode" => 'encode',
26   - "string" => ['string1', 'string2' ],
27   - "float" => 'float',
28   - "integer" => ['integer1', 'integer2' ],
  24 + $this->configuration = ['hasKey' => true,
  25 + 'configuration' =>
  26 + ['encode' => 'encode',
  27 + 'string' => ['string1', 'string2' ],
  28 + 'float' => 'float',
  29 + 'integer' => ['integer1', 'integer2' ],
29 30 ]];
30 31  
31 32 $this->wrong_configuration = ['config' =>
32   - ["encode" => 'encode',
33   - "string" => 'string',
34   - "float" => 'float',
35   - "integer" => 'integer',
  33 + ['encode' => 'encode',
  34 + 'string' => 'string',
  35 + 'float' => 'float',
  36 + 'integer' => 'integer',
36 37 ]];
37 38  
38 39 $this->data_in = [
... ... @@ -49,7 +50,7 @@ class BaseConverterTest extends \Codeception\TestCase\Test
49 50  
50 51 public function testConvertByConfig(){
51 52  
52   - $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->configuration );
  53 + $this->data_out = $this->converter->convertByConfiguration( $this->data_in, $this->configuration );
53 54 $this->assertEquals( $this->data_out['encode'], iconv( 'windows-1251', 'UTF-8', 'test encode string' ), 'Encoding failed' );
54 55 $this->assertInternalType( 'float', $this->data_out['float'], 'Convert to float is failed' );
55 56  
... ... @@ -58,7 +59,7 @@ class BaseConverterTest extends \Codeception\TestCase\Test
58 59 public function testConvertToException(){
59 60  
60 61 $this->setExpectedException('\Exception');
61   - $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->wrong_configuration );
  62 + $this->data_out = $this->converter->convertByConfiguration( $this->data_in, $this->wrong_configuration );
62 63  
63 64 }
64 65  
... ...
tests/unit/CrossesParsingTest.php
... ... @@ -17,7 +17,7 @@ class CrossesParsingTest extends \Codeception\TestCase\Test
17 17 public function _before()
18 18 {
19 19 $this->options[ 'mode' ] = 'crosses';
20   - $this->options[ 'converter_conf' ] = [ 'configuration' => [ "string" => ['ARTICLE', 'CROSS_ARTICLE'], ] ];
  20 + $this->options[ 'converter_conf' ] = [ 'configuration' => [ "string" => ['ARTICLE', 'CROSS_ARTICLE'] ], 'hasKey' => 1 ];
21 21 $this->file_path = Yii::getAlias('@data_parser') . '\crosses\test1.csv';
22 22  
23 23 }
... ...