Skip to content

Commit 89d0a31

Browse files
committed
Support per-document options
This adds support for per-document options, such as enabling/disabling printing, copying, exporting, etc. and adds the ability to set a watermark and other security settings. These option/settings can be modified by the document owner. The document locking logic is also included as a form option to make it homogeneous with the others. The options are hidden by default, in a collapsed section. They are never shown to user without the ability to modify them.
1 parent fc22536 commit 89d0a31

File tree

7 files changed

+356
-18
lines changed

7 files changed

+356
-18
lines changed

classes/api.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,71 @@ private function get_user() {
190190
return \core_user::get_user($this->userid);
191191
}
192192

193+
private function get_watermark_text() {
194+
global $DB;
195+
return $DB->get_field('collabora_document', 'watermark_text', ['id' => $this->docrecord->id]);
196+
}
197+
198+
private function get_hide_print() {
199+
return false;
200+
}
201+
202+
private function get_hide_save() {
203+
return false;
204+
}
205+
206+
private function get_hide_export() {
207+
return false;
208+
}
209+
210+
private function get_enable_owner_termination() {
211+
global $DB;
212+
return $DB->get_field('collabora_document', 'enable_owner_termination', ['id' => $this->docrecord->id]);
213+
}
214+
215+
private function get_disable_print() {
216+
global $DB;
217+
return $DB->get_field('collabora_document', 'disable_print', ['id' => $this->docrecord->id]);
218+
}
219+
220+
private function get_disable_export() {
221+
global $DB;
222+
return $DB->get_field('collabora_document', 'disable_export', ['id' => $this->docrecord->id]);
223+
}
224+
225+
private function get_disable_copy() {
226+
global $DB;
227+
return $DB->get_field('collabora_document', 'disable_copy', ['id' => $this->docrecord->id]);
228+
}
229+
230+
private function get_enable_insert_remote_image() {
231+
global $DB;
232+
return $DB->get_field('collabora_document', 'enable_insert_remote_image', ['id' => $this->docrecord->id]);
233+
}
234+
235+
// If set to 'true', the user-list on the status bar will be hidden.
236+
// If set to 'mobile' | 'tablet' | 'desktop', it will be hidden on the
237+
// specified device(s) only (multiples values can be delimited by comma,
238+
// e.g. 'mobile,tablet').
239+
private function get_hide_user_list() {
240+
return 'false';
241+
}
242+
243+
private function get_disable_change_tracking_record() {
244+
global $DB;
245+
return $DB->get_field('collabora_document', 'disable_change_tracking_record', ['id' => $this->docrecord->id]);
246+
}
247+
248+
private function get_disable_change_tracking_show() {
249+
global $DB;
250+
return $DB->get_field('collabora_document', 'disable_change_tracking_show', ['id' => $this->docrecord->id]);
251+
}
252+
253+
private function get_hide_change_tracking_controls() {
254+
global $DB;
255+
return $DB->get_field('collabora_document', 'hide_change_tracking_controls', ['id' => $this->docrecord->id]);
256+
}
257+
193258
/**
194259
* Handle getfile requests.
195260
*/
@@ -234,7 +299,21 @@ private function handle_checkfileinfo() {
234299
'UserCanWrite' => !$this->is_readonly(),
235300
'UserCanNotWriteRelative' => true,
236301
'LastModifiedTime' => date('c', $file->get_timemodified()),
302+
'WatermarkText' => $this->get_watermark_text(),
303+
'HidePrintOption' => $this->get_hide_print(),
304+
'HideSaveOption' => $this->get_hide_save(),
305+
'HideExportOption' => $this->get_hide_export(),
306+
'EnableOwnerTermination' => $this->get_enable_owner_termination(),
307+
'DisablePrint' => $this->get_disable_print(),
308+
'DisableExport' => $this->get_disable_export(),
309+
'DisableCopy' => $this->get_disable_copy(),
310+
'EnableInsertRemoteImage' => $this->get_enable_insert_remote_image(),
311+
'HideUserList' => $this->get_hide_user_list(),
312+
'DisableChangeTrackingRecord' => $this->get_disable_change_tracking_record(),
313+
'DisableChangeTrackingShow' => $this->get_disable_change_tracking_show(),
314+
'HideChangeTrackingControls' => $this->get_hide_change_tracking_controls(),
237315
];
316+
238317
die(json_encode($ret));
239318
}
240319
}

classes/collabora.php

Lines changed: 177 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,8 @@ public function process_lock_unlock() {
118118
if (!$this->can_lock_unlock()) {
119119
return;
120120
}
121-
$lock = optional_param('lock', null, PARAM_INT);
122-
if ($lock !== $this->groupid) {
123-
$lock = null;
124-
}
125-
$unlock = optional_param('unlock', null, PARAM_INT);
126-
if ($unlock !== $this->groupid) {
127-
$unlock = null;
128-
}
129-
if ($lock === null && $unlock === null) {
130-
return;
131-
}
132121
require_sesskey();
133-
$locked = ($lock !== null) ? 1 : 0;
122+
$locked = optional_param('locked', null, PARAM_INT) ? 1 : 0;
134123
$this->document->locked = $locked;
135124
$DB->set_field('collabora_document', 'locked', $locked, ['id' => $this->document->id]);
136125
if ($locked) {
@@ -365,6 +354,182 @@ public function get_lock_icon() {
365354
return $OUTPUT->render_from_template('mod_collabora/lockicon', $data);
366355
}
367356

357+
public function get_settings_panel($cmid) {
358+
global $PAGE, $OUTPUT, $DB;
359+
$canupdate = $this->can_lock_unlock();
360+
$islocked = $this->is_locked();
361+
$url = null;
362+
if ($canupdate) {
363+
$params = ['sesskey' => sesskey()];
364+
if ($islocked) {
365+
$params['unlock'] = $this->groupid;
366+
} else {
367+
$params['lock'] = $this->groupid;
368+
}
369+
370+
$url = new \moodle_url($PAGE->url);
371+
}
372+
373+
$hideuserslist = $DB->get_field('collabora_document', 'hide_user_list', ['id' => $this->document->id]);
374+
$labelstyle = '';
375+
376+
$data = (object)[
377+
'canupdate' => $this->can_lock_unlock(),
378+
'islocked' => $islocked,
379+
'url' => $PAGE->url,
380+
'id' => $cmid,
381+
'sesskey' => sesskey(),
382+
'fieldsets' => [
383+
[
384+
'title' => get_string('docsetting_security_title', 'mod_collabora'),
385+
'fields' => [
386+
[
387+
'name' => 'locked',
388+
'type' => 'checkbox',
389+
'checked' => $DB->get_field('collabora_document', 'locked', ['id' => $this->document->id]) ? 'checked' : '',
390+
'value' => '1',
391+
'label' => get_string('docsetting_locked_label', 'mod_collabora'),
392+
'labelstyle' => $labelstyle,
393+
'tip' => get_string('docsetting_locked_tip', 'mod_collabora'),
394+
'sub' => get_string('docsetting_default_no', 'mod_collabora'),
395+
],
396+
[
397+
'name' => 'disableprint',
398+
'type' => 'checkbox',
399+
'checked' => !$DB->get_field('collabora_document', 'disable_print', ['id' => $this->document->id]) ? 'checked' : '',
400+
'value' => 'true',
401+
'label' => get_string('docsetting_disableprint_label', 'mod_collabora'),
402+
'labelstyle' => $labelstyle,
403+
'tip' => get_string('docsetting_disableprint_tip', 'mod_collabora'),
404+
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
405+
],
406+
[
407+
'name' => 'disableexport',
408+
'type' => 'checkbox',
409+
'checked' => !$DB->get_field('collabora_document', 'disable_export', ['id' => $this->document->id]) ? 'checked' : '',
410+
'value' => 'true',
411+
'label' => get_string('docsetting_disableexport_label', 'mod_collabora'),
412+
'labelstyle' => $labelstyle,
413+
'tip' => get_string('docsetting_disableexport_tip', 'mod_collabora'),
414+
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
415+
],
416+
[
417+
'name' => 'disablecopy',
418+
'type' => 'checkbox',
419+
'checked' => !$DB->get_field('collabora_document', 'disable_copy', ['id' => $this->document->id]) ? 'checked' : '',
420+
'value' => 'true',
421+
'label' => get_string('docsetting_disablecopy_label', 'mod_collabora'),
422+
'labelstyle' => $labelstyle,
423+
'tip' => get_string('docsetting_disablecopy_tip', 'mod_collabora'),
424+
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
425+
],
426+
[
427+
'name' => 'remoteimage',
428+
'hide' => 'true',
429+
'type' => 'checkbox',
430+
'checked' => !$DB->get_field('collabora_document', 'enable_insert_remote_image', ['id' => $this->document->id]) ? 'checked' : '',
431+
'value' => 'true',
432+
'label' => 'Enable Inserting Remote Images',
433+
'labelstyle' => $labelstyle,
434+
'tip' => 'Enable/Disable users to insert remote images.',
435+
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
436+
],
437+
[
438+
'name' => 'watermark',
439+
'type' => 'editbox',
440+
'value' => $DB->get_field('collabora_document', 'watermark_text', ['id' => $this->document->id]),
441+
'widgetstyle' => 'max-width:100% !important',
442+
'label' => get_string('docsetting_watermark_label', 'mod_collabora'),
443+
'tip' => get_string('docsetting_watermark_tip', 'mod_collabora'),
444+
'sub' => get_string('docsetting_default_blank', 'mod_collabora'),
445+
],
446+
],
447+
],
448+
449+
[
450+
'title' => get_string('docsetting_changetracking_title', 'mod_collabora'),
451+
'fields' => [
452+
[
453+
'name' => 'disablechangerecord',
454+
'type' => 'checkbox',
455+
'checked' => !$DB->get_field('collabora_document', 'disable_change_tracking_record', ['id' => $this->document->id]) ? 'checked' : '',
456+
'value' => 'true',
457+
'label' => get_string('docsetting_disablechangerecord_label', 'mod_collabora'),
458+
'labelstyle' => $labelstyle,
459+
'tip' => get_string('docsetting_disablechangerecord_tip', 'mod_collabora'),
460+
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
461+
],
462+
[
463+
'name' => 'disablechangeshow',
464+
'type' => 'checkbox',
465+
'checked' => !$DB->get_field('collabora_document', 'disable_change_tracking_show', ['id' => $this->document->id]) ? 'checked' : '',
466+
'value' => 'true',
467+
'label' => get_string('docsetting_disablechangeshow_label', 'mod_collabora'),
468+
'labelstyle' => $labelstyle,
469+
'tip' => get_string('docsetting_disablechangeshow_tip', 'mod_collabora'),
470+
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
471+
],
472+
[
473+
'name' => 'hidechangecontrols',
474+
'type' => 'checkbox',
475+
'checked' => !$DB->get_field('collabora_document', 'hide_change_tracking_controls', ['id' => $this->document->id]) ? 'checked' : '',
476+
'value' => 'true',
477+
'label' => get_string('docsetting_hidechangecontrols_label', 'mod_collabora'),
478+
'labelstyle' => $labelstyle,
479+
'tip' => get_string('docsetting_hidechangecontrols_tip', 'mod_collabora'),
480+
'sub' => get_string('docsetting_default_yes', 'mod_collabora'),
481+
],
482+
],
483+
],
484+
],
485+
];
486+
487+
return $OUTPUT->render_from_template('mod_collabora/settings_panel', $data);
488+
}
489+
490+
public function process_document_settings() {
491+
global $DB, $PAGE;
492+
if (!$this->can_lock_unlock()) {
493+
return;
494+
}
495+
$sesskey = optional_param('sesskey', null, PARAM_TEXT);
496+
if ($sesskey === null) {
497+
return;
498+
}
499+
500+
require_sesskey();
501+
502+
$disableprint = !optional_param('disableprint', null, PARAM_TEXT) ? 1 : 0;
503+
$DB->set_field('collabora_document', 'disable_print', $disableprint, ['id' => $this->document->id]);
504+
505+
$disableexport = !optional_param('disableexport', null, PARAM_TEXT) ? 1 : 0;
506+
$DB->set_field('collabora_document', 'disable_export', $disableexport, ['id' => $this->document->id]);
507+
508+
$disablecopy = !optional_param('disablecopy', null, PARAM_TEXT) ? 1 : 0;
509+
$DB->set_field('collabora_document', 'disable_copy', $disablecopy, ['id' => $this->document->id]);
510+
511+
$disablechangerecord = !optional_param('disablechangerecord', null, PARAM_TEXT) ? 1 : 0;
512+
$DB->set_field('collabora_document', 'disable_change_tracking_record', $disablechangerecord, ['id' => $this->document->id]);
513+
514+
$disablechangeshow = !optional_param('disablechangeshow', null, PARAM_TEXT) ? 1 : 0;
515+
$DB->set_field('collabora_document', 'disable_change_tracking_show', $disablechangeshow, ['id' => $this->document->id]);
516+
517+
$hidechangecontrols = !optional_param('hidechangecontrols', null, PARAM_TEXT) ? 1 : 0;
518+
$DB->set_field('collabora_document', 'hide_change_tracking_controls', $hidechangecontrols, ['id' => $this->document->id]);
519+
520+
$ownertermination = optional_param('ownertermination', null, PARAM_TEXT) ? 1 : 0;
521+
$DB->set_field('collabora_document', 'enable_owner_termination', $ownertermination, ['id' => $this->document->id]);
522+
523+
$remoteimage = !optional_param('remoteimage', null, PARAM_TEXT) ? 1 : 0;
524+
$DB->set_field('collabora_document', 'enable_insert_remote_image', $remoteimage, ['id' => $this->document->id]);
525+
526+
$watermark = optional_param('watermark', null, PARAM_TEXT);
527+
$DB->set_field('collabora_document', 'watermark_text', $watermark, ['id' => $this->document->id]);
528+
529+
// Process the lock state and reload.
530+
$this->process_lock_unlock();
531+
}
532+
368533
/**
369534
* Choose an appropriate filetype icon based on the mimetype.
370535
* @return string|false Icon URL to be used in `cached_cm_info` or false if there is no appropriate icon.

db/install.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<XMLDB PATH="mod/collabora/db" VERSION="20190125" COMMENT="XMLDB file for Moodle mod/collabora"
2+
<XMLDB PATH="mod/collabora/db" VERSION="20200811" COMMENT="XMLDB file for Moodle mod/collabora"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
55
>
@@ -31,7 +31,16 @@
3131
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
3232
<FIELD NAME="collaboraid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The collabora instance this relates to"/>
3333
<FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The group this document relates to"/>
34-
<FIELD NAME="locked" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Has this document been locked as read-only?"/>
34+
<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?"/>
35+
<FIELD NAME="watermark_text" TYPE="char" LENGTH="127" NOTNULL="false" SEQUENCE="false" COMMENT="The watermark to show on the document, if any."/>
36+
<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."/>
37+
<FIELD NAME="disable_print" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Disables printing the document."/>
38+
<FIELD NAME="disable_export" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Disables exporting the document to different formats."/>
39+
<FIELD NAME="disable_copy" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Disables copying text and other embedded elements from the document."/>
40+
<FIELD NAME="enable_insert_remote_image" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Controls whether inserting remote images is allowed."/>
41+
<FIELD NAME="disable_change_tracking_record" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Controls whether or not change-tracking is enabled."/>
42+
<FIELD NAME="disable_change_tracking_show" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Controls whether or not change-tracking markers are visible."/>
43+
<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."/>
3544
</FIELDS>
3645
<KEYS>
3746
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@@ -54,4 +63,4 @@
5463
</INDEXES>
5564
</TABLE>
5665
</TABLES>
57-
</XMLDB>
66+
</XMLDB>

db/upgrade.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,60 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626
function xmldb_collabora_upgrade($oldversion) {
27+
global $CFG, $DB;
28+
$dbman = $DB->get_manager();
29+
if ($oldversion < 2020091300) {
30+
31+
$table = new xmldb_table('collabora_document');
32+
33+
$field = new xmldb_field('watermark_text', XMLDB_TYPE_CHAR, '127', null, null, null, null, 'locked');
34+
if (!$dbman->field_exists($table, $field)) {
35+
$dbman->add_field($table, $field);
36+
}
37+
38+
$field = new xmldb_field('enable_owner_termination', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'watermark_text');
39+
if (!$dbman->field_exists($table, $field)) {
40+
$dbman->add_field($table, $field);
41+
}
42+
43+
$field = new xmldb_field('disable_print', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'enable_owner_termination');
44+
if (!$dbman->field_exists($table, $field)) {
45+
$dbman->add_field($table, $field);
46+
}
47+
48+
$field = new xmldb_field('disable_export', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_print');
49+
if (!$dbman->field_exists($table, $field)) {
50+
$dbman->add_field($table, $field);
51+
}
52+
53+
$field = new xmldb_field('disable_copy', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_export');
54+
if (!$dbman->field_exists($table, $field)) {
55+
$dbman->add_field($table, $field);
56+
}
57+
58+
$field = new xmldb_field('enable_insert_remote_image', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_copy');
59+
if (!$dbman->field_exists($table, $field)) {
60+
$dbman->add_field($table, $field);
61+
}
62+
63+
$field = new xmldb_field('disable_change_tracking_record', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'enable_insert_remote_image');
64+
if (!$dbman->field_exists($table, $field)) {
65+
$dbman->add_field($table, $field);
66+
}
67+
68+
$field = new xmldb_field('disable_change_tracking_show', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_change_tracking_record');
69+
if (!$dbman->field_exists($table, $field)) {
70+
$dbman->add_field($table, $field);
71+
}
72+
73+
$field = new xmldb_field('hide_change_tracking_controls', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'disable_change_tracking_show');
74+
if (!$dbman->field_exists($table, $field)) {
75+
$dbman->add_field($table, $field);
76+
}
77+
78+
// Collabora savepoint reached.
79+
upgrade_mod_savepoint(true, 2020091300, 'collabora');
80+
}
81+
2782
return true;
2883
}

0 commit comments

Comments
 (0)