Skip to content

Commit 4bcdec0

Browse files
committed
feat(Admin Settings): add ssh clone address host setting (Github: #132)
feat #132
1 parent 1ad489a commit 4bcdec0

File tree

9 files changed

+43
-6
lines changed

9 files changed

+43
-6
lines changed

application/models/user_model.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function normalize(array $list, bool $extra = FALSE)
3636
'unReadNotification' => $extra ? $this->notificationModel->unReadNotificationCount($item['u_key']) : 0,
3737
'status' => $item['u_status'] == COMMON_STATUS_NORMAL,
3838
'host' => YAML_HOST,
39+
'ssh' => YAML_SSH,
3940
]);
4041
}
4142
return $result;

config.template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
host: http://localhost
3+
ssh: 'git@localhost:'
34
allowRegister: true
45
email:
56
name: CodeFever Community

www/view/src/components/unit/RepositoryDashboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class RepositoryDashboard extends Component {
235235
fullWidth
236236
variant='outlined'
237237
value={
238-
NetworkHelper.getSSHHost(currentUserInfo) + ':' +
238+
NetworkHelper.getSSHHost(currentUserInfo) +
239239
[repositoryConfig.group.name, repositoryConfig.repository.name].join('/') +
240240
'.git'
241241
}

www/view/src/components/view/admin/Settings.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Settings extends React.Component {
3535
this.state = {
3636
allowRegister: false,
3737
host: '',
38+
ssh: '',
3839
email_from: '',
3940
email_name: '',
4041
pending: true,
@@ -55,7 +56,15 @@ class Settings extends React.Component {
5556
passPattern: /^http(s)?:\/\/[^/]+$/,
5657
errorMessage: this.props.intl.formatMessage(
5758
{ id: 'message.error._S_invalid' },
58-
{ s: this.props.intl.formatMessage({ id: 'label.url' }) }
59+
{ s: this.props.intl.formatMessage({ id: 'label.urlPrefix' }) }
60+
)
61+
},
62+
{
63+
name: 'ssh',
64+
passPattern: /^[^@]+@.+$/,
65+
errorMessage: this.props.intl.formatMessage(
66+
{ id: 'message.error._S_invalid' },
67+
{ s: this.props.intl.formatMessage({ id: 'label.sshPrefix' }) }
5968
)
6069
},
6170
{
@@ -103,6 +112,7 @@ class Settings extends React.Component {
103112
this.setState({
104113
pending: false,
105114
host: data.data.host,
115+
ssh: data.data.ssh,
106116
allowRegister: data.data.allowRegister,
107117
email_from: data.data.email.from,
108118
email_name: data.data.email.name
@@ -118,6 +128,7 @@ class Settings extends React.Component {
118128

119129
const data = {
120130
host: this.state.host,
131+
ssh: this.state.ssh,
121132
allowRegister: this.state.allowRegister,
122133
email: { name: this.state.email_name, from: this.state.email_from }
123134
}
@@ -159,13 +170,13 @@ class Settings extends React.Component {
159170
<Grid item xs={12}>
160171
<Paper className={classes.paper}>
161172
<Grid container spacing={2}>
162-
<Grid item xs={12}>
173+
<Grid item xs={12}>
163174
<Typography variant='h6' component='div' gutterBottom> {intl.formatMessage({ id: 'label.host' })} </Typography>
164175
</Grid>
165176
<Grid item xs={12} mg={9} lg={8}>
166177
<Grid container spacing={2}>
167178
<Grid item xs={12}>
168-
<Typography variant='subtitle1' component='div' gutterBottom> {intl.formatMessage({ id: 'label.url' })} </Typography>
179+
<Typography variant='subtitle1' component='div' gutterBottom> {intl.formatMessage({ id: 'label.urlPrefix' })} </Typography>
169180
</Grid>
170181
<Grid item xs={12}>
171182
<TextField
@@ -174,10 +185,24 @@ class Settings extends React.Component {
174185
value={this.state.host}
175186
error={!!this.state.error.host}
176187
helperText={this.state.error.host}
177-
placeholder={intl.formatMessage({ id: 'label.url' })}
188+
placeholder={intl.formatMessage({ id: 'label.urlPrefix' })}
178189
onChange={e => this.setState({ host: e.target.value })}
179190
/>
180191
</Grid>
192+
<Grid item xs={12}>
193+
<Typography variant='subtitle1' component='div' gutterBottom> {intl.formatMessage({ id: 'label.sshPrefix' })} </Typography>
194+
</Grid>
195+
<Grid item xs={12}>
196+
<TextField
197+
fullWidth
198+
variant='outlined'
199+
value={this.state.ssh}
200+
error={!!this.state.error.ssh}
201+
helperText={this.state.error.ssh}
202+
placeholder={intl.formatMessage({ id: 'label.sshPrefix' })}
203+
onChange={e => this.setState({ ssh: e.target.value })}
204+
/>
205+
</Grid>
181206
</Grid>
182207
</Grid>
183208
<Grid item xs={12}>&nbsp;</Grid>

www/view/src/helpers/NetworkHelper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ function getHost (userinfo) {
8787
}
8888

8989
function getSSHHost (userinfo) {
90-
return userinfo && 'git@' + userinfo.host.replace('http://', '').replace('https://', '')
90+
return userinfo && userinfo.ssh
91+
? userinfo.ssh
92+
: 'git@' + userinfo.host.replace('http://', '').replace('https://', '')
9193
}
9294

9395
function makeSlug (input) {

www/view/src/lang/en-us/Label.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ const data = {
181181
senderAddress: 'Sender Email Address',
182182
register: 'Register',
183183
allowRegister: 'Allow Register',
184+
urlPrefix: [Phrase.url, Phrase.prefix].join(phraseSeperator),
185+
sshPrefix: [Phrase.ssh, Phrase.prefix].join(phraseSeperator),
184186

185187
support: 'Technical Support',
186188
feedback: 'Submit Feedback',

www/view/src/lang/en-us/Phrase.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const data = {
1717
source: 'Source',
1818
target: 'Target',
1919
url: 'URL',
20+
ssh: 'SSH',
2021
slug: 'Slug',
22+
prefix: 'Prefix',
2123
avatar: 'Avatar',
2224
icon: 'Icon',
2325
joinedAt: 'Joined In',

www/view/src/lang/zh-cn/Label.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ const data = {
181181
senderAddress: '发件人地址',
182182
register: '注册',
183183
allowRegister: '开放注册',
184+
urlPrefix: [Phrase.url, ' ', Phrase.prefix].join(phraseSeperator),
185+
sshPrefix: [Phrase.ssh, ' ', Phrase.prefix].join(phraseSeperator),
184186

185187
support: '技术支持',
186188
feedback: '提交反馈',

www/view/src/lang/zh-cn/Phrase.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const data = {
1717
source: '源',
1818
target: '目标',
1919
url: 'URL',
20+
ssh: 'SSH',
2021
slug: '标识串',
22+
prefix: '前缀',
2123
avatar: '头像',
2224
icon: '图标',
2325
joinedAt: '加入时间',

0 commit comments

Comments
 (0)