Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6921)

Unified Diff: chrome/browser/resources/md_bookmarks/util.js

Issue 2912893002: MD Bookmarks: Support policies for disabling bookmark editing (Closed)
Patch Set: Add lotsa tests Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_bookmarks/util.js
diff --git a/chrome/browser/resources/md_bookmarks/util.js b/chrome/browser/resources/md_bookmarks/util.js
index 2a9de6a1ab7041c2a8fba9e3fe326c3f60ccdc0b..805dd52f9063949211ace2b95cfa1ba057ec9d77 100644
--- a/chrome/browser/resources/md_bookmarks/util.js
+++ b/chrome/browser/resources/md_bookmarks/util.js
@@ -71,6 +71,7 @@ cr.define('bookmarks.util', function() {
selectedFolder: '0',
closedFolders: new Set(),
prefs: {
+ canEdit: true,
incognitoAvailability: IncognitoAvailability.ENABLED,
},
search: {
@@ -93,6 +94,31 @@ cr.define('bookmarks.util', function() {
return !!state.search.term && !state.search.inProgress;
}
+ /**
+ * Returns true if the node with ID |itemId| is unmodifiable. This should only
+ * be used to disable operations which act on the node itself (eg, rename),
+ * as it might still be possible to modify this node's children.
+ * @param {BookmarksPageState} state
+ * @param {string} itemId
+ * @return {boolean}
+ */
calamity 2017/06/09 06:47:31 It's definitely worth mentioning here how unmodifi
tsergeant 2017/06/13 03:13:10 Done.
+ function isNodeUnmodifiable(state, itemId) {
+ return areChildrenUnmodifiable(state, itemId) ||
+ state.nodes[itemId].parentId == ROOT_NODE_ID;
+ }
+
+ /**
+ * Returns true if it is not possible to modify the children of the node with
+ * ID |itemId|. This includes rearranging the children or adding new ones.
+ * @param {BookmarksPageState} state
+ * @param {string} itemId
+ * @return {boolean}
+ */
+ function areChildrenUnmodifiable(state, itemId) {
calamity 2017/06/09 06:47:31 As discussed, it would be good to invert these 2 f
tsergeant 2017/06/13 03:13:10 Done.
+ return !state.prefs.canEdit || !!state.nodes[itemId].unmodifiable ||
+ itemId == ROOT_NODE_ID;
+ }
+
/**
* @param {string} id
* @param {NodeMap} nodes
@@ -166,10 +192,12 @@ cr.define('bookmarks.util', function() {
}
return {
+ areChildrenUnmodifiable: areChildrenUnmodifiable,
createEmptyState: createEmptyState,
getDescendants: getDescendants,
getDisplayedList: getDisplayedList,
hasChildFolders: hasChildFolders,
+ isNodeUnmodifiable: isNodeUnmodifiable,
isShowingSearch: isShowingSearch,
normalizeNode: normalizeNode,
normalizeNodes: normalizeNodes,

Powered by Google App Engine
This is Rietveld 408576698