Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,71 @@ private function get_user() {
return \core_user::get_user($this->userid);
}

private function get_watermark_text() {
global $DB;
return $DB->get_field('collabora_document', 'watermark_text', ['id' => $this->docrecord->id]);
}

private function get_hide_print() {
return false;
}

private function get_hide_save() {
return false;
}

private function get_hide_export() {
return false;
}

private function get_enable_owner_termination() {
global $DB;
return $DB->get_field('collabora_document', 'enable_owner_termination', ['id' => $this->docrecord->id]);
}

private function get_disable_print() {
global $DB;
return $DB->get_field('collabora_document', 'disable_print', ['id' => $this->docrecord->id]);
}

private function get_disable_export() {
global $DB;
return $DB->get_field('collabora_document', 'disable_export', ['id' => $this->docrecord->id]);
}

private function get_disable_copy() {
global $DB;
return $DB->get_field('collabora_document', 'disable_copy', ['id' => $this->docrecord->id]);
}

private function get_enable_insert_remote_image() {
global $DB;
return $DB->get_field('collabora_document', 'enable_insert_remote_image', ['id' => $this->docrecord->id]);
}

// If set to 'true', the user-list on the status bar will be hidden.
// If set to 'mobile' | 'tablet' | 'desktop', it will be hidden on the
// specified device(s) only (multiples values can be delimited by comma,
// e.g. 'mobile,tablet').
private function get_hide_user_list() {
return 'false';
}

private function get_disable_change_tracking_record() {
global $DB;
return $DB->get_field('collabora_document', 'disable_change_tracking_record', ['id' => $this->docrecord->id]);
}

private function get_disable_change_tracking_show() {
global $DB;
return $DB->get_field('collabora_document', 'disable_change_tracking_show', ['id' => $this->docrecord->id]);
}

private function get_hide_change_tracking_controls() {
global $DB;
return $DB->get_field('collabora_document', 'hide_change_tracking_controls', ['id' => $this->docrecord->id]);
}

/**
* Handle getfile requests.
*/
Expand Down Expand Up @@ -234,7 +299,21 @@ private function handle_checkfileinfo() {
'UserCanWrite' => !$this->is_readonly(),
'UserCanNotWriteRelative' => true,
'LastModifiedTime' => date('c', $file->get_timemodified()),
'WatermarkText' => $this->get_watermark_text(),
'HidePrintOption' => $this->get_hide_print(),
'HideSaveOption' => $this->get_hide_save(),
'HideExportOption' => $this->get_hide_export(),
'EnableOwnerTermination' => $this->get_enable_owner_termination(),
'DisablePrint' => $this->get_disable_print(),
'DisableExport' => $this->get_disable_export(),
'DisableCopy' => $this->get_disable_copy(),
'EnableInsertRemoteImage' => $this->get_enable_insert_remote_image(),
'HideUserList' => $this->get_hide_user_list(),
'DisableChangeTrackingRecord' => $this->get_disable_change_tracking_record(),
'DisableChangeTrackingShow' => $this->get_disable_change_tracking_show(),
'HideChangeTrackingControls' => $this->get_hide_change_tracking_controls(),
];

die(json_encode($ret));
}
}
189 changes: 177 additions & 12 deletions classes/collabora.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,8 @@ public function process_lock_unlock() {
if (!$this->can_lock_unlock()) {
return;
}
$lock = optional_param('lock', null, PARAM_INT);
if ($lock !== $this->groupid) {
$lock = null;
}
$unlock = optional_param('unlock', null, PARAM_INT);
if ($unlock !== $this->groupid) {
$unlock = null;
}
if ($lock === null && $unlock === null) {
return;
}
require_sesskey();
$locked = ($lock !== null) ? 1 : 0;
$locked = optional_param('locked', null, PARAM_INT) ? 1 : 0;
$this->document->locked = $locked;
$DB->set_field('collabora_document', 'locked', $locked, ['id' => $this->document->id]);
if ($locked) {
Expand Down Expand Up @@ -365,6 +354,182 @@ public function get_lock_icon() {
return $OUTPUT->render_from_template('mod_collabora/lockicon', $data);
}

public function get_settings_panel($cmid) {
global $PAGE, $OUTPUT, $DB;
$canupdate = $this->can_lock_unlock();
$islocked = $this->is_locked();
$url = null;
if ($canupdate) {
$params = ['sesskey' => sesskey()];
if ($islocked) {
$params['unlock'] = $this->groupid;
} else {
$params['lock'] = $this->groupid;
}

$url = new \moodle_url($PAGE->url);
}

$hideuserslist = $DB->get_field('collabora_document', 'hide_user_list', ['id' => $this->document->id]);
$labelstyle = '';

$data = (object)[
'canupdate' => $this->can_lock_unlock(),
'islocked' => $islocked,
'url' => $PAGE->url,
'id' => $cmid,
'sesskey' => sesskey(),
'fieldsets' => [
[
'title' => get_string('docsetting_security_title', 'mod_collabora'),
'fields' => [
[
'name' => 'locked',
'type' => 'checkbox',
'checked' => $DB->get_field('collabora_document', 'locked', ['id' => $this->document->id]) ? 'checked' : '',
'value' => '1',
'label' => get_string('docsetting_locked_label', 'mod_collabora'),
'labelstyle' => $labelstyle,
'tip' => get_string('docsetting_locked_tip', 'mod_collabora'),
'sub' => get_string('docsetting_default_no', 'mod_collabora'),
],
[
'name' => 'disableprint',
'type' => 'checkbox',
'checked' => !$DB->get_field('collabora_document', 'disable_print', ['id' => $this->document->id]) ? 'checked' : '',
'value' => 'true',
'label' => get_string('docsetting_disableprint_label', 'mod_collabora'),
'labelstyle' => $labelstyle,
'tip' => get_string('docsetting_disableprint_tip', 'mod_collabora'),
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
],
[
'name' => 'disableexport',
'type' => 'checkbox',
'checked' => !$DB->get_field('collabora_document', 'disable_export', ['id' => $this->document->id]) ? 'checked' : '',
'value' => 'true',
'label' => get_string('docsetting_disableexport_label', 'mod_collabora'),
'labelstyle' => $labelstyle,
'tip' => get_string('docsetting_disableexport_tip', 'mod_collabora'),
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
],
[
'name' => 'disablecopy',
'type' => 'checkbox',
'checked' => !$DB->get_field('collabora_document', 'disable_copy', ['id' => $this->document->id]) ? 'checked' : '',
'value' => 'true',
'label' => get_string('docsetting_disablecopy_label', 'mod_collabora'),
'labelstyle' => $labelstyle,
'tip' => get_string('docsetting_disablecopy_tip', 'mod_collabora'),
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
],
[
'name' => 'remoteimage',
'hide' => 'true',
'type' => 'checkbox',
'checked' => !$DB->get_field('collabora_document', 'enable_insert_remote_image', ['id' => $this->document->id]) ? 'checked' : '',
'value' => 'true',
'label' => 'Enable Inserting Remote Images',
'labelstyle' => $labelstyle,
'tip' => 'Enable/Disable users to insert remote images.',
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
],
[
'name' => 'watermark',
'type' => 'editbox',
'value' => $DB->get_field('collabora_document', 'watermark_text', ['id' => $this->document->id]),
'widgetstyle' => 'max-width:100% !important',
'label' => get_string('docsetting_watermark_label', 'mod_collabora'),
'tip' => get_string('docsetting_watermark_tip', 'mod_collabora'),
'sub' => get_string('docsetting_default_blank', 'mod_collabora'),
],
],
],

[
'title' => get_string('docsetting_changetracking_title', 'mod_collabora'),
'fields' => [
[
'name' => 'disablechangerecord',
'type' => 'checkbox',
'checked' => !$DB->get_field('collabora_document', 'disable_change_tracking_record', ['id' => $this->document->id]) ? 'checked' : '',
'value' => 'true',
'label' => get_string('docsetting_disablechangerecord_label', 'mod_collabora'),
'labelstyle' => $labelstyle,
'tip' => get_string('docsetting_disablechangerecord_tip', 'mod_collabora'),
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
],
[
'name' => 'disablechangeshow',
'type' => 'checkbox',
'checked' => !$DB->get_field('collabora_document', 'disable_change_tracking_show', ['id' => $this->document->id]) ? 'checked' : '',
'value' => 'true',
'label' => get_string('docsetting_disablechangeshow_label', 'mod_collabora'),
'labelstyle' => $labelstyle,
'tip' => get_string('docsetting_disablechangeshow_tip', 'mod_collabora'),
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
],
[
'name' => 'hidechangecontrols',
'type' => 'checkbox',
'checked' => !$DB->get_field('collabora_document', 'hide_change_tracking_controls', ['id' => $this->document->id]) ? 'checked' : '',
'value' => 'true',
'label' => get_string('docsetting_hidechangecontrols_label', 'mod_collabora'),
'labelstyle' => $labelstyle,
'tip' => get_string('docsetting_hidechangecontrols_tip', 'mod_collabora'),
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
],
],
],
],
];

return $OUTPUT->render_from_template('mod_collabora/settings_panel', $data);
}

public function process_document_settings() {
global $DB, $PAGE;
if (!$this->can_lock_unlock()) {
return;
}
$sesskey = optional_param('sesskey', null, PARAM_TEXT);
if ($sesskey === null) {
return;
}

require_sesskey();

$disableprint = !optional_param('disableprint', null, PARAM_TEXT) ? 1 : 0;
$DB->set_field('collabora_document', 'disable_print', $disableprint, ['id' => $this->document->id]);

$disableexport = !optional_param('disableexport', null, PARAM_TEXT) ? 1 : 0;
$DB->set_field('collabora_document', 'disable_export', $disableexport, ['id' => $this->document->id]);

$disablecopy = !optional_param('disablecopy', null, PARAM_TEXT) ? 1 : 0;
$DB->set_field('collabora_document', 'disable_copy', $disablecopy, ['id' => $this->document->id]);

$disablechangerecord = !optional_param('disablechangerecord', null, PARAM_TEXT) ? 1 : 0;
$DB->set_field('collabora_document', 'disable_change_tracking_record', $disablechangerecord, ['id' => $this->document->id]);

$disablechangeshow = !optional_param('disablechangeshow', null, PARAM_TEXT) ? 1 : 0;
$DB->set_field('collabora_document', 'disable_change_tracking_show', $disablechangeshow, ['id' => $this->document->id]);

$hidechangecontrols = !optional_param('hidechangecontrols', null, PARAM_TEXT) ? 1 : 0;
$DB->set_field('collabora_document', 'hide_change_tracking_controls', $hidechangecontrols, ['id' => $this->document->id]);

$ownertermination = optional_param('ownertermination', null, PARAM_TEXT) ? 1 : 0;
$DB->set_field('collabora_document', 'enable_owner_termination', $ownertermination, ['id' => $this->document->id]);

$remoteimage = !optional_param('remoteimage', null, PARAM_TEXT) ? 1 : 0;
$DB->set_field('collabora_document', 'enable_insert_remote_image', $remoteimage, ['id' => $this->document->id]);

$watermark = optional_param('watermark', null, PARAM_TEXT);
$DB->set_field('collabora_document', 'watermark_text', $watermark, ['id' => $this->document->id]);

// Process the lock state and reload.
$this->process_lock_unlock();
}

/**
* Choose an appropriate filetype icon based on the mimetype.
* @return string|false Icon URL to be used in `cached_cm_info` or false if there is no appropriate icon.
Expand Down
15 changes: 12 additions & 3 deletions db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/collabora/db" VERSION="20190125" COMMENT="XMLDB file for Moodle mod/collabora"
<XMLDB PATH="mod/collabora/db" VERSION="20200811" COMMENT="XMLDB file for Moodle mod/collabora"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -31,7 +31,16 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="collaboraid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The collabora instance this relates to"/>
<FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The group this document relates to"/>
<FIELD NAME="locked" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Has this document been locked as read-only?"/>
<FIELD NAME="locked" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Has this document been locked as read-only except to those with mod/collabora:editlocked?"/>
<FIELD NAME="watermark_text" TYPE="char" LENGTH="127" NOTNULL="false" SEQUENCE="false" COMMENT="The watermark to show on the document, if any."/>
<FIELD NAME="enable_owner_termination" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="When enabled, the document is closed for everyone when the owner closes the document."/>
<FIELD NAME="disable_print" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Disables printing the document."/>
<FIELD NAME="disable_export" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Disables exporting the document to different formats."/>
<FIELD NAME="disable_copy" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Disables copying text and other embedded elements from the document."/>
<FIELD NAME="enable_insert_remote_image" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Controls whether inserting remote images is allowed."/>
<FIELD NAME="disable_change_tracking_record" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Controls whether or not change-tracking is enabled."/>
<FIELD NAME="disable_change_tracking_show" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Controls whether or not change-tracking markers are visible."/>
<FIELD NAME="hide_change_tracking_controls" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Controls whether or not change-tracking controls (to enable/disable and show/hide change-tracking) are visible."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand All @@ -54,4 +63,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
55 changes: 55 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,60 @@

defined('MOODLE_INTERNAL') || die();
function xmldb_collabora_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2020091300) {

$table = new xmldb_table('collabora_document');

$field = new xmldb_field('watermark_text', XMLDB_TYPE_CHAR, '127', null, null, null, null, 'locked');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('enable_owner_termination', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'watermark_text');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('disable_print', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'enable_owner_termination');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('disable_export', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_print');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('disable_copy', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_export');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('enable_insert_remote_image', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_copy');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('disable_change_tracking_record', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'enable_insert_remote_image');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('disable_change_tracking_show', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_change_tracking_record');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('hide_change_tracking_controls', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_change_tracking_show');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Collabora savepoint reached.
upgrade_mod_savepoint(true, 2020091300, 'collabora');
}

return true;
}
Loading