修改收集任务和分享的删除逻辑
删除→禁用 *已知缺陷,分享和收集详情可以被其他用户访问
This commit is contained in:
parent
6b568955a6
commit
63fef55f65
@ -46,7 +46,7 @@ class CollectionController extends Controller
|
|||||||
{
|
{
|
||||||
$searchModel = new CollectionSearch();
|
$searchModel = new CollectionSearch();
|
||||||
$dataProvider = $searchModel->search($this->request->queryParams);
|
$dataProvider = $searchModel->search($this->request->queryParams);
|
||||||
|
$dataProvider->query->andWhere(['!=', 'status', 0]);
|
||||||
return $this->render('index', [
|
return $this->render('index', [
|
||||||
'searchModel' => $searchModel,
|
'searchModel' => $searchModel,
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
@ -101,7 +101,18 @@ class CollectionController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function actionDelete($id)
|
public function actionDelete($id)
|
||||||
{
|
{
|
||||||
$this->findModel($id)->delete();
|
// 获取模型
|
||||||
|
$model = $this->findModel($id);
|
||||||
|
|
||||||
|
// 设置状态为禁用
|
||||||
|
$model->status = 0;
|
||||||
|
|
||||||
|
// 保存模型
|
||||||
|
if ($model->save()) {
|
||||||
|
Yii::$app->session->setFlash('success', 'Task delete successfully.');
|
||||||
|
} else {
|
||||||
|
Yii::$app->session->setFlash('error', 'Failed to delete task.');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->redirect(['index']);
|
return $this->redirect(['index']);
|
||||||
}
|
}
|
||||||
@ -137,8 +148,8 @@ class CollectionController extends Controller
|
|||||||
$secret = $receive_secret;
|
$secret = $receive_secret;
|
||||||
}
|
}
|
||||||
$model = CollectionTasks::findOne(['id' => $id]);
|
$model = CollectionTasks::findOne(['id' => $id]);
|
||||||
if ($model === null) {
|
if ($model === null | $model->status === 0) {
|
||||||
throw new NotFoundHttpException('请求的文件收集任务不存在');
|
throw new NotFoundHttpException('请求的文件收集任务已失效或不存在');
|
||||||
} elseif (!is_dir(Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $model->user_id . '/' . $model->folder_path)) {
|
} elseif (!is_dir(Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $model->user_id . '/' . $model->folder_path)) {
|
||||||
throw new NotFoundHttpException('收集任务的目标路径不存在');
|
throw new NotFoundHttpException('收集任务的目标路径不存在');
|
||||||
} elseif ($secret === null) {
|
} elseif ($secret === null) {
|
||||||
|
@ -43,6 +43,7 @@ class ShareController extends Controller
|
|||||||
{
|
{
|
||||||
$searchModel = new ShareSearch();
|
$searchModel = new ShareSearch();
|
||||||
$dataProvider = $searchModel->search($this->request->queryParams);
|
$dataProvider = $searchModel->search($this->request->queryParams);
|
||||||
|
$dataProvider->query->andWhere(['!=', 'status', 0]);
|
||||||
|
|
||||||
return $this->render('index', [
|
return $this->render('index', [
|
||||||
'searchModel' => $searchModel,
|
'searchModel' => $searchModel,
|
||||||
@ -138,7 +139,18 @@ class ShareController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function actionDelete($share_id)
|
public function actionDelete($share_id)
|
||||||
{
|
{
|
||||||
$this->findModel($share_id)->delete();
|
// 获取模型
|
||||||
|
$model = $this->findModel($share_id);
|
||||||
|
|
||||||
|
// 设置状态为禁用
|
||||||
|
$model->status = 0;
|
||||||
|
|
||||||
|
// 保存模型
|
||||||
|
if ($model->save()) {
|
||||||
|
Yii::$app->session->setFlash('success', 'Share delete successfully.');
|
||||||
|
} else {
|
||||||
|
Yii::$app->session->setFlash('error', 'Failed to delete share.');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->redirect(['index']);
|
return $this->redirect(['index']);
|
||||||
}
|
}
|
||||||
@ -164,7 +176,7 @@ class ShareController extends Controller
|
|||||||
$model = $this->findModel($share_id);
|
$model = $this->findModel($share_id);
|
||||||
//检查文件/文件夹是否存在
|
//检查文件/文件夹是否存在
|
||||||
$abp = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $model->sharer_id . '/' . $model->file_relative_path;
|
$abp = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $model->sharer_id . '/' . $model->file_relative_path;
|
||||||
if (!file_exists($abp)) {
|
if (!file_exists($abp) || $model->status == 0) {
|
||||||
throw new NotFoundHttpException('分享失效,文件或文件夹不存在');
|
throw new NotFoundHttpException('分享失效,文件或文件夹不存在');
|
||||||
}
|
}
|
||||||
if ($this->request->isPost) {
|
if ($this->request->isPost) {
|
||||||
|
@ -14,6 +14,7 @@ use yii\db\ActiveRecord;
|
|||||||
* @property string $folder_path 收集目标文件夹(相对路径)
|
* @property string $folder_path 收集目标文件夹(相对路径)
|
||||||
* @property string $created_at 收集任务创建时间
|
* @property string $created_at 收集任务创建时间
|
||||||
* @property string $secret 访问密钥
|
* @property string $secret 访问密钥
|
||||||
|
* @property int|null $status 收集任务是否启用
|
||||||
*
|
*
|
||||||
* @property CollectionUploaded[] $collectionUploadeds
|
* @property CollectionUploaded[] $collectionUploadeds
|
||||||
* @property User $user
|
* @property User $user
|
||||||
@ -38,7 +39,7 @@ class CollectionTasks extends ActiveRecord
|
|||||||
return [
|
return [
|
||||||
[['user_id', 'folder_path', 'secret'], 'required'],
|
[['user_id', 'folder_path', 'secret'], 'required'],
|
||||||
[['folder_path', 'secret'], 'required', 'on' => self::SCENARIO_CREATE],
|
[['folder_path', 'secret'], 'required', 'on' => self::SCENARIO_CREATE],
|
||||||
[['user_id'], 'integer'],
|
[['user_id', 'status'], 'integer'],
|
||||||
[['created_at'], 'safe'],
|
[['created_at'], 'safe'],
|
||||||
[['folder_path', 'secret'], 'string', 'max' => 255],
|
[['folder_path', 'secret'], 'string', 'max' => 255],
|
||||||
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
|
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
|
||||||
@ -56,6 +57,7 @@ class CollectionTasks extends ActiveRecord
|
|||||||
'folder_path' => '收集目标文件夹(相对路径)',
|
'folder_path' => '收集目标文件夹(相对路径)',
|
||||||
'created_at' => '任务创建时间',
|
'created_at' => '任务创建时间',
|
||||||
'secret' => '访问密钥',
|
'secret' => '访问密钥',
|
||||||
|
'status' => 'Status',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ use yii\db\ActiveRecord;
|
|||||||
* @property string $file_relative_path 文件的相对路径
|
* @property string $file_relative_path 文件的相对路径
|
||||||
* @property string $access_code 分享密钥
|
* @property string $access_code 分享密钥
|
||||||
* @property string $creation_date 分享创建日期
|
* @property string $creation_date 分享创建日期
|
||||||
|
* @property int|null $status 分享是否启用
|
||||||
*
|
*
|
||||||
* @property User $sharer
|
* @property User $sharer
|
||||||
*/
|
*/
|
||||||
@ -35,7 +36,7 @@ class Share extends ActiveRecord
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['file_relative_path', 'access_code'], 'required'],
|
[['file_relative_path', 'access_code'], 'required'],
|
||||||
[['sharer_id'], 'integer'],
|
[['sharer_id', 'status'], 'integer'],
|
||||||
[['creation_date'], 'safe'],
|
[['creation_date'], 'safe'],
|
||||||
[['file_relative_path'], 'string', 'max' => 255],
|
[['file_relative_path'], 'string', 'max' => 255],
|
||||||
[['access_code'], 'string', 'max' => 4],
|
[['access_code'], 'string', 'max' => 4],
|
||||||
@ -55,6 +56,7 @@ class Share extends ActiveRecord
|
|||||||
'file_relative_path' => '文件位置',
|
'file_relative_path' => '文件位置',
|
||||||
'access_code' => '访问密码',
|
'access_code' => '访问密码',
|
||||||
'creation_date' => '分享创建日期',
|
'creation_date' => '分享创建日期',
|
||||||
|
'status' => 'Status',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user