Skip to content

Commit

Permalink
implemented a user interface for file visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
reinvanoyen committed Feb 18, 2022
1 parent cd4b815 commit 46089e2
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class UpdateMediaFilesTableWithVisibility extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('media_files', function (Blueprint $table) {
$table->string('visibility')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('media_files', function (Blueprint $table) {
$table->dropColumn('visibility');
});
}
}
2 changes: 1 addition & 1 deletion public/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/app.js": "/app.js?id=3ca58e40c17ad35d4e05",
"/app.js": "/app.js?id=e8e7013e0523ca23fc8a",
"/app.css": "/app.css?id=238f6bff04f375ef62cd"
}
2 changes: 1 addition & 1 deletion resources/js/actions/view-media-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class ViewMediaDirectory extends React.Component {

handleChangeFileProperty(property, value, fileId) {

let propertiesMap = ['Description', 'Copyright'];
let propertiesMap = ['Visibility', 'Description', 'Copyright'];

if (propertiesMap.includes(property)) {
let apiCall = api.media['updateFile'+property];
Expand Down
4 changes: 4 additions & 0 deletions resources/js/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ api.media.updateFileCopyright = (copyright, file) => {
return axios.post('cmf/api/media/update-file-copyright', {copyright, file});
};

api.media.updateFileVisibility = (visibility, file) => {
return axios.post('cmf/api/media/update-file-visibility', {visibility, file});
};

api.media.updateFilesDescription = (description, fileIds) => {
return axios.post('cmf/api/media/update-files-description', {description, files: JSON.stringify(fileIds)});
};
Expand Down
1 change: 1 addition & 0 deletions resources/js/core/ui/file-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default class FileView extends React.Component {
['Copyright', this.props.file.copyright, true],
['Size', file.filesize(this.props.file.size)],
['Mimetype', this.props.file.mime_type],
['Visibility', this.props.file.visibility, true],
['Disk', this.props.file.disk],
['Conversions disk', this.props.file.conversions_disk],
]}
Expand Down
18 changes: 18 additions & 0 deletions src/Http/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,24 @@ public function updateFileCopyright(Request $request)
return new MediaFileResource($mediaFile);
}

/**
* @param Request $request
* @return MediaFileResource
*/
public function updateFileVisibility(Request $request)
{
$mediaFile = MediaFile::findOrFail($request->input('file'));
$visibility = $request->input('visibility');

$disk = Storage::disk($mediaFile->disk);
$disk->setVisibility($mediaFile->filename, $visibility);

$mediaFile->visibility = $visibility;
$mediaFile->save();

return new MediaFileResource($mediaFile);
}

/**
* @param Request $request
* @return bool
Expand Down
1 change: 1 addition & 0 deletions src/Http/Resources/MediaFileResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function toArray($request)
'filename' => $this->filename,
'size' => $this->size,
'disk' => $this->disk,
'visibility' => $this->vis,
'conversions_disk' => $this->conversions_disk,
'mime_type' => $this->mime_type,
'label' => $this->label,
Expand Down
16 changes: 16 additions & 0 deletions src/Models/MediaFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ public function delete()
$storage->delete($filename);
}

/**
* @return string
*/
public function getVisAttribute(): string
{
if ($this->visibility) {
return $this->visibility;
}

$storage = Storage::disk($this->disk);
$this->visibility = $storage->getVisibility($this->filename);
$this->save();

return $this->visibility;
}

/**
* @return bool
*/
Expand Down
1 change: 1 addition & 0 deletions src/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
Route::post('media/label-file', [MediaController::class, 'labelFile']);
Route::post('media/update-file-description', [MediaController::class, 'updateFileDescription']);
Route::post('media/update-file-copyright', [MediaController::class, 'updateFileCopyright']);
Route::post('media/update-file-visibility', [MediaController::class, 'updateFileVisibility']);
Route::post('media/update-files-description', [MediaController::class, 'updateFilesDescription']);
Route::post('media/update-files-copyright', [MediaController::class, 'updateFilesCopyright']);
Route::post('media/delete-file', [MediaController::class, 'deleteFile']);
Expand Down

0 comments on commit 46089e2

Please sign in to comment.