Commit 07dfbbc9 authored by Matthieu Le Corre's avatar Matthieu Le Corre

WIP: implement RO Session

parent 1cdd4790
{
"processors": ["stylelint-processor-html"],
"extends": "stylelint-config-standard",
"rules": {
'no-empty-source': true
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -27,6 +27,10 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IRequest;
use OCA\whiteboard\Service\CollaborationEngine ;
use OCP\Files\Folder;
use OCP\Files\File;
use OCP\Files\ForbiddenException;
use OCP\Files\FileInfo;
class CollaborationController extends Controller {
......@@ -34,7 +38,7 @@ class CollaborationController extends Controller {
* @NoAdminRequired
*
**/
public function __construct(string $AppName, IRequest $request, CollaborationEngine $engine, $userId) {
public function __construct(string $AppName, IRequest $request, CollaborationEngine $engine, Folder $userFolder, $userId) {
parent::__construct($AppName, $request);
$this->engine = $engine ;
......@@ -44,6 +48,15 @@ class CollaborationController extends Controller {
$this->engine->setRessourceId($request->getParam('id')) ;
/** @var File $file */
$file = $userFolder->getById($request->getParam('id'));
$this->engine->setUserWriteAccess($file[0]->isUpdateable());
$this->sessionInfo = [
"ROSession" => ! $file[0]->isUpdateable()
] ;
}
/**
......@@ -51,7 +64,8 @@ class CollaborationController extends Controller {
*
**/
public function startSession() {
return new DataResponse($this->engine->startSession(),Http::STATUS_NO_CONTENT) ;
return new DataResponse($this->sessionInfo) ;
//return new DataResponse($this->engine->startSession(),Http::STATUS_NO_CONTENT) ;
}
/**
......@@ -86,7 +100,11 @@ class CollaborationController extends Controller {
*
**/
public function addStep(string $type, string $step) {
return new DataResponse($this->engine->addStep($type,$step)) ;
try {
return new DataResponse($this->engine->addStep($type,$step)) ;
} catch (ForbiddenException $ex) {
return new DataResponse($ex.message,Http::STATUS_FORBIDDEN) ;
}
}
/**
......
......@@ -27,12 +27,15 @@ use OCA\whiteboard\Db\StepMapper ;
use OCA\whiteboard\Db\User ;
use OCA\whiteboard\Db\UserMapper ;
use OCP\Files\ForbiddenException;
class CollaborationEngine {
private $StepMapper ;
private $UserMapper ;
private $AppName ;
private $userId ;
private $userWriteAccess ;
private $ressourceId ;
public function __construct(StepMapper $StepMapper, UserMapper $UserMapper) {
......@@ -54,12 +57,17 @@ class CollaborationEngine {
$this->ressourceId = $ressourceId ;
}
//DONE
public function setUserWriteAccess(string $userWriteAccess) {
$this->userWriteAccess = $userWriteAccess ;
}
// DONE
public function startSession() {
// for now handle by the controller
// nothing to setup with DB engine
}
//DONE
// DONE
public function addUser() {
$usr = $this->UserMapper->find($this->userId,$this->AppName,$this->ressourceId) ;
......@@ -74,11 +82,11 @@ class CollaborationEngine {
return $this->UserMapper->insert($Nuser);
} else {
$this->updateLastSeen($this->userId,$this->ressourceId) ;
return "already there" ;
return $usr ;
} ;
}
//DONE
// DONE
public function removeUser() {
$usr = $this->UserMapper->find($this->userId,$this->AppName,$this->ressourceId) ;
$cnt = count($this->UserMapper->findAll($this->AppName,$this->ressourceId)) ;
......@@ -99,17 +107,21 @@ class CollaborationEngine {
public function addStep(string $type, string $datas) {
$this->updateLastSeen($this->userId,$this->ressourceId) ;
$Nstep = new Step() ;
$Nstep->setAppId($this->AppName) ;
$Nstep->setUserId($this->userId) ;
$Nstep->setStepId(time()) ;
$Nstep->setFileId($this->ressourceId) ;
$Nstep->setStepForwarded($this->userId) ;
$Nstep->setStepType($type) ;
$Nstep->setStepData($datas) ;
return $this->StepMapper->insert($Nstep);
if ($this->setUserWriteAccess) {
$Nstep = new Step() ;
$Nstep->setAppId($this->AppName) ;
$Nstep->setUserId($this->userId) ;
$Nstep->setStepId(time()) ;
$Nstep->setFileId($this->ressourceId) ;
$Nstep->setStepForwarded($this->userId) ;
$Nstep->setStepType($type) ;
$Nstep->setStepData($datas) ;
return $this->StepMapper->insert($Nstep);
} else {
throw new ForbiddenException ;
}
}
// DONE
......
This diff is collapsed.
......@@ -21,8 +21,8 @@
<template>
<Content :id="appContent" :app-name="appName">
<button class="icon-close" @click="close" />
<button class="icon-save" @click="save" />
<button class="icon-menu-sidebar" @click="sidebar" />
<button v-if="!ROSession" class="icon-save" @click="save" />
<button v-if="!ROSession" class="icon-menu-sidebar" @click="sidebar" />
<ul v-if="userList.length > 1" class="AvatarList">
<li v-for="user in userList"
:key="userList.indexOf(user)"
......@@ -33,6 +33,9 @@
menu-position="right" />
</li>
</ul>
<div v-if="ROSession" class="ro">
You don't have write access to this ressource, your modifications won't be forwarded and won't be saved
</div>
<AppContent :id="appEditor">
Loading {{ appName }} ...
</AppContent>
......@@ -65,6 +68,7 @@ export default {
data: function() {
return {
userList: this.$parent.userList,
ROSession: this.$parent.ROSession,
}
},
......@@ -105,36 +109,45 @@ export default {
</script>
<style scoped>
button {
position: relative;
float:right ;
float: right;
top: 0;
width: 30px;
height: 30px;
opacity: .5;
opacity: 0.5;
z-index: inherit;
border-width: 0px ;
border-width: 0;
}
button:hover {
opacity: 1;
opacity: 1;
}
.AvatarList {
position: relative;
float: right;
z-index: inherit;
padding-right: 10px;
margin-top: 2px ;
display: flex ;
position: relative;
float: right;
z-index: inherit;
padding-right: 10px;
margin-top: 2px;
display: flex;
}
.AvatarList li {
margin-left: 2px ;
margin-left: 2px;
}
.offline {
opacity: .4 ;
opacity: 0.4;
}
.ro {
position: relative;
float: right;
z-index: inherit;
padding-right: 10px;
margin-top: 5px;
display: flex;
color: red;
}
</style>
......@@ -38,8 +38,16 @@ export default {
this.filename = filename
this.context = context
this.init().then(function(data) {
this.init().then(function(sessionInfo) {
self.sessionInfo = sessionInfo.data
console.debug('sessionInfo', sessionInfo.data)
self.addUser()
.then(function(userType) {
console.debug('User :', userType.data)
})
// because we may arrive in an allready running session
// get all steps from last save
......
......@@ -45,6 +45,7 @@ export default {
this.NewFileMenu.APP_MIME = APP_MIME
this.userList = []
this.sessionInfo = []
OC.Plugins.register('OCA.Files.NewFileMenu', this.NewFileMenu)
this.registerFileActions()
......@@ -73,6 +74,7 @@ export default {
this.vm = new Vue({
data: {
userList: this.userList,
ROSession: this.sessionInfo.ROSession,
},
render: h => h(
PrototypeView,
......@@ -165,6 +167,8 @@ export default {
this.CE = collaborationEngine
this.CE.start(this.APP_NAME, filename, context)
this.sessionInfo = this.CE.sessionInfo
// subscribtion to event bus
// local changes => send to Engine
subscribe(this.APP_NAME + '::editorAddStep', this.EDS = (data) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment