Attachments nearly complete

This commit is contained in:
Matthew Ross 2020-04-27 13:38:21 -04:00
parent dd08499be9
commit 672c1d031d
7 changed files with 63 additions and 9 deletions

View File

@ -4,8 +4,7 @@ use RedBeanPHP\R;
class Attachments extends BaseController { class Attachments extends BaseController {
public function getAttachment($request, $response, $args) { public function getAttachment($request, $response, $args) {
$status = $this->secureRoute($request, $response, $status = $this->secureRoute($request, $response, SecurityLevel::USER);
SecurityLevel::USER);
if ($status !== 200) { if ($status !== 200) {
return $this->jsonResponse($response, $status); return $this->jsonResponse($response, $status);
} }
@ -33,14 +32,19 @@ class Attachments extends BaseController {
} }
public function addAttachment($request, $response) { public function addAttachment($request, $response) {
$status = $this->secureRoute($request, $response, $status = $this->secureRoute($request, $response, SecurityLevel::USER);
SecurityLevel::USER);
if ($status !== 200) { if ($status !== 200) {
return $this->jsonResponse($response, $status); return $this->jsonResponse($response, $status);
} }
if (!file_exists('uploads/')) {
mkdir('uploads', 0777, true);
}
$body = $request->getBody();
$attachment = R::dispense('attachment'); $attachment = R::dispense('attachment');
if (!BeanLoader::LoadAttachment($attachment, $request->getBody())) {
if (!BeanLoader::LoadAttachment($attachment, $body)) {
$attachment->task_id = 0; $attachment->task_id = 0;
} }
@ -58,6 +62,11 @@ class Attachments extends BaseController {
return $this->jsonResponse($response, 403); return $this->jsonResponse($response, 403);
} }
$body = json_decode($body);
$attachment->diskfilename = sha1($body->filename);
file_put_contents('uploads/' . $attachment->diskfilename, $body->data);
R::store($attachment); R::store($attachment);
$actor = R::load('user', Auth::GetUserId($request)); $actor = R::load('user', Auth::GetUserId($request));
@ -73,8 +82,7 @@ class Attachments extends BaseController {
} }
public function removeAttachment($request, $response, $args) { public function removeAttachment($request, $response, $args) {
$status = $this->secureRoute($request, $response, $status = $this->secureRoute($request, $response, SecurityLevel::USER);
SecurityLevel::USER);
if ($status !== 200) { if ($status !== 200) {
return $this->jsonResponse($response, $status); return $this->jsonResponse($response, $status);
} }
@ -110,7 +118,9 @@ class Attachments extends BaseController {
} }
$before = $attachment; $before = $attachment;
$attachment->delete(); R::trash($attachment);
unlink('uploads/' . $before->diskfilename);
$this->dbLogger->logChange($actor->id, $this->dbLogger->logChange($actor->id,
$actor->username .' removed attachment ' . $before->name, $actor->username .' removed attachment ' . $before->name,

View File

@ -11,6 +11,7 @@ import { ApiInterceptor } from './app.api-http';
import { LoginComponent } from './login/login.component'; import { LoginComponent } from './login/login.component';
import { BoardModule } from './board/board.module'; import { BoardModule } from './board/board.module';
import { FileModule } from './files/file-viewer.module';
import { DashboardModule } from './dashboard/dashboard.module'; import { DashboardModule } from './dashboard/dashboard.module';
import { SettingsModule } from './settings/settings.module'; import { SettingsModule } from './settings/settings.module';
import { SharedModule } from './shared/shared.module'; import { SharedModule } from './shared/shared.module';
@ -21,6 +22,7 @@ import { SharedModule } from './shared/shared.module';
FormsModule, FormsModule,
HttpClientModule, HttpClientModule,
BoardModule, BoardModule,
FileModule,
DashboardModule, DashboardModule,
DragDropModule, DragDropModule,
SettingsModule, SettingsModule,

View File

@ -1,6 +1,7 @@
import { Routes } from '@angular/router'; import { Routes } from '@angular/router';
import { BoardDisplayComponent } from './board/board.component'; import { BoardDisplayComponent } from './board/board.component';
import { FileViewerComponent } from './files/file-viewer.component';
import { LoginComponent } from './login/login.component'; import { LoginComponent } from './login/login.component';
import { SettingsComponent } from './settings/settings.component'; import { SettingsComponent } from './settings/settings.component';
import { DashboardComponent } from './dashboard/dashboard.component'; import { DashboardComponent } from './dashboard/dashboard.component';
@ -30,6 +31,10 @@ export const ROUTES: Routes = [
path: 'dashboard', path: 'dashboard',
component: DashboardComponent, component: DashboardComponent,
canActivate: [ AuthGuard ] canActivate: [ AuthGuard ]
},
{
path: 'files/:hash',
component: FileViewerComponent,
} }
]; ];

View File

@ -1,11 +1,13 @@
export class Attachment { export class Attachment {
constructor(public id: number = 0, constructor(public id: number = 0,
public filename: string = '', public filename: string = '',
public diskfilename: string = '',
public name: string = '', public name: string = '',
public type: string = '', public type: string = '',
public user_id: number = 0, // tslint:disable-line public user_id: number = 0, // tslint:disable-line
public timestamp: number = Date.now(), public timestamp: number = Date.now(),
public task_id: number = 0) { // tslint:disable-line public task_id: number = 0,
public data: any = null) { // tslint:disable-line
} }
} }

View File

@ -44,6 +44,7 @@ export class Task {
attachmentArray.forEach((attachment: any) => { attachmentArray.forEach((attachment: any) => {
this.attachments.push(new Attachment(+attachment.id, this.attachments.push(new Attachment(+attachment.id,
attachment.filename, attachment.filename,
attachment.diskfilename,
attachment.name, attachment.name,
attachment.type, attachment.type,
+attachment.user_id, +attachment.user_id,

View File

@ -9,6 +9,7 @@
"dashboard": "Dashboard", "dashboard": "Dashboard",
"boards": "Boards", "boards": "Boards",
"files": "File Viewer",
"settings": "Settings", "settings": "Settings",
"logout": "Logout", "logout": "Logout",
@ -155,6 +156,8 @@
"boards_confirmRemoveTask": "Confirm Task Removal", "boards_confirmRemoveTask": "Confirm Task Removal",
"boards_confirmWarning": "Removing a task cannot be undone.", "boards_confirmWarning": "Removing a task cannot be undone.",
"boards_confirmContinue": "Continue?", "boards_confirmContinue": "Continue?",
"boards_confirmRemoveAttachment": "Confirm Attachment Removal",
"boards_confirmWarningAttachment": "Removing an attachment cannot be undone.",
"boards_confirmRemoveComment": "Confirm Comment Removal", "boards_confirmRemoveComment": "Confirm Comment Removal",
"boards_confirmWarningComment": "Removing a comment cannot be undone.", "boards_confirmWarningComment": "Removing a comment cannot be undone.",
@ -201,6 +204,10 @@
"boards_taskRemoveAttachment": "Remove Attachment", "boards_taskRemoveAttachment": "Remove Attachment",
"boards_taskNoFileError": "Select a file before uploading.", "boards_taskNoFileError": "Select a file before uploading.",
"boards_taskUpload": "Upload", "boards_taskUpload": "Upload",
"boards_taskUploadedBy": "Uploaded by",
"boards_taskUploadedOn": "on",
"boards_taskView": "View",
"boards_taskDownload": "Download",
"boards_task": "Task", "boards_task": "Task",
"boards_taskComplete": "Complete", "boards_taskComplete": "Complete",

View File

@ -377,6 +377,33 @@
} }
} }
.list-group {
border: 1px solid $color-border;
border-radius: 3px;
.list-group-item {
padding: 7px;
&:nth-of-type(even) {
background-color: $color-table-row;
}
.detail {
margin-left: 7px;
}
.pull-right {
color: $color-primary;
float: right;
margin-top: -2.8rem;
i {
margin-left: 7px;
}
}
}
}
.comment { .comment {
@include shadow-low; @include shadow-low;