-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This change helps user to switch between master keys #27512
Conversation
@sharidas, thanks for your PR! By analyzing the history of the files in this pull request, we identified @DeepDiver1975, @PVince81 and @tomneedham to be potential reviewers. |
I would like to know if the UI part looks ok? |
@felixheidecke Any suggestion? |
@sharidas Could you provide a few screenshots? Would be the fastest way to get feedback ;-) |
settings/js/admin.js
Outdated
$('#confirm-encryption-warning').addClass("hidden"); | ||
} | ||
|
||
if ($('#enableEncryption').prop("checked") == true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always use strict equality ===
.
please setup jshint/jslint, it will show you warnings for this
settings/js/admin.js
Outdated
@@ -41,6 +41,61 @@ $(document).ready(function(){ | |||
$('#encryptionAPI div#EncryptionWarning').toggleClass('hidden'); | |||
}); | |||
|
|||
function selectEncryptionBehavior() { | |||
$('#confirm-encryption-warning').addClass("hidden"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code is difficult to read
I suggest to have only a single method, like "onChange" which then toggles the options based on the conditions.
For example:
$('#encryptionAPI').toggleClass(!userSpecificEncryption, 'hidden')
This way you only need a single row instead of having it appear three times in different functions
settings/js/admin.js
Outdated
}); | ||
|
||
$('#reconfirm-encryption-type').click(function (event) { | ||
console.log("I am clicked the value selected is = ", $('#keyTypeId option:selected').val()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove logging
settings/js/admin.js
Outdated
console.log("I am clicked the value selected is = ", $('#keyTypeId option:selected').val()); | ||
if ($('#keyTypeId option:selected').val() == 'masterkey') { | ||
OC.AppConfig.setValue('encryption', 'useMasterKey', '1'); | ||
location.reload(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function OC.AppConfig.setValue()
does an ajax call, so if you reload the page directly after that there is a slight risk of race condition in which the value isn't completely saved. Usually when reloading the page the browser will abort all ajax connections.
only reload the page once the ajax call finished
<select id="keyTypeId" name="keyType"> | ||
<option value="nokey">Please select an encryption option</option> | ||
<option value="masterkey" <?php echo \OC::$server->getAppConfig()->getValue('encryption', 'useMasterKey', 0) !== 0 ? 'selected' : ''; ?>>Master Key</option> | ||
<option value="customkey">User-specific key</option> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text translation missing, please recheck all the texts and make sure you're using the translation function
e8c665d
to
71b3eda
Compare
@PVince81 I have updated the patch set with the changes mentioned below:
Let me know if the code looks better, else I can refactor again. |
@felixheidecke Below are the screenshots: |
settings/js/admin.js
Outdated
OC.AppConfig.setValue('core', 'encryption_enabled', 'yes'); | ||
OC.AppConfig.setValue("encryption", "encryptHomeStorage", '0'); | ||
OC.AppConfig.setValue('encryption', 'useMasterKey', '1'); | ||
$(document).ajaxStop(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this will break in some cases.
Not only this code is doing ajax calls. There are background processes like the notifications app, the heartbeat, etc that will trigger ajax calls.
A better approach is to use promises:
- adjust
setValue
and other methods to return the result of$.post
or other ajax calls - use
$.when(call1, call2, call3).then(function() { ... })
to find out when all the three calls have finished.
The flow is wrong, "Enable server-side encryption" must always be the first entry. Also, remember that this checkbox "Enable server-side encryption" is about enabling the encryption subsystem/engine in core, not enabling a specific module. The code with the encryption type selection needs to be part of the "Default encryption module" app (aka plugin). Keep in mind that other developers can write their own "Custom encryption module" (aka plugin) in which case the new dropdown is not relevant at all. The encryption module code is in the "apps/encryption" folder. Please move the dropdown logic there. |
Flow as follows:
The dropdown needs a button "Select this mode". |
06754f9
to
80440bd
Compare
@PVince81 Thanks for the review comments. I have updated the PR and below are the changes made in the updated PR:
Let me know how the current PR looks? |
This message shouldn't appear until an encryption type has been selected, because this message is only relevant for user-key mode encryption.
|
Enabling the modes worked fine, nice! |
apps/encryption/js/settings-admin.js
Outdated
|
||
encryptionTypeSelection($("#keyTypeId :selected").val(), "static"); | ||
|
||
OC.AppConfig.getValue("encryption", "useMasterKey", function ($value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: a way to prevent reading these values with ajax would be to append them into the template on the PHP side then read them out with JS.
apps/encryption/js/settings-admin.js
Outdated
//Action to be taken when "Select this mode" button is selected. | ||
$("#select-mode,#keyTypeId").addClass("hidden"); | ||
if($("#keyTypeId :selected").val() === "masterkey") { | ||
$.when(OC.AppConfig.setValue("encryption", "encryptHomeStorage", '0'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this cannot work properly, you didn't adjust OC.AppConfig.setValue
to actually return the ajax object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, the two "setValue" calls do work, but the final callback to reload the page is never called
80440bd
to
f0d7d69
Compare
@PVince81 I have updated the PR for review by making the changes as follows:
Hope the updated PR looks fine. |
37631d0
to
2dc6abe
Compare
Encryption Key: Master Key
Encryption Key: User-specific keys
Command line: Encryption Key : User-specific keys ( ./occ encryption:select-encryption-type user-keys or ./occ encryption:select-encryption-type user-keys -y )
Encryption Key : Master key ( ./occ encryption:select-encryption-type masterkey or ./occ encryption:select-encryption-type masterkey -y )
|
37d5e97
to
1558f08
Compare
Otherwise this looked good in my quick local tests. |
1573616
to
6d3fed3
Compare
apps/encryption/js/settings-admin.js
Outdated
$("#select-mode").click(function () { | ||
//Action to be taken when "Select this mode" button is selected. | ||
$("#loadSpinner").toggleClass("hidden"); | ||
$("#loadSpinner").addClass("loading"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this spinner look ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh, global ids again ? What if another section also has a spinenr called "loadSpinner" ?
Please use class names instead.
The only id that's acceptable here is the parent element #encryptionKeySelection
, so use a selector like #encryptionKeySelection .loading
when toggling or something.
And when toggling please force the value to "true" as you might not know what its previous state is.
6d3fed3
to
17586ef
Compare
apps/encryption/js/settings-admin.js
Outdated
|
||
$("#select-mode").click(function () { | ||
//Action to be taken when "Select this mode" button is selected. | ||
$("#encryptionKeySelection").toggleClass("loading", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks better, right? I have tested the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test it ?
The spinner only shortly appears at the very right of the row and disappears very quickly.
Also looking at the code it looks like it sets the class on the whole container, which looks wrong.
The spinner should have its own div element.
17586ef
to
183f15e
Compare
//Action to be taken when "Select this mode" button is selected. | ||
var $loadSpinner = $('#encryptionKeySelection').find('div.hidden').first(); | ||
$loadSpinner.toggleClass('hidden',false); | ||
$loadSpinner.toggleClass('loading',true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the modification by having the div for spinner. And now atleast the spinner doesn't vanish quickly.
Signed-off-by: Sujith H <[email protected]>
183f15e
to
263adeb
Compare
Looks good now 👍 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
and user specific keys.
Signed-off-by: Sujith H [email protected]
Description
This change helps us to make master key as default for encryption instead of default configuration we had.
Related Issue
fixes #26847
Motivation and Context
How Has This Been Tested?
Testing yet to be done. This has only UI change.
Screenshots (if appropriate):
Types of changes
Checklist: