Organization settings: "Filter settings" tab view-only support.

This changes the layout of "organization settings" for
non-administrators such that they can view "Filter settings".
("Actions" column and form to add a new filter are not available).

Fixes: #3636
This commit is contained in:
Abhijeet Kaur 2017-04-15 03:26:33 +05:30 committed by Tim Abbott
parent dc801eb5ed
commit ddfdf0e4c6
6 changed files with 55 additions and 25 deletions

View File

@ -172,11 +172,14 @@ function render(template_name, args) {
}()); }());
(function admin_filter_list() { (function admin_filter_list() {
// When the logged in user is admin
var args = { var args = {
filter: { filter: {
pattern: "#(?P<id>[0-9]+)", pattern: "#(?P<id>[0-9]+)",
url_format_string: "https://trac.example.com/ticket/%(id)s", url_format_string: "https://trac.example.com/ticket/%(id)s",
}, },
can_modify: true,
}; };
var html = ''; var html = '';
@ -184,13 +187,33 @@ function render(template_name, args) {
html += render('admin_filter_list', args); html += render('admin_filter_list', args);
html += '</tbody>'; html += '</tbody>';
global.write_test_output('admin_filter_list', html);
var filter_pattern = $(html).find('tr.filter_row:first span.filter_pattern'); var filter_pattern = $(html).find('tr.filter_row:first span.filter_pattern');
var filter_format = $(html).find('tr.filter_row:first span.filter_url_format_string'); var filter_format = $(html).find('tr.filter_row:first span.filter_url_format_string');
assert.equal(filter_pattern.text(), '#(?P<id>[0-9]+)'); assert.equal(filter_pattern.text(), '#(?P<id>[0-9]+)');
assert.equal(filter_format.text(), 'https://trac.example.com/ticket/%(id)s'); assert.equal(filter_format.text(), 'https://trac.example.com/ticket/%(id)s');
// When the logged in user is not admin
args = {
filter: {
pattern: "#(?P<id>[0-9]+)",
url_format_string: "https://trac.example.com/ticket/%(id)s",
},
can_modify: false,
};
html = '';
html += '<tbody id="admin_filters_table">';
html += render('admin_filter_list', args);
html += '</tbody>';
global.write_test_output('admin_filter_list', html);
filter_pattern = $(html).find('tr.filter_row:first span.filter_pattern');
filter_format = $(html).find('tr.filter_row:first span.filter_url_format_string');
assert.equal(filter_pattern.text(), '#(?P<id>[0-9]+)');
assert.equal(filter_format.text(), 'https://trac.example.com/ticket/%(id)s');
}()); }());
(function admin_streams_list() { (function admin_streams_list() {

View File

@ -17,6 +17,8 @@ exports.show_or_hide_menu_item = function () {
.find("input, button, select, checked").attr("disabled", true); .find("input, button, select, checked").attr("disabled", true);
$(".organization-box [data-name='default-streams-list']") $(".organization-box [data-name='default-streams-list']")
.find("input, button, select").attr("disabled", true); .find("input, button, select").attr("disabled", true);
$(".organization-box [data-name='filter-settings']")
.find("input, button, select").attr("disabled", true);
} }
}; };

View File

@ -22,6 +22,7 @@ exports.populate_filters = function (filters_data) {
url_format_string: filter[1], url_format_string: filter[1],
id: filter[2], id: filter[2],
}, },
can_modify: page_params.is_admin,
} }
) )
); );

View File

@ -6,10 +6,12 @@
<td> <td>
<span class="filter_url_format_string">{{url_format_string}}</span> <span class="filter_url_format_string">{{url_format_string}}</span>
</td> </td>
{{#if ../can_modify}}
<td> <td>
<button class="btn delete btn-danger" data-filter-id="{{id}}"> <button class="btn delete btn-danger" data-filter-id="{{id}}">
{{t "Delete" }} {{t "Delete" }}
</button> </button>
</td> </td>
{{/if}}
</tr> </tr>
{{/with}} {{/with}}

View File

@ -28,31 +28,35 @@
<tbody id="admin_filters_table"> <tbody id="admin_filters_table">
<th>{{t "Pattern" }}</th> <th>{{t "Pattern" }}</th>
<th>{{t "URL format string" }}</th> <th>{{t "URL format string" }}</th>
<th>{{t "Actions" }}</th> {{#if is_admin}}
<th>{{t "Actions" }}</th>
{{/if}}
</tbody> </tbody>
</table> </table>
</div> </div>
<form class="form-horizontal admin-filter-form"> {{#if is_admin}}
<div class="add-new-filter-box grey-bg green-bg"> <form class="form-horizontal admin-filter-form">
<div class="new-filter-form"> <div class="add-new-filter-box grey-bg green-bg">
<div class="settings-section-title new-filter-section-title">{{t "Add a new filter" }}</div> <div class="new-filter-form">
<div class="alert" id="admin-filter-status"></div> <div class="settings-section-title new-filter-section-title">{{t "Add a new filter" }}</div>
<div class="control-group"> <div class="alert" id="admin-filter-status"></div>
<label for="filter_pattern" class="control-label">{{t "Regular expression" }}</label> <div class="control-group">
<input type="text" id="filter_pattern" name="pattern" placeholder="#(?P<id>[0-9]+)" /> <label for="filter_pattern" class="control-label">{{t "Regular expression" }}</label>
<div class="alert" id="admin-filter-pattern-status"></div> <input type="text" id="filter_pattern" name="pattern" placeholder="#(?P<id>[0-9]+)" />
</div> <div class="alert" id="admin-filter-pattern-status"></div>
<div class="control-group"> </div>
<label for="filter_format_string" class="control-label">{{t "URL format string" }}</label> <div class="control-group">
<input type="text" id="filter_format_string" name="url_format_string" placeholder="https://github.com/zulip/zulip/issues/%(id)s" /> <label for="filter_format_string" class="control-label">{{t "URL format string" }}</label>
<div class="alert" id="admin-filter-format-status"></div> <input type="text" id="filter_format_string" name="url_format_string" placeholder="https://github.com/zulip/zulip/issues/%(id)s" />
</div> <div class="alert" id="admin-filter-format-status"></div>
<div class="control-group"> </div>
<div class="controls"> <div class="control-group">
<input type="submit" class="btn btn-big btn-primary" value="{{t 'Add filter' }}" /> <div class="controls">
<input type="submit" class="btn btn-big btn-primary" value="{{t 'Add filter' }}" />
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </form>
</form> {{/if}}
</div> </div>

View File

@ -72,12 +72,10 @@
<i class="icon icon-vector-exchange"></i> <i class="icon icon-vector-exchange"></i>
<div class="text">{{ _('Default streams') }}</div> <div class="text">{{ _('Default streams') }}</div>
</li> </li>
{% if is_admin %}
<li class="admin" tabindex="1" data-section="filter-settings"> <li class="admin" tabindex="1" data-section="filter-settings">
<i class="icon icon-vector-font"></i> <i class="icon icon-vector-font"></i>
<div class="text">{{ _('Filter settings') }}</div> <div class="text">{{ _('Filter settings') }}</div>
</li> </li>
{% endif %}
</ul> </ul>
</div> </div>