-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a facility to set an SVN Password (#280)
* Initial run at adding a SVN Password functionality. * Linting and alerts * Add some TODOs * Remove the custom code to check for plugin committer / theme author status, and use the user_meta instead. * Use WordPress.org provided functions to set / check for a password in use. * typo * Linting fixes. * Remove nested terninaries * Switch to a dedicated rest api endpoint to generate the SVN password. * Require 2FA validation to enter the SVN password screen. * Linting. * Switch to 'Generate Password' rather than Request. * JSX * Simplify description of the Account Overview SVN password tab. * Remove "forget password", these passwords are random and cannot be remembered. * The SVN password is required to commit * Switch to using the Copy to clipboard component. * Temporarily limit access to the SVN Password interface to beta users only, until the systems side is finalised. * Linting: remove unused function. * Add some verbose about subversion text. * Expand upon the text, combine paragraphs, list the case-sensitive username. * When the SVN password functions aren't available, just return that the user doesn't have a password set, and an explanation instead of a SVN password. * Updated interface design * Add a case-sensitive remark when a username is not all lowercase. * Use a list, add spacing. * Convert the Copy-to-clipboard button into a link. * Add the Generation date * Fill in the creation date to avoid a lag in the UI updating. * Update the account overview text. * Add action container to the svn button to match other views. * Update copy for svn blurb. * Add copy intro class to maintain same spacing with other views * Harmonize security keys and svn password detail styles. * Add more contextual language to submit button. * Update copy to SVN Credentials. * Change props for CopyToClipboard button since it's reused here. * Fix linter issue. * Lowercase status text. That's the new standard. * Enable the UI for all SVN-related users. --------- Co-authored-by: StevenDufresne <dufresnesteven@gmail.com>
- Loading branch information
1 parent
49f063a
commit 19d8f88
Showing
13 changed files
with
2,696 additions
and
2,795 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
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,127 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import { Button } from '@wordpress/components'; | ||
import { useCallback, useContext, useMemo, useState } from '@wordpress/element'; | ||
import { refreshRecord } from '../utilities/common'; | ||
import CopyToClipboardButton from './copy-to-clipboard-button'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { GlobalContext } from '../script'; | ||
|
||
/** | ||
* Render the Email setting. | ||
*/ | ||
export default function SVNPassword() { | ||
const { | ||
user: { userRecord }, | ||
setError, | ||
} = useContext( GlobalContext ); | ||
|
||
const [ isGenerating, setGenerating ] = useState( false ); | ||
const [ generatedPassword, setGeneratedPassword ] = useState( '' ); | ||
|
||
// Generate a new SVN Password. | ||
const handleGenerate = useCallback( async () => { | ||
try { | ||
setGenerating( true ); | ||
|
||
const response = await apiFetch( { | ||
path: '/wporg-two-factor/1.0/generate-svn-password', | ||
method: 'POST', | ||
data: { | ||
user_id: userRecord.record.id, | ||
}, | ||
} ); | ||
|
||
// Fill in the creation date in the user record, we'll refresh it for the actual data below. | ||
userRecord.record.svn_password_created = new Date().toISOString(); | ||
|
||
setGeneratedPassword( response.svn_password ); | ||
setGenerating( false ); | ||
|
||
await refreshRecord( userRecord ); | ||
} catch ( apiFetchError ) { | ||
setError( apiFetchError ); | ||
} | ||
} ); | ||
|
||
const getButtonText = useMemo( () => { | ||
if ( isGenerating ) { | ||
return 'Generating...'; | ||
} | ||
|
||
if ( ! userRecord.record.svn_password_created ) { | ||
return 'Generate Password'; | ||
} | ||
|
||
return 'Regenerate Password'; | ||
}, [ isGenerating, userRecord.record.svn_password_created ] ); | ||
|
||
return ( | ||
<> | ||
<p> | ||
WordPress.org uses Subversion (SVN) for version control, providing each hosted | ||
plugin and theme with a repository that the author can commit to. For information on | ||
using SVN, please see the{ ' ' } | ||
<a href="https://developer.wordpress.org/plugins/wordpress-org/how-to-use-subversion/"> | ||
WordPress.org Plugin Developer Handbook | ||
</a> | ||
. | ||
</p> | ||
|
||
<p className="wporg-2fa__screen-intro"> | ||
For security, your WordPress.org account password should not be used to commit to | ||
SVN, use a separate SVN password, which you can generate here. | ||
</p> | ||
|
||
<h4>Details</h4> | ||
<ul> | ||
<li> | ||
Username: <code>{ userRecord.record.username }</code>{ ' ' } | ||
{ userRecord.record.username.match( /[^a-z0-9]/ ) && <>(case-sensitive)</> } | ||
</li> | ||
<li> | ||
Password:{ ' ' } | ||
{ generatedPassword || userRecord.record.svn_password_created ? ( | ||
<> | ||
<code>{ generatedPassword || 'svn_*****************' }</code> | ||
| ||
{ generatedPassword && ( | ||
<CopyToClipboardButton | ||
variant="link" | ||
contents={ generatedPassword } | ||
/> | ||
) } | ||
{ userRecord.record.svn_password_created && ( | ||
<div className="wporg-2fa__svn-password_generated"> | ||
Generated on{ ' ' } | ||
{ new Date( | ||
userRecord.record.svn_password_created | ||
).toLocaleDateString() } | ||
</div> | ||
) } | ||
</> | ||
) : ( | ||
<> | ||
<em>Not configured</em> | ||
</> | ||
) } | ||
</li> | ||
</ul> | ||
<div className="wporg-2fa__submit-actions"> | ||
<Button | ||
variant="secondary" | ||
onClick={ handleGenerate } | ||
isBusy={ isGenerating } | ||
disabled={ isGenerating } | ||
> | ||
{ getButtonText } | ||
</Button> | ||
</div> | ||
</> | ||
); | ||
} |
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,26 @@ | ||
.wporg-2fa__svn-password { | ||
code { | ||
display: inline-block; | ||
padding: 0 3px; | ||
background: var(--wp--preset--color--light-grey-2, #f6f6f6); | ||
border-radius: 2px; | ||
} | ||
|
||
ul { | ||
padding-top: 16px; | ||
|
||
li:not(:last-child) { | ||
margin-bottom: 8px; | ||
|
||
.wporg-2fa__svn-password_generated { | ||
color: var(--wp--preset--color--charcoal-4, #656a71); | ||
} | ||
} | ||
} | ||
|
||
.wporg-2fa__svn-password_generated { | ||
padding-top: 4px; | ||
font-size: 12px; | ||
color: var(--wp--preset--color--charcoal-4, #656a71); | ||
} | ||
} |
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.