Skip to content

Commit ec339bd

Browse files
committed
Add selector to copy permissions from another container
1 parent a5ebf61 commit ec339bd

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

src/ui/options.css

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,23 @@ fieldset:disabled {
8484
#newsite {
8585
flex: 2 2;
8686
}
87+
88+
.per-site-buttons {
89+
display: flex;
90+
flex-flow: row wrap;
91+
justify-content: flex-end;
92+
width: 100%;
93+
text-align: right;
94+
margin: .5em 0 0 0;
95+
}
8796
#btn-clear-container {
88-
margin-top: .5em;
97+
margin-inline-start: .5em;
98+
}
99+
#copy-container {
100+
margin-inline: .5em;
101+
}
102+
#copy-container-label {
103+
margin-block: .5em;
89104
}
90105

91106
#policy {

src/ui/options.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ <h3 class="flextabs__tab"><button class="flextabs__toggle enforcement_required">
7070
<div class="flextabs__content">
7171
<label for="select-container">Choose a container:</label>
7272
<select name="select-container" id="select-container">
73-
<option value="default">Default</option>
73+
<option value="default">Default</option>
7474
</select>
7575
<section class="sect-sites">
7676
<form id="form-newsite" class="browser-style" >
@@ -82,7 +82,14 @@ <h3 class="flextabs__tab"><button class="flextabs__toggle enforcement_required">
8282
<div class="cssload-whirlpool"></div>
8383
</div>
8484
</div>
85-
<button id="btn-clear-container">Clear permissions for this container</button>
85+
<div class="per-site-buttons">
86+
<label for="copy-container" id="copy-container-label">Copy permissions from container:</label>
87+
<select name="copy-container" id="copy-container">
88+
<option value="default">Default</option>
89+
</select>
90+
<div style="inline-size:0;margin-inline:.5em;border:1px solid #888"></div>
91+
<button id="btn-clear-container">Clear permissions for this container</button>
92+
</div>
8693
</section>
8794
</div>
8895

src/ui/options.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
// SITES UI
166166
let sitesUI = new UI.Sites(document.getElementById("sites"));
167167
let containerSelect = document.querySelector("#select-container");
168+
let containerCopy = document.querySelector("#copy-container");
168169
var cookieStoreId = containerSelect.value;
169170
var currentPolicy = await UI.getPolicy(cookieStoreId);
170171

@@ -178,6 +179,23 @@
178179
}
179180
containerSelect.onchange = changeContainer;
180181

182+
async function copyContainer() {
183+
cookieStoreId = containerSelect.value;
184+
let copyCookieStoreId = containerCopy.value;
185+
let copyContainerName = containerCopy.options[containerCopy.selectedIndex].text;
186+
let copyPolicy = await UI.getPolicy(copyCookieStoreId);
187+
if (confirm(`Copying permissions from "${copyContainerName}".\n` + "All site permissions for this container will be removed.\nThis action cannot be reverted.\nDo you want to continue?")) {
188+
sitesUI.clear()
189+
currentPolicy = await UI.replacePolicy(cookieStoreId, new Policy(copyPolicy.dry(true)));
190+
await UI.updateSettings({policy, contextStore});
191+
sitesUI.render(currentPolicy.sites);
192+
}
193+
sitesUI.clear()
194+
sitesUI.policy = currentPolicy;
195+
sitesUI.render(currentPolicy.sites);
196+
}
197+
containerCopy.onchange = copyContainer;
198+
181199
var containers = [];
182200
async function updateContainers() {
183201
let newContainers = [{cookieStoreId: "default", name: "Default"},];
@@ -193,8 +211,10 @@
193211
}
194212
containerSelect.innerHTML = container_options;
195213
containerSelect.value = cookieStoreId;
214+
containerCopy.innerHTML = container_options;
196215
}
197216
containerSelect.onfocus = updateContainers;
217+
containerCopy.onfocus = updateContainers;
198218
await updateContainers();
199219

200220
UI.onSettings = async () => {

src/ui/ui.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ var UI = (() => {
138138
}
139139
},
140140

141+
async replacePolicy(cookieStoreId, policy) {
142+
await this.contextStore.updateContainers(this.policy);
143+
// debug("set policy", cookieStoreId, this.policy, this.contextStore);
144+
if (this.contextStore.policies.hasOwnProperty(cookieStoreId)) {
145+
this.contextStore.policies[cookieStoreId] = policy;
146+
debug("replaced id", cookieStoreId, "with policy", policy);
147+
let currentPolicy = this.contextStore.policies[cookieStoreId];
148+
return currentPolicy;
149+
} else {
150+
this.policy = policy;
151+
debug("replaced default cookiestore", cookieStoreId, "with policy", policy);
152+
return this.policy;
153+
}
154+
},
155+
141156
isDirty(reset = false) {
142157
let currentSnapshot = this.policy.snapshot+this.contextStore.snapshot;
143158
let dirty = currentSnapshot != this.snapshot;

0 commit comments

Comments
 (0)