summaryrefslogtreecommitdiff
path: root/addons/website_forum/static/src
diff options
context:
space:
mode:
authorjbm-odoo <jbm@odoo.com>2020-01-17 07:51:56 +0000
committerYannick Tivisse <yti@odoo.com>2020-02-28 08:58:43 +0000
commit49d64a8fb1fd79a6e53c3768183f6359d9bee6e4 (patch)
tree1dd92636aeb17c7234bff9dfb1cee9ab37db09ac /addons/website_forum/static/src
parentee519c222f0d1aec3f1b4082bbd76d13dedd07b2 (diff)
[IMP] website_forum: Add privacy
Add privacy on forum: public or private. If private, we must select one group that has access. For forum linked to eLearning course: the privacy of forum is the same as the course. If the course is not yet published, the forum will be invisible (unless we have the group group_website_slides_officer). If a forum linked to a course is unlinked or removed, the forum will become private and his group will be set to group_website_slides_officer. All posts and tags have the same access rules as their linked forum. closes odoo/odoo#43486 Taskid: 2169965 Related: odoo/upgrade#758 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/website_forum/static/src')
-rw-r--r--addons/website_forum/static/src/js/website_forum.editor.js65
-rw-r--r--addons/website_forum/static/src/xml/website_forum_templates.xml27
2 files changed, 86 insertions, 6 deletions
diff --git a/addons/website_forum/static/src/js/website_forum.editor.js b/addons/website_forum/static/src/js/website_forum.editor.js
index 2f6d61791c8..74072c592b4 100644
--- a/addons/website_forum/static/src/js/website_forum.editor.js
+++ b/addons/website_forum/static/src/js/website_forum.editor.js
@@ -12,6 +12,9 @@ var ForumCreateDialog = Dialog.extend({
['/website_forum/static/src/xml/website_forum_templates.xml']
),
template: 'website_forum.add_new_forum',
+ events: _.extend({}, Dialog.prototype.events, {
+ 'change input[name="privacy"]': '_onPrivacyChanged',
+ }),
/**
* @override
@@ -36,19 +39,67 @@ var ForumCreateDialog = Dialog.extend({
});
this._super(parent, options);
},
+ start: function () {
+ var self = this;
+ return this._super.apply(this, arguments).then(function () {
+ var $input = self.$('#group_id');
+ $input.select2({
+ width: '100%',
+ allowClear: true,
+ formatNoMatches: false,
+ multiple: false,
+ selection_data: false,
+ fill_data: function (query, data) {
+ var that = this;
+ var tags = {results: []};
+ _.each(data, function (obj) {
+ if (that.matcher(query.term, obj.display_name)) {
+ tags.results.push({id: obj.id, text: obj.display_name});
+ }
+ });
+ query.callback(tags);
+ },
+ query: function (query) {
+ var that = this;
+ // fetch data only once and store it
+ if (!this.selection_data) {
+ self._rpc({
+ model: 'res.groups',
+ method: 'search_read',
+ args: [[], ['display_name']],
+ }).then(function (data) {
+ that.fill_data(query, data);
+ that.selection_data = data;
+ });
+ } else {
+ this.fill_data(query, this.selection_data);
+ }
+ }
+ });
+ });
+ },
onCreateClick: function () {
var $dialog = this.$el;
- var forumName = $dialog.find('input[name=forum_name]').val();;
- if (!forumName) {
+ var $forumName = $dialog.find('input[name=forum_name]');
+ if (!$forumName.val()) {
+ $forumName.addClass('border-danger');
+ return;
+ }
+ var $forumPrivacyGroup = $dialog.find('input[name=group_id]');
+ var forumPrivacy = $dialog.find('input:radio[name=privacy]:checked').val();
+ if (forumPrivacy === 'private' && !$forumPrivacyGroup.val()) {
+ this.$("#group-required").removeClass('d-none');
return;
}
var addMenu = ($dialog.find('input[type="checkbox"]').is(':checked'));
- var forumMode = $dialog.find('input[type="radio"]:checked').val();
+ var forumMode = $dialog.find('input:radio[name=mode]:checked').val();
return this._rpc({
route: '/forum/new',
params: {
- forum_name: forumName,
+ forum_name: $forumName.val(),
forum_mode: forumMode,
+ forum_privacy: forumPrivacy,
+ forum_privacy_group: $forumPrivacyGroup.val(),
add_menu: addMenu || "",
},
}).then(function (url) {
@@ -56,6 +107,12 @@ var ForumCreateDialog = Dialog.extend({
return new Promise(function () {});
});
},
+ /**
+ * @private
+ */
+ _onPrivacyChanged: function (ev) {
+ this.$('.show_visibility_group').toggleClass('d-none', ev.target.value !== 'private');
+ },
});
WebsiteNewMenu.include({
diff --git a/addons/website_forum/static/src/xml/website_forum_templates.xml b/addons/website_forum/static/src/xml/website_forum_templates.xml
index 0d3ce2407d0..afe95135158 100644
--- a/addons/website_forum/static/src/xml/website_forum_templates.xml
+++ b/addons/website_forum/static/src/xml/website_forum_templates.xml
@@ -3,7 +3,7 @@
<t t-name="website_forum.add_new_forum">
<form id="editor_new_forum">
<div class="form-group row">
- <label for="page-name" class="col-md-4 col-form-label">Forum Name:</label>
+ <label for="page-name" class="col-md-4 col-form-label">Forum Name</label>
<div class="col-md-8">
<input type="text" name="forum_name" class="form-control" required="required"/>
<div class="custom-control custom-checkbox mt-2">
@@ -13,7 +13,8 @@
</div>
</div>
<div class="form-group row mt-2">
- <label class="col-md-4 col-form-label">Forum Mode:</label>
+ <label class="col-md-4 col-form-label" data-toggle="tooltip" data-placement="bottom"
+ title="Questions and Answers mode: only one answer allowed\n Discussions mode: multiple answers allowed">Forum Mode</label>
<div class="col-md-8">
<div class="custom-control custom-radio">
<input type="radio" id="questions" name="mode" class="custom-control-input" value="questions" checked="checked"/>
@@ -25,6 +26,28 @@
</div>
</div>
</div>
+ <div class="form-group row mt-2">
+ <label class="col-md-4 col-form-label" data-toggle="tooltip" data-placement="bottom"
+ title="Public: Forum is pubic\nSigned In: Forum is visible for signed in users\nSome users: Forum and their content are hidden for non members of selected group">Privacy</label>
+ <div class="col-md-8">
+ <div class="custom-control custom-radio">
+ <input type="radio" id="public" name="privacy" class="custom-control-input" value="public" checked="checked"/>
+ <label class="custom-control-label" for="public">Public</label>
+ </div>
+ <div class="custom-control custom-radio">
+ <input type="radio" id="connected" name="privacy" class="custom-control-input" value="connected"/>
+ <label class="custom-control-label" for="connected">Signed In</label>
+ </div>
+ <div class="custom-control custom-radio">
+ <input type="radio" id="private" name="privacy" class="custom-control-input" value="private"/>
+ <label class="custom-control-label" for="private">Some Users</label>
+ </div>
+ <div class="form-group show_visibility_group d-none">
+ <input type="text" class="form-control" name="group_id" id="group_id" placeholder="Select Authorized Group"/>
+ <p id="group-required" class="text-danger mt-1 mb-0 d-none">Please fill in this field</p>
+ </div>
+ </div>
+ </div>
</form>
</t>
</templates>