##// END OF EJS Templates
vcs: Minimal change to expose the shadow repository...
vcs: Minimal change to expose the shadow repository Based on my original research, this was the "minimal" starting point. It shows that three concepts are needed for the "repo_name": * From the security standpoint we think of the shadow repository having the same ACL as the target repository of the pull request. This is because the pull request itself is considered to be a part of the target repository. Out of this thought, the variable "acl_repo_name" is used whenever we want to check permissions or when we need the database configuration of the repository. An alternative name would have been "db_repo_name", but the usage for ACL checking is the most important one. * From the web interaction perspective, we need the URL which was originally used to get to the repository. This is because based on this base URL commands can be identified. Especially for Git this is important, so that the commands are correctly recognized. Since the URL is in the focus, this is called "url_repo_name". * Finally we have to deal with the repository on the file system. This is what the VCS layer deal with normally, so this name is called "vcs_repo_name". The original repository interaction is a special case where all three names are the same. When interacting with a pull request, these three names are typically all different. This change is minimal in a sense that it just makes the interaction with a shadow repository barely work, without checking any special constraints yet. This was the starting point for further work on this topic.

File last commit:

r524:a0b14eeb default
r887:175782be default
Show More
deform.js
194 lines | 7.0 KiB | application/javascript | JavascriptLexer
/*
* Register a top-level callback to the deform.load() function
* this will be called when the DOM has finished loading. No need
* to include the call at the end of the page.
*/
$(document).ready(function(){
deform.load();
});
var deform_loaded = false;
var deform = {
callbacks: [],
addCallback: function (oid, callback) {
deform.callbacks.push([oid, callback]);
},
clearCallbacks: function () {
deform.callbacks = [];
},
load: function() {
$(function() {
if (!deform_loaded) {
deform.processCallbacks();
deform.focusFirstInput();
deform_loaded = true;
}});
},
processCallbacks: function () {
$(deform.callbacks).each(function(num, item) {
var oid = item[0];
var callback = item[1];
callback(oid);
}
);
deform.clearCallbacks();
},
addSequenceItem: function (protonode, before) {
// - Clone the prototype node and add it before the "before" node.
// Also ensure any callbacks are run for the widget.
// In order to avoid breaking accessibility:
//
// - Find each tag within the prototype node with an id
// that has the string ``deformField(\d+)`` within it, and modify
// its id to have a random component.
// - For each label referencing an change id, change the label's
// for attribute to the new id.
var fieldmatch = /deformField(\d+)/;
var namematch = /(.+)?-[#]{3}/;
var code = protonode.attr('prototype');
var html = decodeURIComponent(code);
var $htmlnode = $(html);
var $idnodes = $htmlnode.find('[id]');
var $namednodes = $htmlnode.find('[name]');
var genid = deform.randomString(6);
var idmap = {};
// replace ids containing ``deformField`` and associated label for=
// items which point at them
$idnodes.each(function(idx, node) {
var $node = $(node);
var oldid = $node.attr('id');
var newid = oldid.replace(fieldmatch, "deformField$1-" + genid);
$node.attr('id', newid);
idmap[oldid] = newid;
var labelselector = 'label[for=' + oldid + ']';
var $fornodes = $htmlnode.find(labelselector);
$fornodes.attr('for', newid);
});
// replace names a containing ```deformField`` like we do for ids
$namednodes.each(function(idx, node) {
var $node = $(node);
var oldname = $node.attr('name');
var newname = oldname.replace(fieldmatch, "deformField$1-" + genid);
$node.attr('name', newname);
});
$htmlnode.insertBefore(before);
$(deform.callbacks).each(function(num, item) {
var oid = item[0];
var callback = item[1];
var newid = idmap[oid];
if (newid) {
callback(newid);
}
});
deform.clearCallbacks();
var old_len = parseInt(before.attr('now_len')||'0', 10);
before.attr('now_len', old_len + 1);
// we added something to the dom, trigger a change event
var e = jQuery.Event("change");
$('#deform').trigger(e);
},
appendSequenceItem: function(node) {
var $oid_node = $(node).closest('.deform-seq');
var $proto_node = $oid_node.find('.deform-proto').first();
var $before_node = $oid_node.find('.deform-insert-before').last();
var min_len = parseInt($before_node.attr('min_len')||'0', 10);
var max_len = parseInt($before_node.attr('max_len')||'9999', 10);
var now_len = parseInt($before_node.attr('now_len')||'0', 10);
var orderable = parseInt($before_node.attr('orderable')||'0', 10);
if (now_len < max_len) {
deform.addSequenceItem($proto_node, $before_node);
deform.processSequenceButtons($oid_node, min_len, max_len,
now_len + 1, orderable);
}
return false;
},
removeSequenceItem: function(clicked) {
var $item_node = $(clicked).closest('.deform-seq-item');
var $oid_node = $item_node.closest('.deform-seq');
var $before_node = $oid_node.find('.deform-insert-before').last();
var min_len = parseInt($before_node.attr('min_len')||'0', 10);
var max_len = parseInt($before_node.attr('max_len')||'9999', 10);
var now_len = parseInt($before_node.attr('now_len')||'0', 10);
var orderable = parseInt($before_node.attr('orderable')||'0', 10);
if (now_len > min_len) {
$before_node.attr('now_len', now_len - 1);
$item_node.remove();
deform.processSequenceButtons($oid_node, min_len, max_len,
now_len-1, orderable);
}
// we removed something from the dom, trigger a change event
var e = jQuery.Event("change");
$('#deform').trigger(e);
return false;
},
processSequenceButtons: function(oid_node, min_len, max_len, now_len,
orderable) {
orderable = !!orderable; // convert to bool
var has_multiple = now_len > 1;
var $ul = oid_node.find('.deform-seq-container').not(oid_node.find('.deform-seq-container .deform-seq-container'));
var $lis = $ul.find('.deform-seq-item').not($ul.find('.deform-seq-container .deform-seq-item'));
var show_closebutton = now_len > min_len;
var show_addbutton = now_len < max_len;
$lis.find('.deform-close-button').not($lis.find('.deform-seq-container .deform-close-button')).toggle(show_closebutton);
oid_node.find('.deform-seq-add').not(oid_node.find('.deform-seq-container .deform-seq-add')).toggle(show_addbutton);
$lis.find('.deform-order-button').not($lis.find('.deform-seq-container .deform-order-button')).toggle(orderable && has_multiple);
},
focusFirstInput: function (el) {
el = el || document.body;
var input = $(el).find(':input')
.filter('[id ^= deformField]')
.filter('[type != hidden]')
.first();
if (input) {
var raw = input.get(0);
if (raw) {
if (raw.type === 'text' || raw.type === 'file' ||
raw.type == 'password' || raw.type == 'text' ||
raw.type == 'textarea') {
if (!input.hasClass("hasDatepicker")) {
input.focus();
}
}
}
}
},
randomString: function (length) {
var chr='0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
chr = chr.split('');
if (! length) {
length = Math.floor(Math.random() * chr.length);
}
var str = '';
for (var i = 0; i < length; i++) {
str += chr[Math.floor(Math.random() * chr.length)];
}
return str;
}
};