Skip to content

Commit

Permalink
Merge pull request #1127 from proditis/master
Browse files Browse the repository at this point in the history
Handle challenge fileuploads better
  • Loading branch information
proditis authored Mar 19, 2024
2 parents 48bd016 + b7a191d commit ba66d2f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
19 changes: 17 additions & 2 deletions backend/modules/gameplay/controllers/ChallengeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ public function actionCreate()
try
{
if($model->file)
$model->file->saveAs('uploads/'.$model->id);
{
if(trim($model->filename)==='')
{
$model->filename=$model->id;
$model->updateAttributes(['filename'=>$model->id]);
}
$model->file->saveAs(Yii::getAlias(Yii::$app->sys->challenge_home).'/'.$model->filename);
}
Yii::$app->session->addFlash('success', Yii::t('app','Challenge [{name}] created',['name'=>Html::encode($model->name)]));
Yii::$app->session->addFlash('warning', Yii::t('app','Don\'t forget to create a question for the challenge.'));
}
Expand Down Expand Up @@ -131,7 +138,15 @@ public function actionUpdate($id)
{
$model->file=UploadedFile::getInstance($model, 'file');
if($model->file !== null)
$model->file->saveAs('uploads/'.$model->id);
{
if(trim($model->filename)==='')
{
$model->filename=$model->id;
$model->updateAttributes(['filename'=>$model->id]);
}
$model->file->saveAs(Yii::getAlias(Yii::$app->sys->challenge_home).'/'.$model->filename);
}
Yii::$app->session->addFlash('success', Yii::t('app','Challenge [{name}] updated',['name'=>Html::encode($model->name)]));
return $this->redirect(['view', 'id' => $model->id]);
}

Expand Down
3 changes: 2 additions & 1 deletion backend/modules/gameplay/models/Challenge.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @property string $description
* @property string $player_type
* @property string $filename The filename that will be provided to participants
* @property string $file The filename that will be provided to participants
* @property object $file The file upload handler
* @property boolean $active Is challenge active?
* @property boolean $timer Keep timer for solving?
* @property boolean $public Is challenge public?
Expand Down Expand Up @@ -44,6 +44,7 @@ public function rules()
[['active','timer','public'], 'boolean'],
[['file'], 'file'],
[['name', 'category', 'difficulty', 'filename'], 'string', 'max' => 255],
[['filename'], 'trim'],
[['name'], 'unique'],
[['player_type'],'default', 'value'=>'offense'],
['player_type', 'in', 'range' => ['offense', 'defense','both']],
Expand Down
7 changes: 6 additions & 1 deletion backend/modules/settings/models/ConfigureForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ConfigureForm extends Model
public $twitter_hashtags;
public $registrations_start;
public $registrations_end;
public $challenge_home;
public $challenge_home='@webroot/uploads';
public $challenge_root='@web/uploads';
public $offense_registered_tag;
public $defense_registered_tag;
public $offense_domain;
Expand Down Expand Up @@ -94,6 +95,7 @@ class ConfigureForm extends Model
'registrations_start',
'registrations_end',
'challenge_home',
'challenge_root',
'offense_registered_tag',
'defense_registered_tag',
'vpngw',
Expand Down Expand Up @@ -220,6 +222,8 @@ public function rules()
'target_days_new',
'target_days_updated',
], 'required'],
['challenge_home','default','value'=>'@web/uploads'],
['challenge_root','default','value'=>'/uploads/'],
[['dn_countryName'],'default','value'=>\Yii::$app->sys->dn_countryName],
[['dn_stateOrProvinceName'],'default','value'=>\Yii::$app->sys->dn_stateOrProvinceName],
[['dn_localityName'],'default','value'=>\Yii::$app->sys->dn_localityName],
Expand Down Expand Up @@ -276,6 +280,7 @@ public function attributeLabels()
'defense_domain' => 'Defense domain',
'moderator_domain' => 'Moderator domain',
'challenge_home' => 'Challenge home',
'challenge_root' => 'Challenge root',
'approved_avatar' => 'Approved Avatar',
'offense_vether_network' => 'Offense vether network',
'offense_vether_netmask' => 'Offense vether netmask',
Expand Down
7 changes: 5 additions & 2 deletions backend/modules/settings/views/sysconfig/configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@
<hr/>
<h4>Targets and Challenges properties</h4>
<div class="row form-group">
<div class="col-sm-6"><?= $form->field($model, 'target_days_new')->textInput()->hint('How many days are targets considered new?') ?></div>
<div class="col-sm-6"><?= $form->field($model, 'target_days_updated')->textInput()->hint('How many days are targets considered updated?') ?></div>
<div class="col-sm-3"><?= $form->field($model, 'target_days_new')->textInput()->hint('How many days are targets considered new?') ?></div>
<div class="col-sm-3"><?= $form->field($model, 'target_days_updated')->textInput()->hint('How many days are targets considered updated?') ?></div>
<div class="col-sm-3"><?= $form->field($model, 'challenge_home')->textInput()->hint('Web accessible path for downloading challenge files?') ?></div>
<div class="col-sm-3"><?= $form->field($model, 'challenge_root')->textInput()->hint('Folder that challenge files will be uploaded to?') ?></div>

</div>

<hr/>
Expand Down
3 changes: 2 additions & 1 deletion docs/Sysconfig-Keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
* `offense_scenario` A scenario displayed to the users once they have signed into the frontend.
* `spins_per_day` Limit allowed restarts per day per player
* `online_timeout` Timeout in seconds that a user is no longer considered online on the platform
* `challenge_home` Web accessible folder that the challenges can be downloaded from. (default: `uploads/`)
* `challenge_home` Full path to folder that the challenges will be uploaded to. (default: `@web/uploads/`)
* `challenge_root` Web accessible folder that the challenges can be downloaded from. (default: `/uploads/`)
* `offense_registered_tag` PF tag used for registered offense users
* `defense_registered_tag` PF tag used for registered defense users
* `footer_logos`: HTML code to display logos for the event on the footer of the page. (PENDING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="well">
<h3><b><?=$model->name.' (ID#'.$model->id.')'?> <?php if($model->completed):?><i class="fas fa-check-double"></i> <?=Twitter::widget(['message'=>\Yii::t('app','Hey check this out, I completed the challenge ').Html::encode($model->name)]);?><?php else:?><?=Twitter::widget(['message'=>\Yii::t('app','I currently grinding the challenge ').Html::encode($model->name)]);?><?php endif;?></b></h3>
<h4><?=Html::encode($model->category);?> / <?=Html::encode($model->difficulty)?> / <?=Html::encode(number_format($model->points));?>pts</h4>
<?=trim($model->filename) !== '' ? '<h4><b>'.\Yii::t('app','Challenge file:').'</b> '.Html::a($model->filename, ['/uploads/'.$model->filename], ['data-pjax'=>"0"]).'</h4>' : ''?>
<?=trim($model->filename) !== '' ? '<h4><b>'.\Yii::t('app','Challenge file:').'</b> '.Html::a($model->filename, [Yii::getAlias(\Yii::$app->sys->challenge_root).'/'.$model->filename], ['data-pjax'=>"0"]).'</h4>' : ''?>
<?php if($model->completed):?>
<div class="col-xl-4 col-sm-6"><?=VoteWidget::widget(['model'=>$solver,'id'=>$model->id,'action'=>['/game/default/rate-solver','id'=>$model->id]]);?></div>
<?php endif;?>
Expand Down

0 comments on commit ba66d2f

Please sign in to comment.