Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
873ea6bb
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
873ea6bb
编写于
12月 06, 2016
作者:
L
lepdou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor email builder
上级
f144fe06
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
73 addition
and
27 deletion
+73
-27
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/ConfigPublishEmailBuilder.java
...al/components/emailbuilder/ConfigPublishEmailBuilder.java
+40
-15
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/GrayPublishEmailBuilder.java
...rtal/components/emailbuilder/GrayPublishEmailBuilder.java
+2
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/ConfigPublishListener.java
...amework/apollo/portal/listener/ConfigPublishListener.java
+11
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserService.java
...va/com/ctrip/framework/apollo/portal/spi/UserService.java
+2
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripUserService.java
...p/framework/apollo/portal/spi/ctrip/CtripUserService.java
+3
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java
...ork/apollo/portal/spi/defaultimpl/DefaultUserService.java
+5
-0
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js
...ces/static/scripts/directive/namespace-panel-directive.js
+4
-5
apollo-portal/src/main/resources/static/views/component/namespace-panel.html
...ain/resources/static/views/component/namespace-panel.html
+6
-3
未找到文件。
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/ConfigPublishEmailBuilder.java
浏览文件 @
873ea6bb
package
com.ctrip.framework.apollo.portal.components.emailbuilder
;
import
com.google.common.collect.Lists
;
import
com.ctrip.framework.apollo.common.constants.ReleaseOperation
;
import
com.ctrip.framework.apollo.common.dto.ReleaseDTO
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.constant.RoleType
;
...
...
@@ -16,15 +19,20 @@ import com.ctrip.framework.apollo.portal.service.AppNamespaceService;
import
com.ctrip.framework.apollo.portal.service.ReleaseService
;
import
com.ctrip.framework.apollo.portal.service.RolePermissionService
;
import
com.ctrip.framework.apollo.portal.service.ServerConfigService
;
import
com.ctrip.framework.apollo.portal.spi.UserService
;
import
com.ctrip.framework.apollo.portal.util.RoleUtils
;
import
org.apache.commons.lang.time.FastDateFormat
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
javax.annotation.PostConstruct
;
...
...
@@ -62,7 +70,6 @@ public abstract class ConfigPublishEmailBuilder {
private
FastDateFormat
dateFormat
=
FastDateFormat
.
getInstance
(
"yyyy-MM-dd hh:mm:ss"
);
private
String
emailAddressSuffix
;
private
String
emailSender
;
@Autowired
...
...
@@ -73,10 +80,11 @@ public abstract class ConfigPublishEmailBuilder {
private
ReleaseService
releaseService
;
@Autowired
private
AppNamespaceService
appNamespaceService
;
@Autowired
private
UserService
userService
;
@PostConstruct
public
void
init
()
{
emailAddressSuffix
=
serverConfigService
.
getValue
(
"email.address.suffix"
);
emailSender
=
serverConfigService
.
getValue
(
"email.sender"
);
}
...
...
@@ -103,15 +111,31 @@ public abstract class ConfigPublishEmailBuilder {
Set
<
UserInfo
>
releaseRoleUsers
=
rolePermissionService
.
queryUsersWithRole
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
RoleType
.
RELEASE_NAMESPACE
));
Set
<
UserInfo
>
owners
=
rolePermissionService
.
queryUsersWithRole
(
RoleUtils
.
buildAppMasterRoleName
(
appId
));
List
<
String
>
recipients
=
new
ArrayList
<>(
modifyRoleUsers
.
size
()
+
releaseRoleUs
ers
.
size
());
Set
<
String
>
userIds
=
new
HashSet
<>(
modifyRoleUsers
.
size
()
+
releaseRoleUsers
.
size
()
+
own
ers
.
size
());
for
(
UserInfo
userInfo
:
modifyRoleUsers
)
{
recipients
.
add
(
userInfo
.
getUserId
()
+
emailAddressSuffix
);
userIds
.
add
(
userInfo
.
getUserId
()
);
}
for
(
UserInfo
userInfo
:
releaseRoleUsers
)
{
recipients
.
add
(
userInfo
.
getUserId
()
+
emailAddressSuffix
);
userIds
.
add
(
userInfo
.
getUserId
());
}
for
(
UserInfo
userInfo
:
owners
)
{
userIds
.
add
(
userInfo
.
getUserId
());
}
List
<
UserInfo
>
userInfos
=
userService
.
findByUserIds
(
Lists
.
newArrayList
(
userIds
));
if
(
CollectionUtils
.
isEmpty
(
userInfos
)){
return
Collections
.
emptyList
();
}
List
<
String
>
recipients
=
new
ArrayList
<>(
userInfos
.
size
());
for
(
UserInfo
userInfo:
userInfos
){
recipients
.
add
(
userInfo
.
getEmail
());
}
return
recipients
;
...
...
@@ -124,15 +148,15 @@ public abstract class ConfigPublishEmailBuilder {
}
private
String
renderReleaseBasicInfo
(
String
template
,
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
String
renderResult
=
template
.
replaceAll
(
EMAIL_CONTENT_FIELD_APPID
,
releaseHistory
.
getAppId
(
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_ENV
,
env
.
toString
(
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_CLUSTER
,
releaseHistory
.
getClusterName
(
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_NAMESPACE
,
releaseHistory
.
getNamespaceName
(
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_OPERATOR
,
releaseHistory
.
getOperator
(
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_TITLE
,
releaseHistory
.
getReleaseTitle
(
));
String
renderResult
=
template
.
replaceAll
(
EMAIL_CONTENT_FIELD_APPID
,
Matcher
.
quoteReplacement
(
releaseHistory
.
getAppId
()
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_ENV
,
Matcher
.
quoteReplacement
(
env
.
toString
()
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_CLUSTER
,
Matcher
.
quoteReplacement
(
releaseHistory
.
getClusterName
()
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_NAMESPACE
,
Matcher
.
quoteReplacement
(
releaseHistory
.
getNamespaceName
()
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_OPERATOR
,
Matcher
.
quoteReplacement
(
releaseHistory
.
getOperator
()
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_TITLE
,
Matcher
.
quoteReplacement
(
releaseHistory
.
getReleaseTitle
()
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_ID
,
String
.
valueOf
(
releaseHistory
.
getReleaseId
()));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_COMMENT
,
releaseHistory
.
getReleaseComment
(
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_COMMENT
,
Matcher
.
quoteReplacement
(
releaseHistory
.
getReleaseComment
()
));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_APOLLO_SERVER_ADDRESS
,
getApolloPortalAddress
());
return
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_TIME
,
dateFormat
.
format
(
releaseHistory
.
getReleaseTime
()));
...
...
@@ -150,7 +174,8 @@ public abstract class ConfigPublishEmailBuilder {
//don't show diff content if namespace's format is file
if
(
appNamespace
==
null
||
!
appNamespace
.
getFormat
().
equals
(
ConfigFileFormat
.
Properties
.
getValue
()))
{
return
template
;
return
template
.
replaceAll
(
EMAIL_CONTENT_FIELD_DIFF
,
"请点击链接到Apollo上查看"
);
}
ReleaseCompareResult
result
=
getReleaseCompareResult
(
env
,
releaseHistory
);
...
...
@@ -177,7 +202,8 @@ public abstract class ConfigPublishEmailBuilder {
changesHtmlBuilder
.
append
(
"</tr>"
);
}
String
renderResult
=
template
.
replaceAll
(
EMAIL_CONTENT_FIELD_DIFF
,
changesHtmlBuilder
.
toString
());
String
diffContent
=
Matcher
.
quoteReplacement
(
changesHtmlBuilder
.
toString
());
String
renderResult
=
template
.
replaceAll
(
EMAIL_CONTENT_FIELD_DIFF
,
diffContent
);
return
renderResult
.
replaceAll
(
EMAIL_CONTENT_DIFF_HAS_CONTENT_SWITCH
,
""
);
}
...
...
@@ -214,5 +240,4 @@ public abstract class ConfigPublishEmailBuilder {
return
source
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/GrayPublishEmailBuilder.java
浏览文件 @
873ea6bb
...
...
@@ -13,6 +13,7 @@ import org.springframework.util.CollectionUtils;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
@Component
public
class
GrayPublishEmailBuilder
extends
ConfigPublishEmailBuilder
{
...
...
@@ -59,7 +60,7 @@ public class GrayPublishEmailBuilder extends ConfigPublishEmailBuilder {
}
}
return
result
.
replaceAll
(
EMAIL_CONTENT_FIELD_RULE
,
rulesHtmlBuilder
.
toString
(
));
return
result
.
replaceAll
(
EMAIL_CONTENT_FIELD_RULE
,
Matcher
.
quoteReplacement
(
rulesHtmlBuilder
.
toString
()
));
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/ConfigPublishListener.java
浏览文件 @
873ea6bb
...
...
@@ -13,6 +13,8 @@ import com.ctrip.framework.apollo.portal.service.ServerConfigService;
import
com.ctrip.framework.apollo.portal.spi.EmailService
;
import
com.ctrip.framework.apollo.tracer.Tracer
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.stereotype.Component
;
...
...
@@ -24,6 +26,7 @@ import javax.annotation.PostConstruct;
@Component
public
class
ConfigPublishListener
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConfigPublishListener
.
class
);
@Autowired
private
ServerConfigService
serverConfigService
;
...
...
@@ -53,6 +56,7 @@ public class ConfigPublishListener {
emailSupportedEnvs
.
add
(
Env
.
fromString
(
env
.
trim
()));
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"init email supported envs failed."
,
e
);
Tracer
.
logError
(
"init email supported envs failed."
,
e
);
}
...
...
@@ -75,12 +79,16 @@ public class ConfigPublishListener {
int
realOperation
=
releaseHistory
.
getOperation
();
Email
email
=
buildEmail
(
env
,
releaseHistory
,
realOperation
);
Email
email
=
null
;
try
{
email
=
buildEmail
(
env
,
releaseHistory
,
realOperation
);
}
catch
(
Throwable
e
)
{
Tracer
.
logError
(
"build email failed."
,
e
);
}
if
(
email
!=
null
)
{
emailService
.
send
(
email
);
}
}
private
ReleaseHistoryBO
getReleaseHistory
(
ConfigPublishEvent
event
)
{
...
...
@@ -99,7 +107,7 @@ public class ConfigPublishListener {
if
(
info
.
isRollbackEvent
())
{
return
releaseHistoryService
.
findLatestByPreviousReleaseIdAndOperation
(
env
,
info
.
getPreviousReleaseId
(),
operation
);
}
else
{
}
else
{
return
releaseHistoryService
.
findLatestByReleaseIdAndOperation
(
env
,
info
.
getReleaseId
(),
operation
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/UserService.java
浏览文件 @
873ea6bb
...
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.portal.spi;
import
com.ctrip.framework.apollo.portal.entity.bo.UserInfo
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author Jason Song(song_s@ctrip.com)
...
...
@@ -13,4 +14,5 @@ public interface UserService {
UserInfo
findByUserId
(
String
userId
);
List
<
UserInfo
>
findByUserIds
(
List
<
String
>
userIds
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripUserService.java
浏览文件 @
873ea6bb
...
...
@@ -18,8 +18,10 @@ import org.springframework.util.CollectionUtils;
import
org.springframework.web.client.RestTemplate
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -31,6 +33,7 @@ public class CtripUserService implements UserService {
private
List
<
String
>
searchUserMatchFields
;
private
ParameterizedTypeReference
<
Map
<
String
,
List
<
UserServiceResponse
>>>
responseType
;
public
CtripUserService
(
ServerConfigService
serverConfigService
)
{
this
.
serverConfigService
=
serverConfigService
;
this
.
restTemplate
=
new
RestTemplate
(
clientHttpRequestFactory
());
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultUserService.java
浏览文件 @
873ea6bb
...
...
@@ -5,8 +5,13 @@ import com.google.common.collect.Lists;
import
com.ctrip.framework.apollo.portal.entity.bo.UserInfo
;
import
com.ctrip.framework.apollo.portal.spi.UserService
;
import
org.springframework.util.CollectionUtils
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author Jason Song(song_s@ctrip.com)
...
...
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js
浏览文件 @
873ea6bb
...
...
@@ -40,7 +40,6 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
ALL
:
'
all
'
};
var
MIN_ROW_SIZE
=
10
;
var
operate_branch_storage_key
=
'
OperateBranch
'
;
...
...
@@ -642,7 +641,7 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
function
parseModel2Text
(
namespace
)
{
if
(
namespace
.
items
.
length
==
0
)
{
namespace
.
itemCnt
=
MIN_ROW_SIZE
;
namespace
.
itemCnt
=
0
;
return
""
;
}
...
...
@@ -658,7 +657,7 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
function
parseNotPropertiesText
(
namespace
)
{
var
text
=
namespace
.
items
[
0
].
item
.
value
;
var
lineNum
=
text
.
split
(
"
\n
"
).
length
;
namespace
.
itemCnt
=
lineNum
<
MIN_ROW_SIZE
?
MIN_ROW_SIZE
:
lineNum
;
namespace
.
itemCnt
=
lineNum
;
return
text
;
}
...
...
@@ -682,10 +681,10 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
itemCnt
++
;
});
namespace
.
itemCnt
=
itemCnt
<
MIN_ROW_SIZE
?
MIN_ROW_SIZE
:
itemCnt
;
namespace
.
itemCnt
=
itemCnt
;
return
result
;
}
function
toggleItemSearchInput
(
namespace
)
{
namespace
.
showSearchInput
=
!
namespace
.
showSearchInput
;
}
...
...
apollo-portal/src/main/resources/static/views/component/namespace-panel.html
浏览文件 @
873ea6bb
...
...
@@ -295,13 +295,15 @@
</div>
<!--text view-->
<!--只读模式下的文本内容,不替换换行符-->
<textarea
class=
"form-control no-radius"
rows=
"{{namespace.itemCnt}}"
<textarea
class=
"form-control no-radius"
rows=
"{{namespace.itemCnt < 10 ? 10: namespace.itemCnt>20 ? 20:namespace.itemCnt}}"
ng-show=
"namespace.viewType == 'text' && !namespace.isTextEditing"
ng-disabled=
"!namespace.isTextEditing"
ng-bind=
"namespace.text"
>
</textarea>
<!--编辑状态下的文本内容,会过滤掉换行符-->
<textarea
class=
"form-control"
rows=
"{{namespace.itemCnt}}"
style=
"border-radius: 0px"
<textarea
class=
"form-control no-radius"
rows=
"{{namespace.itemCnt < 10 ? 10: namespace.itemCnt>20 ? 20:namespace.itemCnt}}"
ng-show=
"namespace.viewType == 'text' && namespace.isTextEditing"
ng-disabled=
"!namespace.isTextEditing"
ng-model=
"namespace.editText"
>
</textarea>
...
...
@@ -874,7 +876,8 @@
<!--gray rules-->
<div
class=
"rules-manage-view row"
ng-show=
"namespace.branch.viewType == 'rule'"
>
<div
class=
"alert alert-warning no-radius"
ng-show=
"!namespace.hasModifyPermission && !namespace.hasReleasePermission"
>
<div
class=
"alert alert-warning no-radius"
ng-show=
"!namespace.hasModifyPermission && !namespace.hasReleasePermission"
>
<strong>
Tips:
</strong>
您没有权限编辑灰度规则, 具有namespace修改权或者发布权的人员才可以编辑灰度规则. 如需要编辑灰度规则,请找项目管理员申请权限.
</div>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录