-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/688: Credentials sharing (#708)
* Implement share credentials --------- Co-authored-by: Mountain Star <[email protected]>
- Loading branch information
Showing
34 changed files
with
1,161 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5.0 | ||
5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# frozen_string_literal: true | ||
|
||
class EncryptableTransferedName | ||
|
||
INCREMENT_REGEX = /\((\d+)\)/ | ||
|
||
def initialize(name, existing_names, is_file) | ||
@name = name | ||
@existing_names = existing_names | ||
@is_file = is_file | ||
end | ||
|
||
def destination_name | ||
destination_name = @name | ||
if @existing_names.present? | ||
similar_names = find_similar_names | ||
if similar_names.present? && similar_names.include?(@name) | ||
similar_names = sort_similar_names(similar_names) | ||
latest_name = similar_names.last | ||
destination_name = copy_name(@name, latest_name) | ||
end | ||
end | ||
|
||
destination_name | ||
end | ||
|
||
def copy_name(name, latest_name) | ||
if @is_file | ||
suffix = File.extname(name) | ||
name = File.basename(name, '.*') | ||
end | ||
|
||
next_copy_name(name, latest_name, suffix) | ||
end | ||
|
||
def sort_similar_names(similar_names) | ||
if @is_file | ||
similar_names.sort_by do |element| | ||
number_match = element.match(/\((\d+)\)/) | ||
number_match ? number_match[1].to_i : 0 | ||
end | ||
else | ||
similar_names.sort | ||
end | ||
end | ||
|
||
def next_copy_name(name, latest_name, suffix) | ||
# Remove (NUMBER) if it already exists in name | ||
if INCREMENT_REGEX.match(name) | ||
name = name.sub(/\(\d+\)\z/, '') | ||
end | ||
|
||
# If last encryptable in inbox has (NUMBER) add (NUMBER + 1) | ||
name += if INCREMENT_REGEX.match(latest_name) | ||
"(#{INCREMENT_REGEX.match(latest_name)[1].to_i + 1})" | ||
else | ||
'(1)' | ||
end | ||
|
||
name += suffix if @is_file | ||
|
||
name | ||
end | ||
|
||
def find_similar_names | ||
suffix = File.extname(@name) | ||
name = File.basename(@name, '.*') | ||
|
||
# For the loop through inbox encryptables remove (NUMBER) from name | ||
name = basename_of_copy(name) | ||
|
||
regex_pattern = /\A#{Regexp.escape(name)}(\(\d+\))?\z/ | ||
@existing_names.select do |existing_name| | ||
current_suffix = File.extname(existing_name) | ||
current_name = File.basename(existing_name, '.*') | ||
current_name.match?(regex_pattern) && current_suffix == suffix | ||
end | ||
end | ||
|
||
def basename_of_copy(name) | ||
basename_regex = /\A.*\(\d+\)\z/ | ||
|
||
if name.match?(basename_regex) | ||
name = name.gsub(/\(\d+\)\z/, '') | ||
end | ||
|
||
name | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { action } from "@ember/object"; | ||
import Changeset from "ember-changeset"; | ||
import { inject as service } from "@ember/service"; | ||
import { tracked } from "@glimmer/tracking"; | ||
import BaseFormComponent from "./base-form-component"; | ||
import ENV from "frontend/config/environment"; | ||
import lookupValidator from "ember-changeset-validations"; | ||
import EncryptableTransferCredential from "../validations/encryptable-transfer-credential"; | ||
|
||
export default class CredentialTransfer extends BaseFormComponent { | ||
@service store; | ||
@service router; | ||
@service navService; | ||
@tracked encryptableId; | ||
@tracked encryptableName; | ||
@tracked candidates; | ||
@tracked receiver; | ||
|
||
constructor() { | ||
super(...arguments); | ||
|
||
this.record = this.store.createRecord("encryptable-transfer"); | ||
|
||
this.changeset = new Changeset( | ||
this.record, | ||
lookupValidator(EncryptableTransferCredential), | ||
EncryptableTransferCredential | ||
); | ||
|
||
this.changeset.csrfToken = ENV.CSRFToken; | ||
|
||
this.encryptableId = this.args.encryptableId; | ||
this.encryptableName = this.args.encryptableName; | ||
this.changeset.encryptableId = this.encryptableId; | ||
|
||
this.loadValidation(); | ||
|
||
this.loadCandidates(); | ||
} | ||
|
||
loadCandidates() { | ||
this.store | ||
.query("user-human", { | ||
candidates: true | ||
}) | ||
.then((res) => (this.candidates = res)); | ||
} | ||
|
||
async loadValidation() { | ||
await this.changeset.validate(); | ||
} | ||
|
||
@action | ||
selectReceiver(receiver) { | ||
this.changeset.receiver = receiver; | ||
this.loadValidation(); | ||
} | ||
|
||
@action | ||
search(input) { | ||
return this.candidates.filter( | ||
(c) => c.label.toLowerCase().indexOf(input.toLowerCase()) >= 0 | ||
); | ||
} | ||
|
||
@action | ||
abort() { | ||
if (this.args.onAbort) { | ||
this.args.onAbort(); | ||
} | ||
} | ||
|
||
showSuccessMessage() { | ||
let msg = this.intl.t( | ||
"flashes.encryptable_transfer.credentials.transferred" | ||
); | ||
this.notify.success(msg); | ||
} | ||
|
||
handleSubmitSuccess() { | ||
this.abort(); | ||
} | ||
|
||
handleSubmitError(response) { | ||
this.errors = JSON.parse(response.body).errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.