Skip to content

Commit

Permalink
Merge pull request #238 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
LinneyS authored Dec 11, 2018
2 parents fef5f21 + 7620422 commit 87b07ef
Show file tree
Hide file tree
Showing 27 changed files with 259 additions and 72 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## 2.1.3
## Added
- restricting access for groups
- goback from editor to shared folder by link

## Changed
- using notification methods

## 2.1.1
## Added
- Swedish translation
Expand Down
4 changes: 3 additions & 1 deletion appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public function __construct(array $urlParams = []) {
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener("OCA\Files::loadAdditionalScripts",
function() {
if (!empty($this->appConfig->GetDocumentServerUrl()) && $this->appConfig->SettingsAreSuccessful()) {
if (!empty($this->appConfig->GetDocumentServerUrl())
&& $this->appConfig->SettingsAreSuccessful()
&& $this->appConfig->isUserAllowedToUse()) {
Util::addScript("onlyoffice", "desktop");
Util::addScript("onlyoffice", "main");
Util::addStyle("onlyoffice", "main");
Expand Down
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>ONLYOFFICE connector enables you to edit Office documents within ONLYOFFICE from the familiar web interface. This will create a new Open in ONLYOFFICE action within the document library for Office documents. This allows multiple users to collaborate in real time and to save back those changes to your file storage.</description>
<licence>agpl</licence>
<author>Ascensio System SIA</author>
<version>2.1.1</version>
<version>2.1.3</version>
<namespace>Onlyoffice</namespace>
<types>
<filesystem/>
Expand All @@ -26,6 +26,6 @@
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-owncloud/master/screenshots/new.png</screenshot>
<screenshot>https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice-owncloud/master/screenshots/open.png</screenshot>
<dependencies>
<owncloud min-version="9.0" max-version="10.0" />
<owncloud min-version="10" max-version="10" />
</dependencies>
</info>
4 changes: 3 additions & 1 deletion controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ public function emptyfile($doc) {
* @param string $doc - verification token with the file identifier
* @param array $users - the list of the identifiers of the users
* @param string $key - the edited document identifier
* @param integer $status - the edited status
* @param string $url - the link to the edited document to be saved
* @param string $token - access token
*
* @return array
*
Expand Down Expand Up @@ -449,7 +451,7 @@ public function track($doc, $users, $key, $status, $url, $token) {
/**
* Getting file by identifier
*
* @param integer $userId - user identifier
* @param string $userId - user identifier
* @param integer $fileId - file identifier
*
* @return array
Expand Down
82 changes: 72 additions & 10 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public function __construct($AppName,
public function create($name, $dir) {
$this->logger->debug("Create: " . $name, array("app" => $this->appName));

if (!$this->config->isUserAllowedToUse()) {
return ["error" => $this->trans->t("Not permitted")];
}

$userId = $this->userSession->getUser()->getUID();
$userFolder = $this->root->getUserFolder($userId);
$folder = $userFolder->get($dir);
Expand Down Expand Up @@ -228,6 +232,14 @@ public function create($name, $dir) {
return $result;
}

/**
* Get template path
*
* @param string $lang - language
* @param string $ext - file extension
*
* @return string
*/
private function getTemplatePath($lang, $ext) {
return dirname(__DIR__) . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . $lang . DIRECTORY_SEPARATOR . "new" . $ext;
}
Expand All @@ -244,6 +256,10 @@ private function getTemplatePath($lang, $ext) {
public function convert($fileId) {
$this->logger->debug("Convert: " . $fileId, array("app" => $this->appName));

if (!$this->config->isUserAllowedToUse()) {
return ["error" => $this->trans->t("Not permitted")];
}

$userId = $this->userSession->getUser()->getUID();
list ($file, $error) = $this->getFile($userId, $fileId);

Expand Down Expand Up @@ -342,11 +358,15 @@ public function index($fileId, $token = NULL) {
return new RedirectResponse($redirectUrl);
}

if (empty($token) && !$this->config->isUserAllowedToUse()) {
return $this->renderError($this->trans->t("Not permitted"));
}

$documentServerUrl = $this->config->GetDocumentServerUrl();

if (empty($documentServerUrl)) {
$this->logger->error("documentServerUrl is empty", array("app" => $this->appName));
return ["error" => $this->trans->t("ONLYOFFICE app is not configured. Please contact admin")];
return $this->renderError($this->trans->t("ONLYOFFICE app is not configured. Please contact admin"));
}

$params = [
Expand Down Expand Up @@ -374,6 +394,7 @@ public function index($fileId, $token = NULL) {
/**
* Print public editor section
*
* @param integer $fileId - file identifier
* @param string $token - access token
*
* @return TemplateResponse
Expand All @@ -391,6 +412,7 @@ public function PublicPage($fileId, $token) {
*
* @param integer $fileId - file identifier
* @param string $token - access token
* @param bool $desktop - desktop label
*
* @return array
*
Expand All @@ -399,13 +421,17 @@ public function PublicPage($fileId, $token) {
*/
public function config($fileId, $token = NULL, $desktop = false) {

if (empty($token) && !$this->config->isUserAllowedToUse()) {
return ["error" => $this->trans->t("Not permitted")];
}

$user = $this->userSession->getUser();
$userId = NULL;
if (!empty($user)) {
$userId = $user->getUID();
}

list ($file, $error) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $token);
list ($file, $error, $share) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $token);

if (isset($error)) {
$this->logger->error("Config: " . $fileId . " " . $error, array("app" => $this->appName));
Expand Down Expand Up @@ -443,7 +469,7 @@ public function config($fileId, $token = NULL, $desktop = false) {

$canEdit = isset($format["edit"]) && $format["edit"];
$editable = $file->isUpdateable()
&& (empty($token) || ($this->getShare($token)[0]->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE);
&& (empty($token) || ($share->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE);
if ($editable && $canEdit) {
$ownerId = NULL;
$owner = $file->getOwner();
Expand All @@ -468,21 +494,40 @@ public function config($fileId, $token = NULL, $desktop = false) {
"id" => $userId,
"name" => $user->getDisplayName()
];
}

$folderLink = NULL;

if (!empty($token)) {
$node = $share->getNode();
if ($node instanceof Folder) {
$sharedFolder = $node;
$folderPath = $sharedFolder->getRelativePath($file->getParent()->getPath());
if (!empty($folderPath)) {
$linkAttr = [
"path" => $folderPath,
"scrollto" => $file->getName(),
"token" => $token
];
$folderLink = $this->urlGenerator->linkToRouteAbsolute("files_sharing.sharecontroller.showShare", $linkAttr);
}
}
} else if (!empty($userId)) {
$userFolder = $this->root->getUserFolder($userId);
$folderPath = $userFolder->getRelativePath($file->getParent()->getPath());
$linkAttr = NULL;
if (!empty($folderPath)) {
$linkAttr = [
"dir" => $folderPath,
"scrollto" => $file->getName()
];
$folderLink = $this->urlGenerator->linkToRouteAbsolute("files.view.index", $linkAttr);

$params["editorConfig"]["customization"]["goback"] = [
"url" => $folderLink
];
}
}

if ($folderLink !== NULL) {
$params["editorConfig"]["customization"]["goback"] = [
"url" => $folderLink
];

if (!$desktop) {
if ($this->config->GetSameTab()) {
Expand All @@ -506,7 +551,7 @@ public function config($fileId, $token = NULL, $desktop = false) {
/**
* Getting file by identifier
*
* @param integer $userId - user identifier
* @param string $userId - user identifier
* @param integer $fileId - file identifier
*
* @return array
Expand Down Expand Up @@ -566,7 +611,7 @@ private function getFileByToken($fileId, $token) {
$file = $node;
}

return [$file, NULL];
return [$file, NULL, $share];
}

/**
Expand Down Expand Up @@ -681,4 +726,21 @@ private function setCustomization($params) {

return $params;
}

/**
* Print error page
*
* @param string $error - error message
* @param string $hint - error hint
*
* @return TemplateResponse
*/
private function renderError($error, $hint = "") {
return new TemplateResponse("", "error", array(
"errors" => array(array(
"error" => $error,
"hint" => $hint
))
), "error");
}
}
16 changes: 11 additions & 5 deletions controller/settingscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public function index() {
"currentServer" => $this->urlGenerator->getAbsoluteURL("/"),
"formats" => $this->config->FormatsSetting(),
"sameTab" => $this->config->GetSameTab(),
"encryption" => $this->checkEncryptionModule()
"encryption" => $this->checkEncryptionModule(),
"limitGroups" => $this->config->GetLimitGroups()
];
return new TemplateResponse($this->appName, "settings", $data, "blank");
}
Expand All @@ -133,7 +134,10 @@ public function index() {
* @param string $documentserverInternal - document service address available from ownCloud
* @param string $storageUrl - ownCloud address available from document server
* @param string $secret - secret key for signature
* @param string $defFormats - formats array with default action
* @param array $defFormats - formats array with default action
* @param array $editFormats - editable formats array
* @param bool $sameTab - open in same tab
* @param array $limitGroups - list of groups
*
* @return array
*/
Expand All @@ -143,7 +147,8 @@ public function SaveSettings($documentserver,
$secret,
$defFormats,
$editFormats,
$sameTab
$sameTab,
$limitGroups
) {
$this->config->SetDocumentServerUrl($documentserver);
$this->config->SetDocumentServerInternalUrl($documentserverInternal);
Expand All @@ -161,6 +166,7 @@ public function SaveSettings($documentserver,
$this->config->SetDefaultFormats($defFormats);
$this->config->SetEditableFormats($editFormats);
$this->config->SetSameTab($sameTab);
$this->config->SetLimitGroups($limitGroups);

if ($this->checkEncryptionModule()) {
$this->logger->info("SaveSettings when encryption is enabled", array("app" => $this->appName));
Expand Down Expand Up @@ -195,8 +201,6 @@ public function GetSettings() {
/**
* Checking document service location
*
* @param string $documentServer - document service address
*
* @return string
*/
private function checkDocServiceUrl() {
Expand Down Expand Up @@ -280,6 +284,8 @@ private function checkDocServiceUrl() {

/**
* Checking encryption enabled
*
* @return bool
*/
private function checkEncryptionModule() {
if (!App::isEnabled("encryption")) {
Expand Down
4 changes: 0 additions & 4 deletions css/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@
position: absolute;
vertical-align: top;
}
#iframeEditor.error {
color: red;
}

.AscDesktopEditor #header {
display: none;
}
.AscDesktopEditor #content-wrapper {
padding-top: 0;
}

4 changes: 3 additions & 1 deletion js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

OCA.Onlyoffice.InitEditor = function () {
var displayError = function (error) {
$("#iframeEditor").text(error).addClass("error");
OC.Notification.show(error, {
type: "error"
});
};

var fileId = $("#iframeEditor").data("id");
Expand Down
30 changes: 14 additions & 16 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,19 @@
if (winEditor) {
winEditor.close();
}
var row = OC.Notification.show(response.error);
setTimeout(function () {
OC.Notification.hide(row);
}, 3000);
OC.Notification.show(response.error, {
type: "error",
timeout: 3
});
return;
}

fileList.add(response, { animate: true });
OCA.Onlyoffice.OpenEditor(response.id, winEditor);

var row = OC.Notification.show(t(OCA.Onlyoffice.AppName, "File created"));
setTimeout(function () {
OC.Notification.hide(row);
}, 3000);
OC.Notification.show(t(OCA.Onlyoffice.AppName, "File created"), {
timeout: 3
});
}
);
};
Expand Down Expand Up @@ -107,21 +106,20 @@
},
function onSuccess(response) {
if (response.error) {
var row = OC.Notification.show(response.error);
setTimeout(function () {
OC.Notification.hide(row);
}, 3000);
OC.Notification.show(response.error, {
type: "error",
timeout: 3
});
return;
}

if (response.parentId == fileList.dirInfo.id) {
fileList.add(response, { animate: true });
}

var row = OC.Notification.show(t(OCA.Onlyoffice.AppName, "File created"));
setTimeout(function () {
OC.Notification.hide(row);
}, 3000);
OC.Notification.show(t(OCA.Onlyoffice.AppName, "File created"), {
timeout: 3
});
});
};

Expand Down
Loading

0 comments on commit 87b07ef

Please sign in to comment.