Esempio n. 1
0
 public function update()
 {
     define('STDIN', fopen("php://stdin", "r"));
     Artisan::call("paperwork:update", ['--quiet' => true]);
     Cache::forget('paperwork.commitInfo');
     return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, array());
 }
Esempio n. 2
0
 protected static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->{$model->getKeyName()} = (string) PaperworkHelpers::generateUuid('PaperworkModel');
     });
 }
Esempio n. 3
0
 public function setConfiguration()
 {
     File::put(storage_path() . "/config/paperwork.json", json_encode(Input::all()));
     if (File::exists(storage_path() . "/config/paperwork.json")) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, array());
     } else {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, Input::all());
     }
 }
 public function show($id = null)
 {
     if (is_null($id)) {
         return index();
     } else {
         $shortcuts = DB::table('notebooks')->join('shortcuts', function ($join) {
             $join->on('notebooks.id', '=', 'shortcuts.notebook_id')->where('shortcuts.user_id', '=', Auth::user()->id);
         })->select('notebooks.id', 'notebooks.parent_id', 'notebooks.type', 'notebooks.title', 'shortcuts.id', 'shortcuts.sortkey')->where('notebooks.id', '=', $id)->first();
         if (is_null($shortcuts)) {
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
         } else {
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $shortcuts);
         }
     }
 }
 public function index()
 {
     $notes = DB::table('notes')->join('note_user', function ($join) {
         $join->on('notes.id', '=', 'note_user.note_id')->where('note_user.user_id', '=', Auth::user()->id);
     })->join('notebooks', function ($join) {
         $join->on('notes.notebook_id', '=', 'notebooks.id');
     })->join('versions', function ($join) {
         $join->on('notes.version_id', '=', 'versions.id');
     })->select('notes.id', 'versions.title', DB::raw('DATE(notes.updated_at) as updated_at'))->whereNull('notes.deleted_at')->whereNull('notebooks.deleted_at')->get();
     $indexed = array_reduce($notes, function (&$array, $item) {
         if (!isset($array[$item->updated_at])) {
             $array[$item->updated_at] = array();
         }
         $array[$item->updated_at][] = $item;
         return $array;
     }, array());
     return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $indexed);
 }
 public function show($notebookId, $noteId, $versionId)
 {
     $note = Note::with(array('users' => function ($query) {
         $query->where('note_user.user_id', '=', Auth::user()->id);
     }, 'notebook' => function ($query) use(&$notebookId) {
         $query->where('id', $notebookId > 0 ? '=' : '>', $notebookId > 0 ? $notebookId : '0');
     }, 'version' => function ($query) {
     }))->where('id', '=', $noteId)->whereNull('deleted_at')->first();
     $currentVersion = $note->version()->first();
     if (is_null($currentVersion)) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
     }
     while (!is_null($currentVersion)) {
         if ($currentVersion->id == $versionId || $versionId == '0') {
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $currentVersion);
         }
         $currentVersion = $currentVersion->previous()->first();
     }
     return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
 }
Esempio n. 7
0
 /**
  * Register action.
  *
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function register()
 {
     $validator = $this->getRegistrationValidator();
     if ($validator->passes()) {
         //only allow users to register who actually have a valid ldap account
         if ($this->isLdap) {
             $creds = $this->getLoginCredentials();
             $creds['isRegister'] = true;
             if (!Auth::validate($creds)) {
                 return Redirect::back()->withInput()->withErrors(["password" => [Lang::get('messages.invalid_credentials')]]);
             }
         }
         //if we are using ldap and auto registration, the user will have been created in the Auth::attemp call above
         //thus, we need to just load the user using eloquent and not create a new one.
         if ($this->isLdap && Config::get('ldap.autoRegister')) {
             $user = User::query()->where('username', Input::get('username'))->first();
         } else {
             $user = $this->userRegistrator->registerUser(Input::except('_token', 'password_confirmation', 'ui_language'), Input::get('ui_language'));
         }
         if ($user && !Input::get('frominstaller')) {
             Auth::login($user);
             Session::put('ui_language', Input::get('ui_language'));
             return Redirect::route("/");
         } else {
             if ($user) {
                 return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, array());
             }
         }
         if (!Input::get('frominstaller')) {
             return Redirect::back()->withErrors(["password" => [Lang::get('messages.account_creation_failed')]]);
         } else {
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, ["password" => [Lang::get('messages.account_creation_failed')]]);
         }
     } else {
         if (!Input::get('frominstaller')) {
             return Redirect::back()->withInput()->withErrors($validator);
         } else {
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, $validator->failed());
         }
     }
 }
 public function share($notebookId, $toUserId, $toUMASK)
 {
     $toUserIds = explode(PaperworkHelpers::MULTIPLE_REST_RESOURCE_DELIMITER, $toUserId);
     $toUMASKs = explode(PaperworkHelpers::MULTIPLE_REST_RESOURCE_DELIMITER, $toUMASK);
     if (count($toUserIds) != count($toUMASKs)) {
         //as much toUsers as toUmasks, if not raise an Error.
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('error_id' => $noteId));
     }
     $responses = array();
     $status = PaperworkHelpers::STATUS_SUCCESS;
     for ($i = 0; $i < count($toUserIds); $i++) {
         //adding a loop to share with multiple users
         $tmp = $this->shareNotebook($notebookId, $toUserIds[$i], $toUMASK[$i]);
         if (is_null($tmp)) {
             $status = PaperworkHelpers::STATUS_ERROR;
             $responses[] = array('error_id' => $notebookId);
         } else {
             $responses[] = $tmp;
         }
     }
     return PaperworkHelpers::apiResponse($status, $responses);
 }
 public function testHasUiLanguage()
 {
     $this->assertEquals(true, PaperworkHelpers::hasUiLanguage("en"));
 }
 public function nest($tagId, $parentTagId)
 {
     $tag = Tag::find($tagId);
     //cannot nest a tag in itself.
     if (is_null($tag) || $tag->user_id != Auth::user()->id || $tagId == $parentTagId) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
     }
     $parentTag = Tag::find($parentTagId);
     //if trying to nest in an unexisting tag, then tag is unnested.
     if (is_null($parentTag)) {
         $tag->parent_id = NULL;
         $tag->save();
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $tagId);
     }
     if ($parentTag->user_id != Auth::user()->id) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
     }
     //cannot nest a tag with children, cannot nest into a tag with parents
     if (count($tag->children()->get()) > 0 || count($parentTag->parents()->get()) > 0) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
     }
     $tag->parents()->associate($parentTag);
     $tag->save();
     return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $tagId);
 }
Esempio n. 11
0
     Route::any("/settings", ["as" => "user/settings", "uses" => "UserController@settings"]);
     Route::any("/help/{topic?}", ["as" => "user/help", "uses" => "UserController@help"]);
     Route::any("/logout", ["as" => "user/logout", "uses" => "UserController@logout"]);
     Route::any("/settings/export", ["as" => "user/settings/export", "uses" => "UserController@export"]);
     Route::any("/settings/import", ["as" => "user/settings/import", "uses" => "UserController@import"]);
     Route::get('/', ["as" => "/", "uses" => "LibraryController@show"]);
     //Administrators
     Route::group(['prefix' => 'admin', 'before' => ['admin']], function () {
         Route::get('/', ['as' => 'admin/console', 'uses' => 'AdminController@showConsole']);
     });
 });
 Route::get('/templates/{angularTemplate}', function ($angularTemplate) {
     return View::make('templates/' . $angularTemplate);
 });
 Route::group(array('prefix' => 'api/v1', 'before' => 'auth'), function () {
     App::setLocale(PaperworkHelpers::getUiLanguageFromSession());
     // Route::any('notebook/{num?}', 'ApiNotebooksController@index')->where('num','([0-9]*)');
     Route::resource('notebooks', 'ApiNotebooksController');
     Route::get('/notebooks/{notebookId}/share/{toUserId}/{toUMASK}', 'ApiNotebooksController@share');
     Route::resource('tags', 'ApiTagsController');
     Route::resource('notebooks.notes', 'ApiNotesController');
     // I really don't know whether that's a great way to solve this...
     Route::get('/notebooks/{notebookId}/notes/{noteId}/move/{toNotebookId}', 'ApiNotesController@move');
     Route::get('/notebooks/{notebookId}/notes/{noteId}/tag/{toTagId}', 'ApiNotesController@tagNote');
     Route::get('/notebooks/{notebookId}/notes/{noteId}/share/{toUserId}/{toUMASK}', 'ApiNotesController@share');
     Route::resource('notebooks.notes.versions', 'ApiVersionsController');
     Route::resource('notebooks.notes.versions.attachments', 'ApiAttachmentsController');
     Route::get('/notebooks/{notebookId}/notes/{noteId}/versions/{versionId}/attachments/{attachmentId}/raw', 'ApiAttachmentsController@raw');
     Route::resource('shortcuts', 'ApiShortcutsController');
     Route::get('/tags/{tagId}/{parentTagId}', 'ApiTagsController@nest');
     Route::resource('tags', 'ApiTagsController');
 public function delete()
 {
     return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, array());
 }
 public function raw($notebookId, $noteId, $versionId, $attachmentId)
 {
     $note = self::getNote($notebookId, $noteId, $versionId);
     $tmp = $note->version()->first();
     $version = null;
     if (is_null($tmp)) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
     }
     while (!is_null($tmp)) {
         if ($tmp->id == $versionId || $versionId == 0) {
             $version = $tmp;
             break;
         }
         $tmp = $tmp->previous()->first();
     }
     $attachment = $version->attachments()->where('attachments.id', '=', $attachmentId)->whereNull('attachments.deleted_at')->first();
     // $version->attachments()->detach($attachment);
     if (is_null($attachment)) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
     }
     $destinationFolder = Config::get('paperwork.attachmentsDirectory') . '/' . $attachment->id;
     $headers = array('Content-Type' => $attachment->mimetype, 'Content-Transfer-Encoding' => 'binary', 'Content-Disposition' => 'inline; filename="' . $attachment->filename . '"', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => $attachment->filesize);
     // $headers are not being set correctly and I don't really know why. Workaround:
     header('Content-Type: ' . $attachment->mimetype);
     return Response::make(readfile($destinationFolder . '/' . $attachment->filename), 200, $headers);
 }
Esempio n. 14
0
 public function destroy($tagId)
 {
     $tag = Tag::find($tagId);
     if (is_null($tag) || $tag->user_id != Auth::user()->id) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
     }
     $tag->delete();
     return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $tagId);
 }
<div class="error-reporting">
    <?php 
list($lastCommitOnInstall, $upstreamLatest, $lastCommitTimestamp, $upstreamTimestamp) = PaperworkHelpers::getHashes();
?>
        <div class="alert alert-warning" role="alert">
    @if(empty($lastCommitOnInstall))
            <p>[[Lang::get('messages.error_version_check')]]</p>
    @elseif($lastCommitOnInstall === $upstreamLatest)
            <p>[[Lang::get('messages.found_bug')]]</p>
    @elseif(strtotime($lastCommitTimestamp) > strtotime($upstreamTimestamp))
            <p>[[Lang::get('messages.found_bug_newer_commit_installed')]]
    @else
            <p>[[Lang::get('messages.new_version_available')]]
    @endif
            <p>[[Lang::get('messages.dblclick_dismiss')]]
        </div>
</div>
 public function show($translation)
 {
     return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, Lang::get($translation));
 }
Esempio n. 17
0
 public function __construct(UserRegistrator $userRegistrator)
 {
     $this->userRegistrator = $userRegistrator;
     $this->isLdap = PaperworkHelpers::isLdap();
 }
 public function updateCollection($collectionId)
 {
     $idArray = [];
     $validator = $this->getNewCollectionValidator();
     if ($validator->passes()) {
         $updateCollection = Input::json();
         $collection = User::find(Auth::user()->id)->notebooks()->wherePivot('umask', '>', PaperworkHelpers::UMASK_READONLY)->where('notebooks.id', '=', $collectionId)->whereNull('notebooks.deleted_at')->first();
         if (is_null($collection)) {
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array());
         }
         $collection->title = $updateCollection->get('title');
         $collection->save();
         $children = User::find(Auth::user()->id)->notebooks()->wherePivot('umask', '>', PaperworkHelpers::UMASK_READONLY)->where('notebooks.parent_id', '=', $collectionId)->whereNull('notebooks.deleted_at')->get()->toArray();
         $newChildren = $updateCollection->get('notebooks');
         foreach ($children as $child) {
             $idArray[] = $child["id"];
         }
         $addedChildren = array_diff($newChildren, $idArray);
         if (count($addedChildren) > 0) {
             foreach ($addedChildren as $addedChild) {
                 $addedChild = User::find(Auth::user()->id)->notebooks()->wherePivot('umask', '>', PaperworkHelpers::UMASK_READONLY)->where('notebooks.id', '=', $addedChild)->whereNull('notebooks.deleted_at')->first();
                 $addedChild->parent_id = $collectionId;
                 $addedChild->save();
             }
         }
         $removedChildren = array_diff($idArray, $newChildren);
         if (count($removedChildren) > 0) {
             foreach ($removedChildren as $removedChild) {
                 $removedChild = User::find(Auth::user()->id)->notebooks()->wherePivot('umask', '>', PaperworkHelpers::UMASK_READONLY)->where('notebooks.id', '=', $removedChild)->whereNull('notebooks.deleted_at')->first();
                 $removedChild->parent_id = null;
                 $removedChild->save();
             }
         }
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $collection);
     } else {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, $validator->getMessageBag()->toArray());
     }
 }