Skip to content

Commit 62545e7

Browse files
committed
In web UI, disallow commit of other users' changes (but still show diffs)
Also cleans up text at the top of the page.
1 parent f3f74ac commit 62545e7

File tree

4 files changed

+106
-86
lines changed

4 files changed

+106
-86
lines changed

git-webui/release/share/git-webui/webui/css/git-webui.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,26 @@ body {
560560
border-right: 0;
561561
white-space: nowrap;
562562
}
563+
#workspace-view #workspace-editor #working-copy-view .file-list-container .list-group .list-group-item.available,
564+
#commit-explorer-view #workspace-editor #working-copy-view .file-list-container .list-group .list-group-item.available,
565+
#workspace-view #commit-explorer-navigator-view #working-copy-view .file-list-container .list-group .list-group-item.available,
566+
#commit-explorer-view #commit-explorer-navigator-view #working-copy-view .file-list-container .list-group .list-group-item.available,
567+
#workspace-view #workspace-editor #staging-area-view .file-list-container .list-group .list-group-item.available,
568+
#commit-explorer-view #workspace-editor #staging-area-view .file-list-container .list-group .list-group-item.available,
569+
#workspace-view #commit-explorer-navigator-view #staging-area-view .file-list-container .list-group .list-group-item.available,
570+
#commit-explorer-view #commit-explorer-navigator-view #staging-area-view .file-list-container .list-group .list-group-item.available {
571+
cursor: pointer;
572+
}
573+
#workspace-view #workspace-editor #working-copy-view .file-list-container .list-group .list-group-item.unavailable,
574+
#commit-explorer-view #workspace-editor #working-copy-view .file-list-container .list-group .list-group-item.unavailable,
575+
#workspace-view #commit-explorer-navigator-view #working-copy-view .file-list-container .list-group .list-group-item.unavailable,
576+
#commit-explorer-view #commit-explorer-navigator-view #working-copy-view .file-list-container .list-group .list-group-item.unavailable,
577+
#workspace-view #workspace-editor #staging-area-view .file-list-container .list-group .list-group-item.unavailable,
578+
#commit-explorer-view #workspace-editor #staging-area-view .file-list-container .list-group .list-group-item.unavailable,
579+
#workspace-view #commit-explorer-navigator-view #staging-area-view .file-list-container .list-group .list-group-item.unavailable,
580+
#commit-explorer-view #commit-explorer-navigator-view #staging-area-view .file-list-container .list-group .list-group-item.unavailable {
581+
cursor: not-allowed;
582+
}
563583
#workspace-view #workspace-editor #commit-message-view,
564584
#commit-explorer-view #workspace-editor #commit-message-view,
565585
#workspace-view #commit-explorer-navigator-view #commit-message-view,

git-webui/release/share/git-webui/webui/js/git-webui.js

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,37 +1460,47 @@ webui.ChangedFilesView = function(workspaceView, type, label) {
14601460
$(fileList).empty()
14611461
var col = type == "working-copy" ? 1 : 0;
14621462
webui.git("status --porcelain", function(data) {
1463-
self.filesCount = 0;
1464-
webui.splitLines(data).forEach(function(line) {
1465-
var status = line[col];
1466-
if (col == 0 && status != " " && status != "?" || col == 1 && status != " ") {
1467-
++self.filesCount;
1468-
var item = $('<a class="list-group-item">').appendTo(fileList)[0];
1469-
item.status = status;
1470-
line = line.substr(3);
1471-
var splitted = line.split(" -> ");
1472-
if (splitted.length > 1) {
1473-
item.model = splitted[1];
1474-
} else {
1475-
item.model = line
1463+
$.get("api/uncommitted", function (uncommitted) {
1464+
var uncommittedItems = JSON.parse(uncommitted);
1465+
self.filesCount = 0;
1466+
webui.splitLines(data).forEach(function(line) {
1467+
var status = line[col];
1468+
if (col == 0 && status != " " && status != "?" || col == 1 && status != " ") {
1469+
++self.filesCount;
1470+
line = line.substr(3);
1471+
var splitted = line.split(" -> ");
1472+
var model;
1473+
if (splitted.length > 1) {
1474+
model = splitted[1];
1475+
} else {
1476+
model = line;
1477+
}
1478+
var isForCurrentUser = (uncommittedItems.indexOf(model) > -1);
1479+
var cssClass = isForCurrentUser ? 'list-group-item available' : 'list-group-item unavailable';
1480+
1481+
var item = $('<a class="'+cssClass+'">').appendTo(fileList)[0];
1482+
item.model = model;
1483+
item.status = status;
1484+
item.appendChild(document.createTextNode(line));
1485+
$(item).click(self.select);
1486+
if (isForCurrentUser) {
1487+
$(item).dblclick(self.process);
1488+
}
1489+
}
1490+
});
1491+
if (selectedIndex !== null && selectedIndex >= fileList.childElementCount) {
1492+
selectedIndex = fileList.childElementCount - 1;
1493+
if (selectedIndex == -1) {
1494+
selectedIndex = null;
14761495
}
1477-
item.appendChild(document.createTextNode(line));
1478-
$(item).click(self.select);
1479-
$(item).dblclick(self.process);
14801496
}
1481-
});
1482-
if (selectedIndex !== null && selectedIndex >= fileList.childElementCount) {
1483-
selectedIndex = fileList.childElementCount - 1;
1484-
if (selectedIndex == -1) {
1485-
selectedIndex = null;
1497+
if (selectedIndex !== null) {
1498+
var selectedNode = fileList.children[selectedIndex];
1499+
$(selectedNode).addClass("active");
1500+
self.refreshDiff(selectedNode);
14861501
}
1487-
}
1488-
if (selectedIndex !== null) {
1489-
var selectedNode = fileList.children[selectedIndex];
1490-
$(selectedNode).addClass("active");
1491-
self.refreshDiff(selectedNode);
1492-
}
1493-
fileListContainer.scrollTop = prevScrollTop;
1502+
fileListContainer.scrollTop = prevScrollTop;
1503+
});
14941504
});
14951505
};
14961506

@@ -1549,7 +1559,7 @@ webui.ChangedFilesView = function(workspaceView, type, label) {
15491559
var child = fileList.children[i];
15501560
var included = including == undefined || including.indexOf(child.status) != -1;
15511561
var excluded = excluding != undefined && excluding.indexOf(child.status) != -1;
1552-
if ($(child).hasClass("active") && included && !excluded) {
1562+
if ($(child).hasClass("active") && $(child).hasClass("available") && included && !excluded) {
15531563
files += '"' + (child.model) + '" ';
15541564
}
15551565
}
@@ -1686,20 +1696,6 @@ function MainUi() {
16861696
self.mainView.appendChild(element);
16871697
}
16881698

1689-
//api to to display username and email at top of page
1690-
//format needs to be edited
1691-
$.get("api/userinfo", function (data) {
1692-
var body = $("body")[0];
1693-
var obj = JSON.parse(data)
1694-
body.innerHTML += "User: " + obj.name + " Email: " + obj.email;
1695-
});
1696-
1697-
$.get("api/uncommitted", function (data) {
1698-
var body = $("body")[0];
1699-
var obj = JSON.parse(data)
1700-
body.innerHTML += data;
1701-
});
1702-
17031699
$.get("dirname", function (data) {
17041700
webui.repo = data;
17051701
var title = $("title")[0];

git-webui/src/share/git-webui/webui/css/git-webui.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,14 @@ body {
560560
border-right: 0;
561561
white-space: nowrap;
562562
}
563+
564+
.list-group-item.available {
565+
cursor: pointer;
566+
}
567+
568+
.list-group-item.unavailable {
569+
cursor: not-allowed;
570+
}
563571
}
564572
}
565573
}

git-webui/src/share/git-webui/webui/js/git-webui.js

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,37 +1460,47 @@ webui.ChangedFilesView = function(workspaceView, type, label) {
14601460
$(fileList).empty()
14611461
var col = type == "working-copy" ? 1 : 0;
14621462
webui.git("status --porcelain", function(data) {
1463-
self.filesCount = 0;
1464-
webui.splitLines(data).forEach(function(line) {
1465-
var status = line[col];
1466-
if (col == 0 && status != " " && status != "?" || col == 1 && status != " ") {
1467-
++self.filesCount;
1468-
var item = $('<a class="list-group-item">').appendTo(fileList)[0];
1469-
item.status = status;
1470-
line = line.substr(3);
1471-
var splitted = line.split(" -> ");
1472-
if (splitted.length > 1) {
1473-
item.model = splitted[1];
1474-
} else {
1475-
item.model = line
1463+
$.get("api/uncommitted", function (uncommitted) {
1464+
var uncommittedItems = JSON.parse(uncommitted);
1465+
self.filesCount = 0;
1466+
webui.splitLines(data).forEach(function(line) {
1467+
var status = line[col];
1468+
if (col == 0 && status != " " && status != "?" || col == 1 && status != " ") {
1469+
++self.filesCount;
1470+
line = line.substr(3);
1471+
var splitted = line.split(" -> ");
1472+
var model;
1473+
if (splitted.length > 1) {
1474+
model = splitted[1];
1475+
} else {
1476+
model = line;
1477+
}
1478+
var isForCurrentUser = (uncommittedItems.indexOf(model) > -1);
1479+
var cssClass = isForCurrentUser ? 'list-group-item available' : 'list-group-item unavailable';
1480+
1481+
var item = $('<a class="'+cssClass+'">').appendTo(fileList)[0];
1482+
item.model = model;
1483+
item.status = status;
1484+
item.appendChild(document.createTextNode(line));
1485+
$(item).click(self.select);
1486+
if (isForCurrentUser) {
1487+
$(item).dblclick(self.process);
1488+
}
1489+
}
1490+
});
1491+
if (selectedIndex !== null && selectedIndex >= fileList.childElementCount) {
1492+
selectedIndex = fileList.childElementCount - 1;
1493+
if (selectedIndex == -1) {
1494+
selectedIndex = null;
14761495
}
1477-
item.appendChild(document.createTextNode(line));
1478-
$(item).click(self.select);
1479-
$(item).dblclick(self.process);
14801496
}
1481-
});
1482-
if (selectedIndex !== null && selectedIndex >= fileList.childElementCount) {
1483-
selectedIndex = fileList.childElementCount - 1;
1484-
if (selectedIndex == -1) {
1485-
selectedIndex = null;
1497+
if (selectedIndex !== null) {
1498+
var selectedNode = fileList.children[selectedIndex];
1499+
$(selectedNode).addClass("active");
1500+
self.refreshDiff(selectedNode);
14861501
}
1487-
}
1488-
if (selectedIndex !== null) {
1489-
var selectedNode = fileList.children[selectedIndex];
1490-
$(selectedNode).addClass("active");
1491-
self.refreshDiff(selectedNode);
1492-
}
1493-
fileListContainer.scrollTop = prevScrollTop;
1502+
fileListContainer.scrollTop = prevScrollTop;
1503+
});
14941504
});
14951505
};
14961506

@@ -1549,7 +1559,7 @@ webui.ChangedFilesView = function(workspaceView, type, label) {
15491559
var child = fileList.children[i];
15501560
var included = including == undefined || including.indexOf(child.status) != -1;
15511561
var excluded = excluding != undefined && excluding.indexOf(child.status) != -1;
1552-
if ($(child).hasClass("active") && included && !excluded) {
1562+
if ($(child).hasClass("active") && $(child).hasClass("available") && included && !excluded) {
15531563
files += '"' + (child.model) + '" ';
15541564
}
15551565
}
@@ -1686,20 +1696,6 @@ function MainUi() {
16861696
self.mainView.appendChild(element);
16871697
}
16881698

1689-
//api to to display username and email at top of page
1690-
//format needs to be edited
1691-
$.get("api/userinfo", function (data) {
1692-
var body = $("body")[0];
1693-
var obj = JSON.parse(data)
1694-
body.innerHTML += "User: " + obj.name + " Email: " + obj.email;
1695-
});
1696-
1697-
$.get("api/uncommitted", function (data) {
1698-
var body = $("body")[0];
1699-
var obj = JSON.parse(data)
1700-
body.innerHTML += data;
1701-
});
1702-
17031699
$.get("dirname", function (data) {
17041700
webui.repo = data;
17051701
var title = $("title")[0];

0 commit comments

Comments
 (0)