Skip to content

Commit

Permalink
Improved the rule copy feature to differentiate between incoming and …
Browse files Browse the repository at this point in the history
…outgoing services
  • Loading branch information
jc21 committed Jun 18, 2018
1 parent 206074a commit 5ada900
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
14 changes: 10 additions & 4 deletions src/backend/internal/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ const internalRule = {
* @param {Object} data
* @param {Integer} data.from
* @param {Integer} data.to
* @param {String} [data.service_type]
* @param {String} [data.in_service_type]
* @param {String} [data.out_service_type]
*/
copy: (access, data) => {
return access.can('rules:copy')
Expand All @@ -249,9 +250,14 @@ const internalRule = {
.where('rule.is_deleted', 0)
.andWhere('rule.user_id', data.from);

if (typeof data.service_type !== 'undefined' && data.service_type) {
query.join('service', 'rule.in_service_id', 'service.id')
.andWhere('service.type', data.service_type);
if (typeof data.in_service_type !== 'undefined' && data.in_service_type) {
query.join('service as in_service', 'rule.in_service_id', 'in_service.id')
.andWhere('in_service.type', data.in_service_type);
}

if (typeof data.out_service_type !== 'undefined' && data.out_service_type) {
query.join('service as out_service', 'rule.out_service_id', 'out_service.id')
.andWhere('out_service.type', data.out_service_type);
}

return query;
Expand Down
5 changes: 4 additions & 1 deletion src/backend/schema/endpoints/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@
"type": "integer",
"minimum": 1
},
"service_type": {
"in_service_type": {
"$ref": "../definitions.json#/definitions/service_type"
},
"out_service_type": {
"$ref": "../definitions.json#/definitions/service_type"
}
}
Expand Down
24 changes: 18 additions & 6 deletions src/frontend/js/app/user/copy_rules.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<p>This will NOT overwrite or remove any existing rules for the user, who currently has <strong><%- rule_count %></strong> rules.</p>

<div class="form-group">
<label class="col-sm-3 control-label">Copy rules from</label>
<div class="col-sm-9">
<label class="col-sm-5 control-label">Copy rules from</label>
<div class="col-sm-7">
<select name="from_user_id" class="form-control" required>
<option value="">Select...</option>
<%
Expand All @@ -27,17 +27,29 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Rules for Services</label>
<div class="col-sm-9">
<select name="service_type" class="form-control">
<option value="">All Services</option>
<label class="col-sm-5 control-label">Rules for Incoming Services</label>
<div class="col-sm-7">
<select name="in_service_type" class="form-control">
<option value="">All Incoming Services</option>
<option value="bitbucket-webhook">Bitbucket Rules</option>
<option value="dockerhub-webhook">Docker Hub Rules</option>
<option value="jenkins-webhook">Jenkins</option>
<option value="jira-webhook">Jira Rules</option>
<option value="zendesk-webhook">Zendesk Rules</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label">Rules for Outgoing Services</label>
<div class="col-sm-7">
<select name="out_service_type" class="form-control">
<option value="">All Outgoing Services</option>
<option value="gchat">Google Chat Rules</option>
<option value="jabber">Jabber Rules</option>
<option value="slack">Slack Rules</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
Expand Down
13 changes: 7 additions & 6 deletions src/frontend/js/app/user/copy_rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ module.exports = Mn.View.extend({
template: template,

ui: {
form: 'form',
buttons: 'form button',
cancel: 'button.cancel',
from_user_id: 'select[name="from_user_id"]',
service_type: 'select[name="service_type"]'
form: 'form',
buttons: 'form button',
cancel: 'button.cancel',
from_user_id: 'select[name="from_user_id"]',
in_service_type: 'select[name="in_service_type"]',
out_service_type: 'select[name="out_service_type"]'
},

events: {
Expand All @@ -24,7 +25,7 @@ module.exports = Mn.View.extend({
let from_user_id = parseInt(this.ui.from_user_id.val(), 10);

this.ui.buttons.prop('disabled', true).addClass('btn-disabled');
Api.Rules.copy(from_user_id, this.model.get('id'), this.ui.service_type.val())
Api.Rules.copy(from_user_id, this.model.get('id'), this.ui.in_service_type.val(), this.ui.out_service_type.val())
.then(() => {
App.UI.closeModal();
Controller.showUsers();
Expand Down

0 comments on commit 5ada900

Please sign in to comment.