Configure iPhone Git commit identity (#76)
This commit is contained in:
1 parent
e45ad07c89
commit
009db5cbcf
10 files changed
+392
-37
No files matched your search
@@ -190,6 +190,7 @@ struct ActiveMobileLease {
|
||||
|
||||
struct MobileAuthenticationStatus {
|
||||
biometric_unlock_enabled: bool,
|
||||
git_identity: GitIdentity,
|
||||
active: Option<ActiveMobileLease>,
|
||||
next_editor_id: u64,
|
||||
editors: BTreeMap<u64, MobileEntryDraft>,
|
||||
@@ -226,6 +227,7 @@ impl MobileAuthentication {
|
||||
Ok(Self {
|
||||
status: Mutex::new(MobileAuthenticationStatus {
|
||||
biometric_unlock_enabled: config.biometric_unlock_enabled(),
|
||||
git_identity: config.git_identity().clone(),
|
||||
active: None,
|
||||
next_editor_id: 0,
|
||||
editors: BTreeMap::new(),
|
||||
@@ -394,6 +396,29 @@ impl MobileAuthentication {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn git_identity(&self) -> Result<GitIdentity, MobileAuthenticationError> {
|
||||
Ok(self.status()?.git_identity.clone())
|
||||
}
|
||||
|
||||
pub fn set_git_identity(
|
||||
&self,
|
||||
name: String,
|
||||
email: String,
|
||||
) -> Result<GitIdentity, MobileAuthenticationError> {
|
||||
let identity = GitIdentity::new(name, email).map_err(|_| {
|
||||
MobileAuthenticationError::new(
|
||||
MobileAuthenticationErrorKind::Configuration,
|
||||
"Git Identity Is Invalid",
|
||||
"Enter a non-empty name and email without line breaks or angle brackets.",
|
||||
)
|
||||
})?;
|
||||
self.config
|
||||
.update_git_identity(&identity)
|
||||
.map_err(config_error)?;
|
||||
self.status()?.git_identity = identity.clone();
|
||||
Ok(identity)
|
||||
}
|
||||
|
||||
pub fn touch_user_activity(&self) -> Result<(), MobileAuthenticationError> {
|
||||
let status = self.status()?;
|
||||
let active = status.active.as_ref().ok_or_else(|| {
|
||||
@@ -483,17 +508,18 @@ impl MobileAuthentication {
|
||||
&self,
|
||||
request: MobileMutationRequest,
|
||||
) -> Result<MobileMutationOutcome, MobileAuthenticationError> {
|
||||
let (handle, key) = {
|
||||
let (handle, key, identity) = {
|
||||
let status = self.status()?;
|
||||
let active = status.active.as_ref().ok_or_else(locked_error)?;
|
||||
(active.handle.clone(), active.key.clone())
|
||||
(
|
||||
active.handle.clone(),
|
||||
active.key.clone(),
|
||||
status.git_identity.clone(),
|
||||
)
|
||||
};
|
||||
let mut committer = AutomaticTreeCommitter::for_source(
|
||||
&self.repository,
|
||||
&request.source,
|
||||
GitIdentity::ironstorage(),
|
||||
)
|
||||
.map_err(git_mutation_error)?;
|
||||
let mut committer =
|
||||
AutomaticTreeCommitter::for_source(&self.repository, &request.source, identity)
|
||||
.map_err(git_mutation_error)?;
|
||||
let has_open_editor = self.editor_state(&request.source)?.0;
|
||||
let editors = if has_open_editor && request.discard_editor {
|
||||
self.take_entry_editors(&request.source)?
|
||||
@@ -632,9 +658,9 @@ impl MobileAuthentication {
|
||||
document
|
||||
.replace_field_value(EntryFieldId::from_value(field), value.into_bytes())
|
||||
.map_err(document_error)?;
|
||||
let mut committer =
|
||||
AutomaticEntryCommitter::for_entry(&self.repository, path, GitIdentity::ironstorage())
|
||||
.map_err(|error| entry_detail("Password Entry Could Not Be Saved", error))?;
|
||||
let identity = self.git_identity()?;
|
||||
let mut committer = AutomaticEntryCommitter::for_entry(&self.repository, path, identity)
|
||||
.map_err(|error| entry_detail("Password Entry Could Not Be Saved", error))?;
|
||||
EntryDocumentService::new(&self.repository, &self.keys)
|
||||
.save_recoverable(&document, None, &mut committer)
|
||||
.map_err(document_error)?;
|
||||
@@ -795,17 +821,15 @@ impl MobileAuthentication {
|
||||
return Err(editor_error(error));
|
||||
}
|
||||
let path = draft.document().path().to_string();
|
||||
let mut committer = match AutomaticEntryCommitter::for_entry(
|
||||
&self.repository,
|
||||
&path,
|
||||
GitIdentity::ironstorage(),
|
||||
) {
|
||||
Ok(committer) => committer,
|
||||
Err(error) => {
|
||||
self.restore_editor(editor, draft)?;
|
||||
return Err(entry_detail("Password Entry Could Not Be Saved", error));
|
||||
}
|
||||
};
|
||||
let identity = self.git_identity()?;
|
||||
let mut committer =
|
||||
match AutomaticEntryCommitter::for_entry(&self.repository, &path, identity) {
|
||||
Ok(committer) => committer,
|
||||
Err(error) => {
|
||||
self.restore_editor(editor, draft)?;
|
||||
return Err(entry_detail("Password Entry Could Not Be Saved", error));
|
||||
}
|
||||
};
|
||||
if let Err(error) = EntryDocumentService::new(&self.repository, &self.keys)
|
||||
.save_recoverable(draft.document(), None, &mut committer)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user