diff --git a/src/app/addoption-dialog/addoption-dialog.page.html b/src/app/addoption-dialog/addoption-dialog.page.html
index 6d01f7be3..4a767c5aa 100644
--- a/src/app/addoption-dialog/addoption-dialog.page.html
+++ b/src/app/addoption-dialog/addoption-dialog.page.html
@@ -41,7 +41,8 @@
: 'draftpoll.target-name-label') | translate">
-
{
- }).catch(err => {
- });
- if (this.parent.delegation_status == 'agreed') {
- this.G.Del.update_my_delegation(this.p.pid, o.oid, true);
+ if (!this.isAddButtonDisabled()) {
+ /** add the option */
+ const name = this.formGroup.get('option_name').value,
+ desc = this.formGroup.get('option_desc').value,
+ url = this.formGroup.get('option_url').value,
+ o = new Option(this.G, this.p, null, name, desc, url);
+ LocalNotifications.schedule({
+ notifications: [{
+ title: this.translate.instant("addoption.notification-added-title"),
+ body: name,
+ id: 0
+ }]
+ })
+ .then(res => {
+ }).catch(err => {
+ });
+ if (this.parent.delegation_status == 'agreed') {
+ this.G.Del.update_my_delegation(this.p.pid, o.oid, true);
+ }
+ this.p.set_my_own_rating(o.oid, this.G.S.default_wap);
+ this.parent.oidsorted.push(o.oid);
+ this.parent.sortingcounter++;
+ this.ref.detectChanges();
+ // need to wait a little for the view to refresh:
+ setTimeout(() => {
+ this.p.tally_all();
+ this.popover.dismiss();
+ }, 200);
}
- this.p.set_my_own_rating(o.oid, this.G.S.default_wap);
- this.parent.oidsorted.push(o.oid);
- this.parent.sortingcounter++;
- this.ref.detectChanges();
- // need to wait a little for the view to refresh:
- setTimeout(() => {
- this.p.tally_all();
- this.popover.dismiss();
- }, 200);
}
ClosePopover()
diff --git a/src/app/openpoll/vodle/package.json b/src/app/openpoll/vodle/package.json
new file mode 100644
index 000000000..48e65adcd
--- /dev/null
+++ b/src/app/openpoll/vodle/package.json
@@ -0,0 +1,4 @@
+{
+ "name": "vodle",
+ "description": "vodle CouchDB logics: contains a validation function to restrict permissions in _user database"
+}
\ No newline at end of file
diff --git a/src/app/openpoll/vodle/validate_doc_update.js b/src/app/openpoll/vodle/validate_doc_update.js
new file mode 100644
index 000000000..8287dbf39
--- /dev/null
+++ b/src/app/openpoll/vodle/validate_doc_update.js
@@ -0,0 +1,43 @@
+function(newDoc, savedDoc, userCtx) {
+ // restrict permissions so that only "vodle" can create users,
+ // a user can only update their own user doc,
+ // but "vodle" cannot even do that (so that no-one can change this shared user's password!):
+ if (!(userCtx.name == "admin")) {
+ // restrict what others than "admin" can do:
+ if (!savedDoc) {
+ // Attempt to create new doc
+ // Make sure only "vodle" can do this:
+ if (!(userCtx.name == "vodle")) {
+ throw ({forbidden: 'Only users "admin" and "vodle" may create new users.'});
+ }
+ // Make sure new doc is a user doc whose name begins with "vodle.":
+ if (!newDoc._id.startsWith("org.couchdb.user:vodle.")) {
+ throw ({forbidden: 'New usernames must start with "vodle.".'});
+ }
+ } else if (!newDoc) {
+ // Attempt to delete existing doc
+ // Make sure only the user themself can do this to her user doc:
+ if (!(savedDoc._id == "org.couchdb.user:"+userCtx.name)) {
+ throw ({forbidden: 'Users may only delete their own user document.'});
+ }
+ // Make sure special user "vodle" can NOT delete their own document:
+ if (userCtx.name == "vodle") {
+ throw ({forbidden: 'User "vodle" may not delete any user document.'});
+ }
+ } else {
+ // Attempt to delete or update existing doc
+ // Make sure only the user themself can do this to her user doc:
+ if (!(newDoc._id == "org.couchdb.user:"+userCtx.name)) {
+ throw ({forbidden: 'Users may only delete or update their own user document.'});
+ }
+ // Make sure special user "vodle" can NOT update their own user document:
+ if (userCtx.name == "vodle") {
+ throw ({forbidden: 'User "vodle" may not delete or update any user document.'});
+ }
+ // Make sure poll users "vodle.poll.XXX" can NOT update their own user documents either:
+ if (userCtx.name.beginsWith("vodle.poll.") && !userCtx.name.includes(".voter.")) {
+ throw ({forbidden: 'Poll users "vodle.poll.XXX" may not delete or update any user document.'});
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/app/poll.service.ts b/src/app/poll.service.ts
index 3ebf6324b..02cd2a1a2 100644
--- a/src/app/poll.service.ts
+++ b/src/app/poll.service.ts
@@ -1922,8 +1922,11 @@ export class Poll {
}
}
-
-
+ add_option_deadline(): Date {
+ const t0 = this.start_date.getTime(),
+ t2 = this.due.getTime();
+ return new Date(t2 - (t2 - t0) * environment.no_more_options_time_fraction);
+ }
}
diff --git a/src/app/poll/poll.page.html b/src/app/poll/poll.page.html
index d9eb36266..7de22cb6b 100644
--- a/src/app/poll/poll.page.html
+++ b/src/app/poll/poll.page.html
@@ -941,8 +941,8 @@
[disabled]="!p.can_add_option()">
-
-
+
+
diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json
index 48c98d1d4..76c9a8059 100644
--- a/src/assets/i18n/de.json
+++ b/src/assets/i18n/de.json
@@ -594,7 +594,7 @@
"average-rating": "durchschn. Wap {{average}}",
"explain": "Erklären",
"add-option": "Option hinzufügen",
- "add-option-info": "Wenn Du denkst, eine wichtige Option fehlt noch und ist nicht von den anderen Optionen mit abgedeckt, kannst Du sie hinzufügen. Einmal hinzugefügte Optionen kann allerdings niemand mehr verändern oder löschen.",
+ "add-option-info": "Wenn Du denkst, eine wichtige Option fehlt noch und ist nicht von den anderen Optionen mit abgedeckt, kannst Du sie bis {{deadline}} hinzufügen. Einmal hinzugefügte Optionen kann allerdings niemand mehr verändern oder löschen.",
"sorting": "Optionen werden neu sortiert..."
},
"previewpoll": {
diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json
index bb6700e8a..852dc261d 100644
--- a/src/assets/i18n/en.json
+++ b/src/assets/i18n/en.json
@@ -600,7 +600,7 @@
"average-rating": "avg. wap {{average}}",
"explain": "Explain",
"add-option": "Add option",
- "add-option-info": "If you believe some important option is missing and is not covered by any of the listed options, you can add it. Once added, options cannot be edited or removed again, however.",
+ "add-option-info": "If you believe some important option is missing and is not covered by any of the listed options, you can add it until {{deadline}}. Once added, options cannot be edited or removed again, however.",
"sorting": "Sorting options by approval...",
"add-option-expired": "Time to add new options has expired."
},
diff --git a/src/environments/environment.ts b/src/environments/environment.ts
index f5bc645d1..141287d57 100644
--- a/src/environments/environment.ts
+++ b/src/environments/environment.ts
@@ -55,7 +55,7 @@ export const environment = {
enabled: false,
max_weight: 3
},
- no_more_options_time_fraction: 1/14,
+ no_more_options_time_fraction: 1/2,
db_put_retry_delay_ms: 100,
default_lang: "en",
github_url: "https://github.com/pik-gane/vodle/",