diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php index 56a8ccfe79..ea38e1dc1b 100644 --- a/app/Http/Controllers/AttachmentController.php +++ b/app/Http/Controllers/AttachmentController.php @@ -5,7 +5,12 @@ namespace FireflyIII\Http\Controllers; use Crypt; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; +use FireflyIII\Http\Requests\AttachmentFormRequest; use FireflyIII\Models\Attachment; +use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; +use Input; +use Preferences; +use Session; use View; /** @@ -66,8 +71,40 @@ class AttachmentController extends Controller } else { abort(404); } + } + /** + * @param AttachmentFormRequest $request + * @param AttachmentRepositoryInterface $repository + * @param Attachment $attachment + * + * @return \Illuminate\Http\RedirectResponse + */ + public function update(AttachmentFormRequest $request, AttachmentRepositoryInterface $repository, Attachment $attachment) + { + + $attachmentData = [ + 'title' => $request->input('title'), + 'description' => $request->input('description'), + 'notes' => $request->input('notes'), + ]; + + $repository->update($attachment, $attachmentData); + + Session::flash('success', 'Attachment "' . $attachment->filename . '" updated.'); + Preferences::mark(); + + if (intval(Input::get('return_to_edit')) === 1) { + // set value so edit routine will not overwrite URL: + Session::put('accounts.edit.fromUpdate', true); + + return redirect(route('attachment.edit', [$attachment->id]))->withInput(['return_to_edit' => 1]); + } + + // redirect to previous URL. + return redirect(Session::get('accounts.edit.url')); + } } \ No newline at end of file diff --git a/app/Http/Requests/AttachmentFormRequest.php b/app/Http/Requests/AttachmentFormRequest.php new file mode 100644 index 0000000000..50a6665591 --- /dev/null +++ b/app/Http/Requests/AttachmentFormRequest.php @@ -0,0 +1,36 @@ + 'between:1,255', + 'description' => 'between:1,65536', + 'notes' => 'between:1,65536', + ]; + } +} diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index 4384abdc17..87c28524a1 100644 --- a/app/Models/Attachment.php +++ b/app/Models/Attachment.php @@ -2,6 +2,7 @@ namespace FireflyIII\Models; +use Crypt; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -9,20 +10,20 @@ use Illuminate\Database\Eloquent\SoftDeletes; * Class Attachment * * @package FireflyIII\Models - * @property integer $id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $deleted_at - * @property integer $attachable_id - * @property string $attachable_type - * @property integer $user_id - * @property string $md5 - * @property string $filename - * @property string $mime - * @property integer $size - * @property boolean $uploaded - * @property-read \ $attachable - * @property-read \FireflyIII\User $user + * @property integer $id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $deleted_at + * @property integer $attachable_id + * @property string $attachable_type + * @property integer $user_id + * @property string $md5 + * @property string $filename + * @property string $mime + * @property integer $size + * @property boolean $uploaded + * @property-read \ $attachable + * @property-read \FireflyIII\User $user * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereId($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereCreatedAt($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereUpdatedAt($value) @@ -35,12 +36,18 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereMime($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereSize($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereUploaded($value) + * @property string $title + * @property string $description + * @property string $notes + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereTitle($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereDescription($value) + * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Attachment whereNotes($value) */ class Attachment extends Model { use SoftDeletes; - protected $fillable = ['attachable_id', 'attachable_type', 'user_id', 'md5', 'filename', 'mime', 'size', 'uploaded']; + protected $fillable = ['attachable_id', 'attachable_type', 'user_id', 'md5', 'filename', 'mime', 'title', 'notes', 'description', 'size', 'uploaded']; /** * Get all of the owning imageable models. @@ -59,4 +66,125 @@ class Attachment extends Model return $this->belongsTo('FireflyIII\User'); } + + /** + * @codeCoverageIgnore + * + * @param $value + * + * @return null|string + */ + public function getFilenameAttribute($value) + { + if (is_null($value)) { + return null; + } + + return Crypt::decrypt($value); + } + + /** + * @param string $value + */ + public function setFilenameAttribute($value) + { + $this->attributes['filename'] = Crypt::encrypt($value); + } + + /** + * @codeCoverageIgnore + * + * @param $value + * + * @return null|string + */ + public function getMimeAttribute($value) + { + if (is_null($value)) { + return null; + } + + return Crypt::decrypt($value); + } + + /** + * @param string $value + */ + public function setMimeAttribute($value) + { + $this->attributes['mime'] = Crypt::encrypt($value); + } + + /** + * @codeCoverageIgnore + * + * @param $value + * + * @return null|string + */ + public function getTitleAttribute($value) + { + if (is_null($value)) { + return null; + } + + return Crypt::decrypt($value); + } + + /** + * @param string $value + */ + public function setTitleAttribute($value) + { + $this->attributes['title'] = Crypt::encrypt($value); + } + + /** + * @codeCoverageIgnore + * + * @param $value + * + * @return null|string + */ + public function getDescriptionAttribute($value) + { + if (is_null($value)) { + return null; + } + + return Crypt::decrypt($value); + } + + /** + * @param string $value + */ + public function setDescriptionAttribute($value) + { + $this->attributes['description'] = Crypt::encrypt($value); + } + + /** + * @codeCoverageIgnore + * + * @param $value + * + * @return null|string + */ + public function getNotesAttribute($value) + { + if (is_null($value)) { + return null; + } + + return Crypt::decrypt($value); + } + + /** + * @param string $value + */ + public function setNotesAttribute($value) + { + $this->attributes['notes'] = Crypt::encrypt($value); + } + } \ No newline at end of file diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index a08a908fde..45e2d5bb62 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -88,6 +88,7 @@ class FireflyServiceProvider extends ServiceProvider $this->app->bind('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface', 'FireflyIII\Repositories\PiggyBank\PiggyBankRepository'); $this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository'); $this->app->bind('FireflyIII\Repositories\Tag\TagRepositoryInterface', 'FireflyIII\Repositories\Tag\TagRepository'); + $this->app->bind('FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface', 'FireflyIII\Repositories\Attachment\AttachmentRepository'); $this->app->bind('FireflyIII\Support\Search\SearchInterface', 'FireflyIII\Support\Search\Search'); // CSV import diff --git a/app/Repositories/Attachment/AttachmentRepository.php b/app/Repositories/Attachment/AttachmentRepository.php new file mode 100644 index 0000000000..2e1b579845 --- /dev/null +++ b/app/Repositories/Attachment/AttachmentRepository.php @@ -0,0 +1,32 @@ +title = $data['title']; + $attachment->description = $data['description']; + $attachment->notes = $data['notes']; + $attachment->save(); + + return $attachment; + + } +} \ No newline at end of file diff --git a/app/Repositories/Attachment/AttachmentRepositoryInterface.php b/app/Repositories/Attachment/AttachmentRepositoryInterface.php new file mode 100644 index 0000000000..3b6c55186a --- /dev/null +++ b/app/Repositories/Attachment/AttachmentRepositoryInterface.php @@ -0,0 +1,22 @@ +string('attachable_type'); $table->integer('user_id')->unsigned(); $table->string('md5', 32); - $table->string('filename'); - $table->string('title')->nullable(); + $table->text('filename'); + $table->text('title')->nullable(); $table->text('description')->nullable(); $table->text('notes')->nullable(); - - $table->string('mime'); + $table->text('mime'); $table->integer('size')->unsigned(); $table->tinyInteger('uploaded', false, true)->default(0); @@ -37,6 +36,8 @@ class ChangesForV3410 extends Migration ); } + + /** * Reverse the migrations. * diff --git a/resources/twig/attachments/edit.twig b/resources/twig/attachments/edit.twig index 9aaa0a84d1..600f6b4e3a 100644 --- a/resources/twig/attachments/edit.twig +++ b/resources/twig/attachments/edit.twig @@ -31,9 +31,9 @@

{{ 'optionalFields'|_ }}

- {{ ExpandedForm.text('title') }} - {{ ExpandedForm.textarea('description') }} - {{ ExpandedForm.textarea('notes') }} + {{ ExpandedForm.text('title', attachment.title) }} + {{ ExpandedForm.textarea('description', attachment.description) }} + {{ ExpandedForm.textarea('notes', attachment.notes) }}
diff --git a/resources/twig/transactions/show.twig b/resources/twig/transactions/show.twig index 420e96e447..095fa53220 100644 --- a/resources/twig/transactions/show.twig +++ b/resources/twig/transactions/show.twig @@ -93,8 +93,18 @@ - {{ att.filename }} + + {% if att.title %} + {{ att.title }} + {% else %} + {{ att.filename }} + {% endif %} + ({{ att.size|filesize }}) + {% if att.description %} +
+ {{ att.description }} + {% endif %} {% endfor %}