Skip to content

The Unified and Autonomous Development Platform

Some improvements

Robin Shen948690efeb5f
diff --git a/pom.xml b/pom.xml
index 9c4a834a81..a0f2c4ff2e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -637,7 +637,7 @@
</repositories>
<properties>
<commons.version>3.0.7</commons.version>
- <agent.version>2.2.2</agent.version>
+ <agent.version>2.2.3</agent.version>
<slf4j.version>2.0.9</slf4j.version>
<logback.version>1.4.14</logback.version>
<antlr.version>4.7.2</antlr.version>
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateIssueAction.java b/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateIssueAction.java
index 695ebc148f..e2dff30e4b 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateIssueAction.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateIssueAction.java
@@ -30,10 +30,7 @@ import javax.annotation.Nullable;
import javax.validation.Valid;
import javax.validation.ValidationException;
import javax.validation.constraints.NotEmpty;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
import java.util.stream.Collectors;
@Editable(name="Create issue", order=300)
diff --git a/server-core/src/main/java/io/onedev/server/data/migration/DataMigrator.java b/server-core/src/main/java/io/onedev/server/data/migration/DataMigrator.java
index 7fce24cb97..720ef8ab3b 100644
--- a/server-core/src/main/java/io/onedev/server/data/migration/DataMigrator.java
+++ b/server-core/src/main/java/io/onedev/server/data/migration/DataMigrator.java
@@ -7135,5 +7135,44 @@ public class DataMigrator {
dom.writeToFile(file, false);
}
}
- }
+ }
+
+ private void migrate181(File dataDir, Stack<Integer> versions) {
+ for (File file : dataDir.listFiles()) {
+ if (file.getName().startsWith("Issues.xml")) {
+ VersionedXmlDoc dom = VersionedXmlDoc.fromFile(file);
+ for (Element element : dom.getRootElement().elements())
+ element.addElement("externalParticipants");
+ dom.writeToFile(file, false);
+ } else if (file.getName().startsWith("Settings.xml")) {
+ VersionedXmlDoc dom = VersionedXmlDoc.fromFile(file);
+ for (Element element : dom.getRootElement().elements()) {
+ String key = element.elementTextTrim("key");
+ if (key.equals("SERVICE_DESK_SETTING")) {
+ Element valueElement = element.element("value");
+ if (valueElement != null) {
+ valueElement.element("senderAuthorizations").detach();
+ var projectDesignationsElement = valueElement.element("projectDesignations");
+ projectDesignationsElement.setName("defaultProjectSettings");
+ for (var projectDesignationElement: projectDesignationsElement.elements()) {
+ projectDesignationElement.setName("io.onedev.server.model.support.administration.DefaultProjectSetting");
+ }
+ }
+ } else if (key.equals("JOB_EXECUTORS")) {
+ Element valueElement = element.element("value");
+ if (valueElement != null) {
+ for (Element executorElement : valueElement.elements()) {
+ if (executorElement.getName().contains("KubernetesExecutor")
+ || executorElement.getName().contains("DockerExecutor")) {
+ executorElement.element("imageMappings").detach();
+ }
+ }
+ }
+ }
+ }
+ dom.writeToFile(file, false);
+ }
+ }
+ }
+
}
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/entitymanager/IssueCommentManager.java b/server-core/src/main/java/io/onedev/server/entitymanager/IssueCommentManager.java
index efa2fd46a4..067f05c353 100644
--- a/server-core/src/main/java/io/onedev/server/entitymanager/IssueCommentManager.java
+++ b/server-core/src/main/java/io/onedev/server/entitymanager/IssueCommentManager.java
@@ -7,6 +7,8 @@ import io.onedev.server.persistence.dao.EntityManager;
public interface IssueCommentManager extends EntityManager<IssueComment> {
+ void create(IssueComment comment);
+
void create(IssueComment comment, Collection<String> notifiedEmailAddresses);
void delete(IssueComment comment);
diff --git a/server-core/src/main/java/io/onedev/server/entitymanager/IssueManager.java b/server-core/src/main/java/io/onedev/server/entitymanager/IssueManager.java
index 68f49b949f..6891e4807e 100644
--- a/server-core/src/main/java/io/onedev/server/entitymanager/IssueManager.java
+++ b/server-core/src/main/java/io/onedev/server/entitymanager/IssueManager.java
@@ -35,6 +35,8 @@ public interface IssueManager extends EntityManager<Issue> {
void open(Issue issue);
+ void open(Issue issue, Collection<String> notifiedEmailAddresses);
+
void togglePin(Issue issue);
Long getNextNumber(Project numberScope);
diff --git a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultIssueCommentManager.java b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultIssueCommentManager.java
index 0f8fffa766..7dd830092b 100644
--- a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultIssueCommentManager.java
+++ b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultIssueCommentManager.java
@@ -16,6 +16,7 @@ import io.onedev.server.security.SecurityUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
+import java.util.ArrayList;
import java.util.Collection;
@Singleton
@@ -53,6 +54,10 @@ public class DefaultIssueCommentManager extends BaseEntityManager<IssueComment>
changeManager.create(change, null);
}
+ public void create(IssueComment comment) {
+ create(comment, new ArrayList<>());
+ }
+
@Transactional
@Override
public void create(IssueComment comment, Collection<String> notifiedEmailAddresses) {
diff --git a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultIssueManager.java b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultIssueManager.java
index 3e2632dc6e..b5b3d0a8fb 100644
--- a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultIssueManager.java
+++ b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultIssueManager.java
@@ -174,9 +174,14 @@ public class DefaultIssueManager extends BaseEntityManager<Issue> implements Iss
return find(criteria);
}
- @Transactional
@Override
public void open(Issue issue) {
+ open(issue, new ArrayList<>());
+ }
+
+ @Transactional
+ @Override
+ public void open(Issue issue, Collection<String> notifiedEmailAddresses) {
Preconditions.checkArgument(issue.isNew());
issue.setNumberScope(issue.getProject().getForkRoot());
issue.setNumber(getNextNumber(issue.getNumberScope()));
@@ -195,13 +200,15 @@ public class DefaultIssueManager extends BaseEntityManager<Issue> implements Iss
for (IssueSchedule schedule: issue.getSchedules())
dao.persist(schedule);
- IssueAuthorization authorization = new IssueAuthorization();
- authorization.setIssue(issue);
- authorization.setUser(issue.getSubmitter());
- issue.getAuthorizations().add(authorization);
- authorizationManager.createOrUpdate(authorization);
+ if (!SecurityUtils.isAdministrator(issue.getSubmitter().asSubject())) {
+ IssueAuthorization authorization = new IssueAuthorization();
+ authorization.setIssue(issue);
+ authorization.setUser(issue.getSubmitter());
+ issue.getAuthorizations().add(authorization);
+ authorizationManager.createOrUpdate(authorization);
+ }
- listenerRegistry.post(new IssueOpened(issue));
+ listenerRegistry.post(new IssueOpened(issue, notifiedEmailAddresses));
}
@Transactional
diff --git a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultRoleManager.java b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultRoleManager.java
index 9b58237fd3..4c679f15e8 100644
--- a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultRoleManager.java
+++ b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultRoleManager.java
@@ -219,11 +219,9 @@ public class DefaultRoleManager extends BaseEntityManager<Role> implements RoleM
Role issueManager = new Role();
issueManager.setName("Issue Manager");
+ issueManager.setManageIssues(true);
issueManager.setCodePrivilege(CodePrivilege.READ);
- codeWriter.setPackPrivilege(PackPrivilege.READ);
- codeWriter.setScheduleIssues(true);
- codeWriter.setAccessConfidentialIssues(true);
- issueManager.setEditableIssueFields(new AllIssueFields());
+ issueManager.setPackPrivilege(PackPrivilege.READ);
jobPrivilege = new JobPrivilege();
jobPrivilege.setJobNames("*");
diff --git a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSettingManager.java b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSettingManager.java
index 127f21de86..d6381359e4 100644
--- a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSettingManager.java
+++ b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSettingManager.java
@@ -443,8 +443,6 @@ public class DefaultSettingManager extends BaseEntityManager<Setting>
@Override
public void onRenameRole(String oldName, String newName) {
getIssueSetting().onRenameRole(oldName, newName);
- if (getServiceDeskSetting() != null)
- getServiceDeskSetting().onRenameRole(oldName, newName);
saveSetting(Key.ISSUE, getIssueSetting());
saveSetting(Key.SERVICE_DESK_SETTING, getServiceDeskSetting());
}
@@ -452,11 +450,7 @@ public class DefaultSettingManager extends BaseEntityManager<Setting>
@Override
public Usage onDeleteRole(String roleName) {
Usage usage = new Usage();
-
usage.add(getIssueSetting().onDeleteRole(roleName));
- if (getServiceDeskSetting() != null)
- usage.add(getServiceDeskSetting().onDeleteRole(roleName));
-
return usage.prefix("administration");
}
diff --git a/server-core/src/main/java/io/onedev/server/event/project/issue/IssueOpened.java b/server-core/src/main/java/io/onedev/server/event/project/issue/IssueOpened.java
index b3e497f14e..cd8210eb41 100644
--- a/server-core/src/main/java/io/onedev/server/event/project/issue/IssueOpened.java
+++ b/server-core/src/main/java/io/onedev/server/event/project/issue/IssueOpened.java
@@ -23,8 +23,11 @@ public class IssueOpened extends IssueEvent implements CommitAware {
private static final long serialVersionUID = 1L;
- public IssueOpened(Issue issue) {
+ private final Collection<String> notifiedEmailAddresses;
+
+ public IssueOpened(Issue issue, Collection<String> notifiedEmailAddresses) {
super(issue.getSubmitter(), issue.getSubmitDate(), issue);
+ this.notifiedEmailAddresses = notifiedEmailAddresses;
}
@Override
@@ -37,6 +40,10 @@ public class IssueOpened extends IssueEvent implements CommitAware {
return true;
}
+ public Collection<String> getNotifiedEmailAddresses() {
+ return notifiedEmailAddresses;
+ }
+
@Override
public Map<String, Collection<User>> getNewUsers() {
Map<String, Collection<User>> newUsers = new HashMap<>();
diff --git a/server-core/src/main/java/io/onedev/server/mail/DefaultMailManager.java b/server-core/src/main/java/io/onedev/server/mail/DefaultMailManager.java
index 8636b4a723..2d01e46d57 100644
--- a/server-core/src/main/java/io/onedev/server/mail/DefaultMailManager.java
+++ b/server-core/src/main/java/io/onedev/server/mail/DefaultMailManager.java
@@ -19,20 +19,19 @@ import io.onedev.server.event.entity.EntityPersisted;
import io.onedev.server.event.system.SystemStarted;
import io.onedev.server.event.system.SystemStopping;
import io.onedev.server.model.*;
-import io.onedev.server.model.support.administration.*;
+import io.onedev.server.model.support.administration.BrandingSetting;
+import io.onedev.server.model.support.administration.GlobalIssueSetting;
+import io.onedev.server.model.support.administration.IssueCreationSetting;
+import io.onedev.server.model.support.administration.ServiceDeskSetting;
import io.onedev.server.model.support.administration.emailtemplates.EmailTemplates;
import io.onedev.server.model.support.issue.field.instance.FieldInstance;
import io.onedev.server.persistence.TransactionManager;
import io.onedev.server.persistence.annotation.Sessional;
import io.onedev.server.persistence.annotation.Transactional;
-import io.onedev.server.security.permission.AccessProject;
-import io.onedev.server.security.permission.BasePermission;
-import io.onedev.server.security.permission.ProjectPermission;
-import io.onedev.server.security.permission.ReadCode;
+import io.onedev.server.security.SecurityUtils;
import io.onedev.server.util.CollectionUtils;
import io.onedev.server.util.HtmlUtils;
import io.onedev.server.util.ParsedEmailAddress;
-import io.onedev.server.validation.validator.UserNameValidator;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.authz.UnauthorizedException;
@@ -74,7 +73,7 @@ import java.util.function.Consumer;
import static com.google.common.collect.Lists.newArrayList;
import static io.onedev.server.model.Setting.Key.MAIL_SERVICE;
import static java.util.Arrays.asList;
-import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toSet;
@Singleton
public class DefaultMailManager implements MailManager, Serializable {
@@ -321,16 +320,6 @@ public class DefaultMailManager implements MailManager, Serializable {
}
}
}
-
- private void checkPermission(InternetAddress sender, Project project, BasePermission privilege,
- @Nullable User user, @Nullable SenderAuthorization authorization) {
- if ((user == null || !user.asSubject().isPermitted(new ProjectPermission(project, privilege)))
- && (authorization == null || !authorization.isPermitted(project, privilege))) {
- String errorMessage = String.format("Permission denied (project: %s, sender: %s, permission: %s)",
- project.getPath(), sender.getAddress(), privilege.getClass().getName());
- throw new UnauthorizedException(errorMessage);
- }
- }
private String getThreadingReferences(String uuid, @Nullable String messageId) {
var threadingReferences = "<" + uuid + "@onedev>";
@@ -354,191 +343,180 @@ public class DefaultMailManager implements MailManager, Serializable {
var fromAddress = fromInternetAddress.getAddress();
if (!fromAddress.equalsIgnoreCase(systemAddress)) {
EmailAddress fromAddressEntity = emailAddressManager.findByValue(fromAddress);
- if (fromAddressEntity != null && !fromAddressEntity.isVerified()) {
- logger.error("Another account uses email address '{}' but not verified", fromAddress);
- } else {
- User fromUser = fromAddressEntity != null ? fromAddressEntity.getOwner() : null;
- SenderAuthorization authorization = null;
- String designatedProject = null;
- ServiceDeskSetting serviceDeskSetting = settingManager.getServiceDeskSetting();
- if (serviceDeskSetting != null) {
- authorization = serviceDeskSetting.getSenderAuthorization(fromAddress);
- designatedProject = serviceDeskSetting.getDesignatedProject(fromAddress);
- }
-
- var parsedSystemAddress = ParsedEmailAddress.parse(systemAddress);
-
- Issue involvedIssue = null;
- PullRequest involvedPullRequest = null;
- Collection<InternetAddress> involvedInternetAddresses = new HashSet<>();
+ User fromUser = null;
+ if (fromAddressEntity != null && fromAddressEntity.isVerified())
+ fromUser = fromAddressEntity.getOwner();
+ String defaultProject = null;
+ ServiceDeskSetting serviceDeskSetting = settingManager.getServiceDeskSetting();
+ if (serviceDeskSetting != null)
+ defaultProject = serviceDeskSetting.getDefaultProject(fromAddress);
+
+ var parsedSystemAddress = ParsedEmailAddress.parse(systemAddress);
+
+ Issue involvedIssue = null;
+ PullRequest involvedPullRequest = null;
+ Collection<InternetAddress> involvedInternetAddresses = new HashSet<>();
- List<InternetAddress> receiverInternetAddresses = new ArrayList<>();
- receiverInternetAddresses.addAll(asList(toInternetAddresses));
- receiverInternetAddresses.addAll(asList(getAddresses(message, "Cc")));
- for (InternetAddress receiverInternetAddress : receiverInternetAddresses) {
- ParsedEmailAddress parsedReceiverAddress = ParsedEmailAddress.parse(receiverInternetAddress.getAddress());
- if (targetAddresses.contains(parsedReceiverAddress.toString().toLowerCase())) {
- if (involvedIssue == null && involvedPullRequest == null) {
- if (isOriginatedFromOneDev(message)) {
- logger.warn("Ignored opening issue from message as it is originated from OneDev");
- } else if (serviceDeskSetting != null) {
- if (designatedProject == null)
- throw new ExplicitException("No project designated for sender: " + fromInternetAddress.getAddress());
- Project project = projectManager.findByPath(designatedProject);
- if (project == null) {
- String errorMessage = String.format(
- "Sender project does not exist (sender: %s, project: %s)",
- fromInternetAddress.getAddress(), designatedProject);
- throw new ExplicitException(errorMessage);
- }
- checkPermission(fromInternetAddress, project, new AccessProject(), fromUser, authorization);
- involvedIssue = openIssue(message, project, fromInternetAddress, fromUser, authorization, parsedSystemAddress);
- } else {
- throw new ExplicitException("Unable to create issue from email as service desk is not enabled");
- }
+ List<InternetAddress> receiverInternetAddresses = new ArrayList<>();
+ receiverInternetAddresses.addAll(asList(toInternetAddresses));
+ receiverInternetAddresses.addAll(asList(getAddresses(message, "Cc")));
+ for (InternetAddress receiverInternetAddress : receiverInternetAddresses) {
+ ParsedEmailAddress parsedReceiverAddress = ParsedEmailAddress.parse(receiverInternetAddress.getAddress());
+ if (targetAddresses.contains(parsedReceiverAddress.toString().toLowerCase())) {
+ if (involvedIssue == null && involvedPullRequest == null) {
+ if (isOriginatedFromOneDev(message)) {
+ logger.warn("Ignored opening issue from message as it is originated from OneDev");
+ } else if (serviceDeskSetting != null) {
+ if (defaultProject == null)
+ throw new ExplicitException("No default project for sender: " + fromInternetAddress.getAddress());
+ Project project = projectManager.findByPath(defaultProject);
+ if (project == null)
+ throw new ExplicitException("Project not found: %s" + defaultProject);
+ involvedIssue = openIssue(message, project, fromInternetAddress, fromUser, parsedSystemAddress, receiverInternetAddresses);
} else {
- logger.warn("Ignored recipient '" + parsedReceiverAddress + "' as issue or pull request is processed");
+ throw new ExplicitException("Unable to create issue from email as service desk is not enabled");
}
- } else if (parsedReceiverAddress.isSubaddress() && targetAddresses.contains(parsedReceiverAddress.getOriginalAddress().toLowerCase())) {
- if (involvedIssue == null && involvedPullRequest == null) {
- String subAddress = StringUtils.substringAfter(parsedReceiverAddress.getName(), "+");
- if (subAddress.equals(MailManager.TEST_SUB_ADDRESS)) {
- break;
- } else if (subAddress.contains("~")) {
- Long entityId;
- try {
- entityId = Long.parseLong(StringUtils.substringAfter(subAddress, "~"));
- } catch (NumberFormatException e) {
- throw new ExplicitException("Invalid id specified in recipient address: " + parsedReceiverAddress);
- }
- if (subAddress.contains("issue")) {
- involvedIssue = issueManager.get(entityId);
- if (involvedIssue == null)
- throw new ExplicitException("Non-existent issue specified in receipient address: " + parsedReceiverAddress);
- if (subAddress.contains("unsubscribe")) {
- if (fromUser != null) {
- IssueWatch watch = issueWatchManager.find(involvedIssue, fromUser);
- if (watch != null) {
- watch.setWatching(false);
- issueWatchManager.createOrUpdate(watch);
- String subject = "Unsubscribed successfully from issue " + involvedIssue.getReference();
- String template = settingManager.getEmailTemplates().getIssueNotificationUnsubscribed();
+ } else {
+ logger.warn("Ignored recipient '" + parsedReceiverAddress + "' as issue or pull request is processed");
+ }
+ } else if (parsedReceiverAddress.isSubaddress() && targetAddresses.contains(parsedReceiverAddress.getOriginalAddress().toLowerCase())) {
+ if (involvedIssue == null && involvedPullRequest == null) {
+ String subAddress = StringUtils.substringAfter(parsedReceiverAddress.getName(), "+");
+ if (subAddress.equals(MailManager.TEST_SUB_ADDRESS)) {
+ break;
+ } else if (subAddress.contains("~")) {
+ Long entityId;
+ try {
+ entityId = Long.parseLong(StringUtils.substringAfter(subAddress, "~"));
+ } catch (NumberFormatException e) {
+ throw new ExplicitException("Invalid id specified in recipient address: " + parsedReceiverAddress);
+ }
+ if (subAddress.contains("issue")) {
+ involvedIssue = issueManager.get(entityId);
+ if (involvedIssue == null)
+ throw new ExplicitException("Non-existent issue specified in recipient address: " + parsedReceiverAddress);
+ if (subAddress.contains("unsubscribe")) {
+ if (fromUser != null) {
+ var watch = issueWatchManager.find(involvedIssue, fromUser);
+ if (watch != null)
+ watch.setWatching(false);
+ } else {
+ involvedIssue.getExternalParticipants().remove(fromInternetAddress);
+ }
+ String subject = "Unsubscribed successfully from issue " + involvedIssue.getReference();
+ String template = settingManager.getEmailTemplates().getIssueNotificationUnsubscribed();
- Map<String, Object> bindings = new HashMap<>();
- bindings.put("issue", involvedIssue);
+ Map<String, Object> bindings = new HashMap<>();
+ bindings.put("issue", involvedIssue);
- String htmlBody = EmailTemplates.evalTemplate(true, template, bindings);
- String textBody = EmailTemplates.evalTemplate(false, template, bindings);
+ String htmlBody = EmailTemplates.evalTemplate(true, template, bindings);
+ String textBody = EmailTemplates.evalTemplate(false, template, bindings);
- var threadingReferences = getThreadingReferences(UUID.randomUUID().toString(), getMessageId(message));
- sendMailAsync(newArrayList(fromInternetAddress.getAddress()), newArrayList(), newArrayList(),
- subject, htmlBody, textBody, null, null, threadingReferences);
- }
- }
+ var threadingReferences = getThreadingReferences(UUID.randomUUID().toString(), getMessageId(message));
+ sendMailAsync(newArrayList(fromInternetAddress.getAddress()), newArrayList(), newArrayList(),
+ subject, htmlBody, textBody, null, null, threadingReferences);
+ } else {
+ if (fromUser != null) {
+ if (SecurityUtils.canAccessIssue(fromUser.asSubject(), involvedIssue))
+ addComment(involvedIssue, message, fromInternetAddress, fromUser, receiverInternetAddresses);
+ else
+ throw new UnauthorizedException("No permission to comment issue: " + involvedIssue.getReference());
} else {
- checkPermission(fromInternetAddress, involvedIssue.getProject(), new AccessProject(), fromUser, authorization);
- addComment(involvedIssue, message, fromInternetAddress, fromUser, authorization, receiverInternetAddresses);
+ if (involvedIssue.getExternalParticipants().contains(fromInternetAddress))
+ addComment(involvedIssue, message, fromInternetAddress, null, receiverInternetAddresses);
+ else
+ throw new UnauthorizedException("Not eligible to comment issue: " + involvedIssue.getReference());
}
- } else if (subAddress.contains("pullrequest")) {
+ }
+ } else if (subAddress.contains("pullrequest")) {
+ if (fromUser != null) {
involvedPullRequest = pullRequestManager.get(entityId);
if (involvedPullRequest == null)
- throw new ExplicitException("Non-existent pull request specified in receipient address: " + parsedReceiverAddress);
+ throw new ExplicitException("Non-existent pull request specified in recipient address: " + parsedReceiverAddress);
if (subAddress.contains("unsubscribe")) {
- if (fromUser != null) {
- PullRequestWatch watch = pullRequestWatchManager.find(involvedPullRequest, fromUser);
- if (watch != null) {
- watch.setWatching(false);
- pullRequestWatchManager.createOrUpdate(watch);
- String subject = "Unsubscribed successfully from pull request " + involvedPullRequest.getReference().toString(null);
+ PullRequestWatch watch = pullRequestWatchManager.find(involvedPullRequest, fromUser);
+ if (watch != null)
+ watch.setWatching(false);
+
+ String subject = "Unsubscribed successfully from pull request " + involvedPullRequest.getReference().toString(null);
- String template = StringUtils.join(settingManager.getEmailTemplates().getPullRequestNotificationUnsubscribed(), "\n");
- Map<String, Object> bindings = new HashMap<>();
- bindings.put("pullRequest", involvedPullRequest);
- String htmlBody = EmailTemplates.evalTemplate(true, template, bindings);
- String textBody = EmailTemplates.evalTemplate(false, template, bindings);
- var threadingReferences = getThreadingReferences(UUID.randomUUID().toString(), getMessageId(message));
- sendMailAsync(newArrayList(fromInternetAddress.getAddress()), newArrayList(), newArrayList(),
- subject, htmlBody, textBody, null, null, threadingReferences);
- }
- }
+ String template = StringUtils.join(settingManager.getEmailTemplates().getPullRequestNotificationUnsubscribed(), "\n");
+ Map<String, Object> bindings = new HashMap<>();
+ bindings.put("pullRequest", involvedPullRequest);
+ String htmlBody = EmailTemplates.evalTemplate(true, template, bindings);
+ String textBody = EmailTemplates.evalTemplate(false, template, bindings);
+ var threadingReferences = getThreadingReferences(UUID.randomUUID().toString(), getMessageId(message));
+ sendMailAsync(newArrayList(fromInternetAddress.getAddress()), newArrayList(), newArrayList(),
+ subject, htmlBody, textBody, null, null, threadingReferences);
} else {
- checkPermission(fromInternetAddress, involvedPullRequest.getProject(), new ReadCode(), fromUser, authorization);
- addComment(involvedPullRequest, message, fromInternetAddress, fromUser, authorization, receiverInternetAddresses);
+ if (!SecurityUtils.canReadCode(involvedPullRequest.getProject())) {
+ addComment(involvedPullRequest, message, fromInternetAddress, fromUser, receiverInternetAddresses);
+ } else {
+ throw new UnauthorizedException("Code read permission required for project: %s"
+ + involvedPullRequest.getProject().getPath());
+ }
}
} else {
- throw new ExplicitException("Invalid recipient address: " + parsedReceiverAddress);
+ throw new ExplicitException("No account found with verified email address: " + fromInternetAddress.getAddress());
}
} else {
- if (isOriginatedFromOneDev(message)) {
- logger.warn("Ignored opening issue from message as it is originated from OneDev");
- } else {
- Project project = projectManager.findByServiceDeskName(subAddress);
- if (project == null)
- project = projectManager.findByPath(subAddress);
+ throw new ExplicitException("Invalid recipient address: " + parsedReceiverAddress);
+ }
+ } else {
+ if (isOriginatedFromOneDev(message)) {
+ logger.warn("Ignored opening issue from message as it is originated from OneDev");
+ } else {
+ Project project = projectManager.findByServiceDeskName(subAddress);
+ if (project == null)
+ project = projectManager.findByPath(subAddress);
- if (project == null)
- throw new ExplicitException("Non-existent project specified in receipient address: " + parsedReceiverAddress);
- if (serviceDeskSetting != null) {
- checkPermission(fromInternetAddress, project, new AccessProject(), fromUser, authorization);
- logger.debug("Creating issue via email (project: {})...", project.getPath());
- involvedIssue = openIssue(message, project, fromInternetAddress, fromUser, authorization, parsedSystemAddress);
- } else {
- throw new ExplicitException("Unable to create issue from email as service desk is not enabled");
- }
+ if (project == null)
+ throw new ExplicitException("Non-existent project specified in receipient address: " + parsedReceiverAddress);
+ if (serviceDeskSetting != null) {
+ logger.debug("Creating issue via email (project: {})...", project.getPath());
+ involvedIssue = openIssue(message, project, fromInternetAddress, fromUser, parsedSystemAddress, receiverInternetAddresses);
+ } else {
+ throw new ExplicitException("Unable to create issue from email as service desk is not enabled");
}
}
- } else {
- logger.warn("Ignored recipient '" + parsedReceiverAddress + "' as issue or pull request is processed");
}
- } else if (!receiverInternetAddress.equals(fromInternetAddress)) {
- involvedInternetAddresses.add(receiverInternetAddress);
+ } else {
+ logger.warn("Ignored recipient '" + parsedReceiverAddress + "' as issue or pull request is processed");
}
+ } else if (!receiverInternetAddress.equals(fromInternetAddress)) {
+ involvedInternetAddresses.add(receiverInternetAddress);
}
if (involvedIssue != null) {
- var project = involvedIssue.getProject();
for (InternetAddress involvedInternetAddress : involvedInternetAddresses) {
EmailAddress involvedAddressEntity = emailAddressManager.findByValue(involvedInternetAddress.getAddress());
- if (involvedAddressEntity != null && !involvedAddressEntity.isVerified()) {
- logger.error("Another account uses email address '{}' but not verified", involvedInternetAddress.getAddress());
- } else {
- if (serviceDeskSetting != null)
- authorization = serviceDeskSetting.getSenderAuthorization(involvedInternetAddress.getAddress());
- var involvedUser = involvedAddressEntity != null ? involvedAddressEntity.getOwner() : null;
- try {
- checkPermission(involvedInternetAddress, project, new AccessProject(), involvedUser, authorization);
- if (involvedUser == null)
- involvedUser = createUser(involvedInternetAddress, project, authorization.getAuthorizedRole());
- else if (!involvedUser.asSubject().isPermitted(new ProjectPermission(project, new AccessProject())))
- authorizationManager.authorize(involvedUser, project, authorization.getAuthorizedRole());
- issueWatchManager.watch(involvedIssue, involvedUser, true);
+ if (involvedAddressEntity != null && involvedAddressEntity.isVerified()) {
+ var involvedUser = involvedAddressEntity.getOwner();
+ if (SecurityUtils.canAccessProject(involvedUser.asSubject(), involvedIssue.getProject())) {
if (involvedIssue.isConfidential())
issueAuthorizationManager.authorize(involvedIssue, involvedUser);
- } catch (UnauthorizedException e) {
- logger.error("Error adding receipient to watch list", e);
+ issueWatchManager.watch(involvedIssue, involvedUser, true);
+ } else {
+ involvedIssue.getExternalParticipants().add(involvedInternetAddress);
}
+ } else {
+ involvedIssue.getExternalParticipants().add(involvedInternetAddress);
}
}
} else if (involvedPullRequest != null) {
- var project = involvedPullRequest.getProject();
for (InternetAddress involvedInternetAddress : involvedInternetAddresses) {
EmailAddress involvedAddressEntity = emailAddressManager.findByValue(involvedInternetAddress.getAddress());
- if (involvedAddressEntity != null && !involvedAddressEntity.isVerified()) {
- logger.error("Another account uses email address '{}' but not verified", involvedInternetAddress.getAddress());
- } else {
- var involvedUser = involvedAddressEntity != null ? involvedAddressEntity.getOwner() : null;
- if (serviceDeskSetting != null)
- authorization = serviceDeskSetting.getSenderAuthorization(involvedInternetAddress.getAddress());
- try {
- checkPermission(involvedInternetAddress, involvedPullRequest.getProject(), new ReadCode(), involvedUser, authorization);
- if (involvedUser == null)
- involvedUser = createUser(involvedInternetAddress, involvedPullRequest.getProject(), authorization.getAuthorizedRole());
- else if (!involvedUser.asSubject().isPermitted(new ProjectPermission(project, new ReadCode())))
- authorizationManager.authorize(involvedUser, project, authorization.getAuthorizedRole());
+ if (involvedAddressEntity != null && involvedAddressEntity.isVerified()) {
+ var involvedUser = involvedAddressEntity.getOwner();
+ if (SecurityUtils.canReadCode(involvedUser.asSubject(), involvedPullRequest.getProject())) {
pullRequestWatchManager.watch(involvedPullRequest, involvedUser, true);
- } catch (UnauthorizedException e) {
- logger.error("Error adding receipient to watch list", e);
+ } else {
+ logger.warn("Code read permission required to watch pull request (user: {}, project: {})",
+ involvedUser.getDisplayName(), involvedPullRequest.getProject().getPath());
}
+ } else {
+ logger.warn("Account with verified email address and code read permission required to watch pull request (email address: {}, project: {})",
+ involvedInternetAddress.getAddress(), involvedPullRequest.getProject().getPath());
}
}
}
@@ -629,42 +607,42 @@ public class DefaultMailManager implements MailManager, Serializable {
}
private void addComment(Issue issue, Message message, InternetAddress authorInternetAddress, @Nullable User author,
- @Nullable SenderAuthorization authorization, Collection<InternetAddress> notifiedInternetAddresses) {
+ Collection<InternetAddress> receiverInternetAddresses) {
IssueComment comment = new IssueComment();
comment.setIssue(issue);
- if (author == null)
- author = createUser(authorInternetAddress, issue.getProject(), authorization.getAuthorizedRole());
- else if (!author.asSubject().isPermitted(new ProjectPermission(issue.getProject(), new AccessProject())))
- authorizationManager.authorize(author, issue.getProject(), authorization.getAuthorizedRole());
- comment.setUser(author);
+ if (author == null) {
+ comment.setUser(userManager.getSystem());
+ comment.setOnBehalfOf(authorInternetAddress);
+ } else {
+ comment.setUser(author);
+ }
String content = parseBody(message, issue.getProject(), issue.getUUID());
if (content != null) {
// Add double line breaks in the beginning and ending as otherwise plain text content
// received from email may not be formatted correctly with our markdown renderer.
comment.setContent(decorateContent(content));
- issueCommentManager.create(comment, notifiedInternetAddresses.stream().map(InternetAddress::getAddress).collect(toList()));
+ var notifiedEmailAddresses = receiverInternetAddresses.stream().map(InternetAddress::getAddress).collect(toSet());
+ notifiedEmailAddresses.add(authorInternetAddress.getAddress());
+ issueCommentManager.create(comment, notifiedEmailAddresses);
}
}
- private void addComment(PullRequest pullRequest, Message message, InternetAddress authorInternetAddress, @Nullable User author,
- @Nullable SenderAuthorization authorization, Collection<InternetAddress> notifiedInternetAddresses) {
+ private void addComment(PullRequest pullRequest, Message message, InternetAddress authorInternetAddress,
+ User author, Collection<InternetAddress> receiverInternetAddresses) {
PullRequestComment comment = new PullRequestComment();
- comment.setRequest(pullRequest);
- if (author == null)
- author = createUser(authorInternetAddress, pullRequest.getProject(), authorization.getAuthorizedRole());
- else if (!author.asSubject().isPermitted(new ProjectPermission(pullRequest.getProject(), new ReadCode())))
- authorizationManager.authorize(author, pullRequest.getProject(), authorization.getAuthorizedRole());
comment.setUser(author);
String content = parseBody(message, pullRequest.getProject(), pullRequest.getUUID());
if (content != null) {
comment.setContent(decorateContent(content));
- pullRequestCommentManager.create(comment, notifiedInternetAddresses.stream().map(InternetAddress::getAddress).collect(toList()));
+ var notifiedEmailAddresses = receiverInternetAddresses.stream().map(InternetAddress::getAddress).collect(toSet());
+ notifiedEmailAddresses.add(authorInternetAddress.getAddress());
+ pullRequestCommentManager.create(comment, notifiedEmailAddresses);
}
}
private Issue openIssue(Message message, Project project, InternetAddress submitterInternetAddress,
- @Nullable User submitter, @Nullable SenderAuthorization authorization,
- ParsedEmailAddress parsedSystemAddress) {
+ @Nullable User submitter, ParsedEmailAddress parsedSystemAddress,
+ Collection<InternetAddress> receiverInternetAddresses) {
Issue issue = new Issue();
issue.setProject(project);
@@ -690,12 +668,14 @@ public class DefaultMailManager implements MailManager, Serializable {
description = stripSignature(description);
if (StringUtils.isNotBlank(description))
issue.setDescription(decorateContent(description));
-
- if (submitter == null)
- submitter = createUser(submitterInternetAddress, project, authorization.getAuthorizedRole());
- else if (!submitter.asSubject().isPermitted(new ProjectPermission(project, new AccessProject())))
- authorizationManager.authorize(submitter, project, authorization.getAuthorizedRole());
- issue.setSubmitter(submitter);
+
+ if (submitter == null) {
+ issue.setSubmitter(userManager.getSystem());
+ issue.setOnBehalfOf(submitterInternetAddress);
+ issue.getExternalParticipants().add(submitterInternetAddress);
+ } else {
+ issue.setSubmitter(submitter);
+ }
GlobalIssueSetting issueSetting = settingManager.getIssueSetting();
issue.setState(issueSetting.getInitialStateSpec().getName());
@@ -708,14 +688,16 @@ public class DefaultMailManager implements MailManager, Serializable {
.convertToObject(instance.getValueProvider().getValue());
issue.setFieldValue(instance.getName(), fieldValue);
}
+
+ var notifyEmailAddresses = receiverInternetAddresses.stream().map(InternetAddress::getAddress).collect(toSet());
+ notifyEmailAddresses.add(submitterInternetAddress.getAddress());
- issueManager.open(issue);
+ issueManager.open(issue, notifyEmailAddresses);
ParsedEmailAddress parsedSubmitterAddress = ParsedEmailAddress.parse(submitterInternetAddress.getAddress());
if (!parsedSubmitterAddress.getDomain().equalsIgnoreCase(parsedSystemAddress.getDomain())
|| !parsedSubmitterAddress.getName().toLowerCase().startsWith(parsedSystemAddress.getName().toLowerCase() + "+")
&& !parsedSubmitterAddress.getName().equalsIgnoreCase(parsedSystemAddress.getName())) {
-
String template = StringUtils.join(settingManager.getEmailTemplates().getServiceDeskIssueOpened(), "\n");
Map<String, Object> bindings = new HashMap<>();
bindings.put("issue", issue);
@@ -723,32 +705,12 @@ public class DefaultMailManager implements MailManager, Serializable {
String textBody = EmailTemplates.evalTemplate(false, template, bindings);
var replyAddress = parsedSystemAddress.getSubaddress("issue~" + issue.getId());
- sendMailAsync(newArrayList(submitterInternetAddress.getAddress()), newArrayList(), newArrayList(),
+ sendMailAsync(notifyEmailAddresses, newArrayList(), newArrayList(),
"Re: " + issue.getTitle(), htmlBody, textBody, replyAddress,
submitterInternetAddress.getPersonal(), issue.getThreadingReferences());
}
return issue;
}
-
- private User createUser(InternetAddress internetAddress, Project project, Role role) {
- User user = new User();
- user.setName(UserNameValidator.suggestUserName(ParsedEmailAddress.parse(internetAddress.getAddress()).getName()));
- user.setFullName(internetAddress.getPersonal());
- user.setPassword("impossible password");
- userManager.create(user);
-
- EmailAddress addressEntity = new EmailAddress();
- addressEntity.setValue(internetAddress.getAddress());
- addressEntity.setVerificationCode(null);
- addressEntity.setPrimary(true);
- addressEntity.setGit(true);
- addressEntity.setOwner(user);
- emailAddressManager.create(addressEntity);
-
- authorizationManager.authorize(user, project, role);
-
- return user;
- }
@Listen
public void on(SystemStarted event) {
diff --git a/server-core/src/main/java/io/onedev/server/model/Issue.java b/server-core/src/main/java/io/onedev/server/model/Issue.java
index 621f5a9db5..b488e98b96 100644
--- a/server-core/src/main/java/io/onedev/server/model/Issue.java
+++ b/server-core/src/main/java/io/onedev/server/model/Issue.java
@@ -45,6 +45,7 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicUpdate;
import javax.annotation.Nullable;
+import javax.mail.internet.InternetAddress;
import javax.persistence.*;
import java.io.Serializable;
import java.util.*;
@@ -228,7 +229,10 @@ public class Issue extends ProjectBelonging implements AttachmentStorageSupport
@Column(nullable=false)
private Date submitDate = new Date();
-
+
+ @Lob
+ private InternetAddress onBehalfOf;
+
private int voteCount;
private int commentCount;
@@ -264,6 +268,10 @@ public class Issue extends ProjectBelonging implements AttachmentStorageSupport
private int boardPosition;
+ @Lob
+ @Column(nullable=false, length=65535)
+ private LinkedHashSet<InternetAddress> externalParticipants = new LinkedHashSet<>();
+
@OneToMany(mappedBy="issue", cascade=CascadeType.REMOVE)
private Collection<IssueField> fields = new ArrayList<>();
@@ -450,6 +458,15 @@ public class Issue extends ProjectBelonging implements AttachmentStorageSupport
this.submitDate = submitDate;
}
+ @Nullable
+ public InternetAddress getOnBehalfOf() {
+ return onBehalfOf;
+ }
+
+ public void setOnBehalfOf(@Nullable InternetAddress onBehalfOf) {
+ this.onBehalfOf = onBehalfOf;
+ }
+
public Collection<IssueSchedule> getSchedules() {
return schedules;
}
@@ -614,6 +631,14 @@ public class Issue extends ProjectBelonging implements AttachmentStorageSupport
this.boardPosition = boardPosition;
}
+ public LinkedHashSet<InternetAddress> getExternalParticipants() {
+ return externalParticipants;
+ }
+
+ public void setExternalParticipants(LinkedHashSet<InternetAddress> externalParticipants) {
+ this.externalParticipants = externalParticipants;
+ }
+
public Collection<IssueField> getFields() {
return fields;
}
diff --git a/server-core/src/main/java/io/onedev/server/model/IssueComment.java b/server-core/src/main/java/io/onedev/server/model/IssueComment.java
index 4066d796d7..52acd9178a 100644
--- a/server-core/src/main/java/io/onedev/server/model/IssueComment.java
+++ b/server-core/src/main/java/io/onedev/server/model/IssueComment.java
@@ -3,6 +3,8 @@ package io.onedev.server.model;
import io.onedev.server.model.support.EntityComment;
import io.onedev.server.rest.annotation.Immutable;
+import javax.annotation.Nullable;
+import javax.mail.internet.InternetAddress;
import javax.persistence.*;
@Entity
@@ -18,6 +20,9 @@ public class IssueComment extends EntityComment {
@JoinColumn(nullable=false)
@Immutable
private Issue issue;
+
+ @Lob
+ private InternetAddress onBehalfOf;
public Issue getIssue() {
return issue;
@@ -27,6 +32,15 @@ public class IssueComment extends EntityComment {
this.issue = issue;
}
+ @Nullable
+ public InternetAddress getOnBehalfOf() {
+ return onBehalfOf;
+ }
+
+ public void setOnBehalfOf(@Nullable InternetAddress onBehalfOf) {
+ this.onBehalfOf = onBehalfOf;
+ }
+
@Override
public AbstractEntity getEntity() {
return getIssue();
diff --git a/server-core/src/main/java/io/onedev/server/model/support/ImageMapping.java b/server-core/src/main/java/io/onedev/server/model/support/ImageMapping.java
deleted file mode 100644
index e06e5f1d73..0000000000
--- a/server-core/src/main/java/io/onedev/server/model/support/ImageMapping.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package io.onedev.server.model.support;
-
-import io.onedev.agent.job.ImageMappingFacade;
-import io.onedev.server.annotation.Editable;
-
-import java.io.Serializable;
-
-@Editable
-public class ImageMapping implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private String from;
-
- private String to;
-
- @Editable(order=100, description = "A Java regular expression matching image (registry/repo:tag)")
- public String getFrom() {
- return from;
- }
-
- public void setFrom(String from) {
- this.from = from;
- }
-
- @Editable(order=200, description = "Target image to use. Note that group reference can be used to " +
- "refer to part of original image based on defined from pattern")
- public String getTo() {
- return to;
- }
-
- public void setTo(String to) {
- this.to = to;
- }
-
- public ImageMappingFacade getFacade() {
- return new ImageMappingFacade(from, to);
- }
-
-}
diff --git a/server-core/src/main/java/io/onedev/server/model/support/administration/ProjectDesignation.java b/server-core/src/main/java/io/onedev/server/model/support/administration/DefaultProjectSetting.java
similarity index 96%
rename from server-core/src/main/java/io/onedev/server/model/support/administration/ProjectDesignation.java
rename to server-core/src/main/java/io/onedev/server/model/support/administration/DefaultProjectSetting.java
index d48c7bbc15..47b48136be 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/administration/ProjectDesignation.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/administration/DefaultProjectSetting.java
@@ -14,7 +14,7 @@ import io.onedev.server.annotation.Editable;
import io.onedev.server.annotation.Patterns;
@Editable
-public class ProjectDesignation implements Serializable {
+public class DefaultProjectSetting implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/server-core/src/main/java/io/onedev/server/model/support/administration/IssueCreationSetting.java b/server-core/src/main/java/io/onedev/server/model/support/administration/IssueCreationSetting.java
index 8754a9d095..c0bb05c9f8 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/administration/IssueCreationSetting.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/administration/IssueCreationSetting.java
@@ -36,7 +36,7 @@ public class IssueCreationSetting implements Serializable {
private String applicableProjects;
- private boolean confidential;
+ private boolean confidential = true;
private List<FieldInstance> issueFields = new ArrayList<>();
diff --git a/server-core/src/main/java/io/onedev/server/model/support/administration/SenderAuthorization.java b/server-core/src/main/java/io/onedev/server/model/support/administration/SenderAuthorization.java
deleted file mode 100644
index feda6ba37d..0000000000
--- a/server-core/src/main/java/io/onedev/server/model/support/administration/SenderAuthorization.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package io.onedev.server.model.support.administration;
-
-import java.io.Serializable;
-import java.util.List;
-
-import org.apache.shiro.authz.Permission;
-import javax.validation.constraints.NotEmpty;
-
-import io.onedev.commons.codeassist.InputSuggestion;
-import io.onedev.commons.utils.ExplicitException;
-import io.onedev.server.OneDev;
-import io.onedev.server.entitymanager.RoleManager;
-import io.onedev.server.model.Project;
-import io.onedev.server.model.Role;
-import io.onedev.commons.utils.match.PathMatcher;
-import io.onedev.server.util.patternset.PatternSet;
-import io.onedev.server.annotation.Editable;
-import io.onedev.server.annotation.Patterns;
-import io.onedev.server.annotation.RoleChoice;
-import io.onedev.server.web.util.SuggestionUtils;
-
-@Editable
-public class SenderAuthorization implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private String senderEmails;
-
- private String authorizedProjects;
-
- private String authorizedRoleName;
-
- @Editable(order=100, name="Applicable Senders", placeholder="Any sender", description=""
- + "Specify space-separated sender email addresses applicable for this entry. "
- + "Use '*' or '?' for wildcard match. Prefix with '-' to exclude. "
- + "Leave empty to match all senders")
- @Patterns
- public String getSenderEmails() {
- return senderEmails;
- }
-
- public void setSenderEmails(String senderEmails) {
- this.senderEmails = senderEmails;
- }
-
- @Editable(order=150, placeholder="Any project", description="Specify space-separated projects "
- + "authorized to senders above. Use '**' or '*' or '?' for "
- + "<a href='https://docs.onedev.io/appendix/path-wildcard' target='_blank'>path wildcard match</a>. "
- + "Prefix with '-' to exclude. Leave empty to authorize all projects")
- @Patterns(suggester="suggestProjects", path=true)
- public String getAuthorizedProjects() {
- return authorizedProjects;
- }
-
- public void setAuthorizedProjects(String authorizedProjects) {
- this.authorizedProjects = authorizedProjects;
- }
-
- @SuppressWarnings("unused")
- private static List<InputSuggestion> suggestProjects(String matchWith) {
- return SuggestionUtils.suggestProjectPaths(matchWith);
- }
-
- @Editable(order=175, name="Authorized Role", description="Specify authorized role for above projects")
- @RoleChoice
- @NotEmpty
- public String getAuthorizedRoleName() {
- return authorizedRoleName;
- }
-
- public void setAuthorizedRoleName(String authorizedRoleName) {
- this.authorizedRoleName = authorizedRoleName;
- }
-
- public Role getAuthorizedRole() {
- Role role = OneDev.getInstance(RoleManager.class).find(authorizedRoleName);
- if (role == null)
- throw new ExplicitException("Undefined role: " + authorizedRoleName);
- return role;
- }
-
- public boolean isPermitted(Project project, Permission privilege) {
- return (authorizedProjects == null
- || PatternSet.parse(authorizedProjects).matches(new PathMatcher(), project.getPath()))
- && getAuthorizedRole().implies(privilege);
- }
-
-}
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/model/support/administration/ServiceDeskSetting.java b/server-core/src/main/java/io/onedev/server/model/support/administration/ServiceDeskSetting.java
index 3c00da2e9a..dbc480347d 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/administration/ServiceDeskSetting.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/administration/ServiceDeskSetting.java
@@ -32,34 +32,20 @@ public class ServiceDeskSetting implements Serializable {
private static final long serialVersionUID = 1L;
- private List<SenderAuthorization> senderAuthorizations = new ArrayList<>();
-
- private List<ProjectDesignation> projectDesignations = new ArrayList<>();
+ private List<DefaultProjectSetting> defaultProjectSettings = new ArrayList<>();
private List<IssueCreationSetting> issueCreationSettings = new ArrayList<>();
-
- @Editable(order=100, description="When sender email address can not be mapped to an existing user, "
- + "OneDev will use entries defined here to determine if the sender has permission to "
- + "create issues. For a particular sender, the first matching entry will take "
- + "effect")
- public List<SenderAuthorization> getSenderAuthorizations() {
- return senderAuthorizations;
- }
-
- public void setSenderAuthorizations(List<SenderAuthorization> senderAuthorizations) {
- this.senderAuthorizations = senderAuthorizations;
- }
@Editable(order=200, name="Default Projects", description="When email is sent to system email " +
"address without specifying project information, OneDev will use entries defined here " +
"to decide in which project to create issues. For a particular sender, the first " +
"matching entry will take effect")
- public List<ProjectDesignation> getProjectDesignations() {
- return projectDesignations;
+ public List<DefaultProjectSetting> getDefaultProjectSettings() {
+ return defaultProjectSettings;
}
- public void setProjectDesignations(List<ProjectDesignation> projectDesignations) {
- this.projectDesignations = projectDesignations;
+ public void setDefaultProjectSettings(List<DefaultProjectSetting> defaultProjectSettings) {
+ this.defaultProjectSettings = defaultProjectSettings;
}
@SuppressWarnings("unused")
@@ -70,8 +56,9 @@ public class ServiceDeskSetting implements Serializable {
return projectPaths;
}
- @Editable(order=300, description="Specify issue creation settings. For a particular sender and project, "
- + "the first matching entry will take effect")
+ @Editable(order=300, description="Specify issue creation settings. For a particular sender and project, " +
+ "the first matching entry will take effect. Issue creation will be disallowed if no matching " +
+ "entry found")
public List<IssueCreationSetting> getIssueCreationSettings() {
return issueCreationSettings;
}
@@ -81,29 +68,15 @@ public class ServiceDeskSetting implements Serializable {
}
@Nullable
- public SenderAuthorization getSenderAuthorization(String senderAddress) {
- Matcher matcher = new StringMatcher();
- for (SenderAuthorization authorization: senderAuthorizations) {
- String patterns = authorization.getSenderEmails();
- if (patterns == null)
- patterns = "*";
- PatternSet patternSet = PatternSet.parse(patterns);
- if (patternSet.matches(matcher, senderAddress))
- return authorization;
- }
- return null;
- }
-
- @Nullable
- public String getDesignatedProject(String senderAddress) {
+ public String getDefaultProject(String senderAddress) {
Matcher matcher = new StringMatcher();
- for (ProjectDesignation designation: projectDesignations) {
- String patterns = designation.getSenderEmails();
+ for (DefaultProjectSetting setting: defaultProjectSettings) {
+ String patterns = setting.getSenderEmails();
if (patterns == null)
patterns = "*";
PatternSet patternSet = PatternSet.parse(patterns);
if (patternSet.matches(matcher, senderAddress))
- return designation.getProject();
+ return setting.getProject();
}
return null;
}
@@ -125,37 +98,15 @@ public class ServiceDeskSetting implements Serializable {
return setting;
}
}
- String errorMessage = String.format("No issue creation setting (sender: %s, project: %s)",
+ String errorMessage = String.format("Not authorized to create issue (sender: %s, project: %s)",
senderAddress, project.getPath());
throw new ExplicitException(errorMessage);
}
- public void onRenameRole(String oldName, String newName) {
- for (SenderAuthorization authorization: getSenderAuthorizations()) {
- if (authorization.getAuthorizedRoleName().equals(oldName))
- authorization.setAuthorizedRoleName(newName);
- }
- }
-
- public Usage onDeleteRole(String roleName) {
- Usage usage = new Usage();
- int index = 1;
- for (SenderAuthorization authorization: getSenderAuthorizations()) {
- if (authorization.getAuthorizedRoleName().equals(roleName))
- usage.add("sender authorization #" + index + ": authorized role");
- index++;
- }
- return usage;
- }
-
public void onMoveProject(String oldPath, String newPath) {
- for (SenderAuthorization authorization: getSenderAuthorizations()) {
- authorization.setAuthorizedProjects(Project.substitutePath(
- authorization.getAuthorizedProjects(), oldPath, newPath));
- }
- for (ProjectDesignation designation: getProjectDesignations()) {
- designation.setProject(PathUtils.substituteSelfOrAncestor(
- designation.getProject(), oldPath, newPath));
+ for (DefaultProjectSetting setting: getDefaultProjectSettings()) {
+ setting.setProject(PathUtils.substituteSelfOrAncestor(
+ setting.getProject(), oldPath, newPath));
}
for (IssueCreationSetting setting: getIssueCreationSettings()) {
setting.setApplicableProjects(Project.substitutePath(
@@ -167,16 +118,9 @@ public class ServiceDeskSetting implements Serializable {
Usage usage = new Usage();
int index = 1;
- for (SenderAuthorization authorization: getSenderAuthorizations()) {
- if (Project.containsPath(authorization.getAuthorizedProjects(), projectPath))
- usage.add("sender authorization #" + index + ": authorized projects");
- index++;
- }
-
- index = 1;
- for (ProjectDesignation senderProject: getProjectDesignations()) {
- if (PathUtils.isSelfOrAncestor(projectPath, senderProject.getProject()))
- usage.add("sender project #" + index + ": project");
+ for (DefaultProjectSetting setting: getDefaultProjectSettings()) {
+ if (PathUtils.isSelfOrAncestor(projectPath, setting.getProject()))
+ usage.add("default project setting #" + index + ": project");
index++;
}
diff --git a/server-core/src/main/java/io/onedev/server/notification/IssueNotificationManager.java b/server-core/src/main/java/io/onedev/server/notification/IssueNotificationManager.java
index ac898533ae..7226684d88 100644
--- a/server-core/src/main/java/io/onedev/server/notification/IssueNotificationManager.java
+++ b/server-core/src/main/java/io/onedev/server/notification/IssueNotificationManager.java
@@ -1,35 +1,16 @@
package io.onedev.server.notification;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import io.onedev.server.entitymanager.*;
-import io.onedev.server.event.project.issue.*;
-import io.onedev.server.util.ProjectScope;
-import io.onedev.server.web.UrlManager;
-import io.onedev.server.web.asset.emoji.Emojis;
-import org.apache.commons.lang3.StringUtils;
-
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-
+import io.onedev.server.entitymanager.*;
import io.onedev.server.event.Listen;
-import io.onedev.server.xodus.VisitInfoManager;
+import io.onedev.server.event.project.issue.IssueCommentCreated;
+import io.onedev.server.event.project.issue.IssueEvent;
+import io.onedev.server.event.project.issue.IssueOpened;
+import io.onedev.server.event.project.issue.IssuesMoved;
import io.onedev.server.mail.MailManager;
-import io.onedev.server.markdown.MarkdownManager;
import io.onedev.server.markdown.MentionParser;
-import io.onedev.server.model.EmailAddress;
-import io.onedev.server.model.Group;
-import io.onedev.server.model.Issue;
-import io.onedev.server.model.IssueWatch;
-import io.onedev.server.model.User;
+import io.onedev.server.model.*;
import io.onedev.server.model.support.NamedQuery;
import io.onedev.server.model.support.QueryPersonalization;
import io.onedev.server.persistence.annotation.Transactional;
@@ -38,10 +19,22 @@ import io.onedev.server.search.entity.QueryWatchBuilder;
import io.onedev.server.search.entity.issue.IssueQuery;
import io.onedev.server.search.entity.issue.IssueQueryParseOption;
import io.onedev.server.security.SecurityUtils;
+import io.onedev.server.util.ProjectScope;
import io.onedev.server.util.commenttext.MarkdownText;
+import io.onedev.server.web.UrlManager;
+import io.onedev.server.web.asset.emoji.Emojis;
+import io.onedev.server.xodus.VisitInfoManager;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.mail.internet.InternetAddress;
+import java.util.*;
+import java.util.stream.Collectors;
import static io.onedev.server.notification.NotificationUtils.getEmailBody;
import static io.onedev.server.notification.NotificationUtils.isNotified;
+import static io.onedev.server.util.EmailAddressUtils.describe;
import static org.unbescape.html.HtmlEscape.escapeHtml5;
@Singleton
@@ -143,6 +136,13 @@ public class IssueNotificationManager {
}
}
+ private String getSenderName(InternetAddress internetAddress) {
+ var senderName = internetAddress.getPersonal();
+ if (senderName == null)
+ senderName = StringUtils.substringBefore(internetAddress.getAddress(), "@");
+ return senderName;
+ }
+
@Transactional
@Listen
public void on(IssueEvent event) {
@@ -155,20 +155,35 @@ public class IssueNotificationManager {
String url = event.getUrl();
String senderName;
- String summary;
- if (user != null) {
+ String summary;
+ IssueComment comment;
+ if (event instanceof IssueOpened && issue.getOnBehalfOf() != null) {
+ senderName = getSenderName(issue.getOnBehalfOf());
+ summary = describe(issue.getOnBehalfOf()) + " " + event.getActivity();
+ } else if (event instanceof IssueCommentCreated && (comment = ((IssueCommentCreated) event).getComment()).getOnBehalfOf() != null) {
+ senderName = getSenderName(comment.getOnBehalfOf());
+ summary = describe(comment.getOnBehalfOf()) + " " + event.getActivity();
+ } else if (user != null) {
senderName = user.getDisplayName();
- summary = user.getDisplayName() + " " + event.getActivity();
+ summary = senderName + " " + event.getActivity();
} else {
senderName = null;
summary = StringUtils.capitalize(event.getActivity());
}
setupWatches(issue);
+
+ Collection<String> notifiedEmailAddresses;
+ if (event instanceof IssueCommentCreated)
+ notifiedEmailAddresses = ((IssueCommentCreated) event).getNotifiedEmailAddresses();
+ else if (event instanceof IssueOpened)
+ notifiedEmailAddresses = ((IssueOpened) event).getNotifiedEmailAddresses();
+ else
+ notifiedEmailAddresses = new HashSet<>();
Collection<User> notifiedUsers = Sets.newHashSet();
if (user != null) {
- if (!user.isNotifyOwnEvents())
+ if (!user.isNotifyOwnEvents() || isNotified(notifiedEmailAddresses, user))
notifiedUsers.add(user);
if (!user.isSystem())
watchManager.watch(issue, user, true);
@@ -235,12 +250,6 @@ public class IssueNotificationManager {
notifiedUsers.addAll(entry.getValue());
}
- Collection<String> notifiedEmailAddresses;
- if (event instanceof IssueCommentCreated)
- notifiedEmailAddresses = ((IssueCommentCreated) event).getNotifiedEmailAddresses();
- else
- notifiedEmailAddresses = new ArrayList<>();
-
if (event.getCommentText() instanceof MarkdownText) {
MarkdownText markdown = (MarkdownText) event.getCommentText();
for (String userName: new MentionParser().parseMentions(markdown.getRendered())) {
@@ -272,7 +281,7 @@ public class IssueNotificationManager {
Collection<String> bccEmailAddresses = new HashSet<>();
- if (user != null && user.isNotifyOwnEvents()
+ if (user != null && !notifiedUsers.contains(user)
&& user.getPrimaryEmailAddress() != null
&& user.getPrimaryEmailAddress().isVerified()) {
bccEmailAddresses.add(user.getPrimaryEmailAddress().getValue());
@@ -291,6 +300,17 @@ public class IssueNotificationManager {
bccEmailAddresses.add(emailAddress.getValue());
}
}
+
+ for (var notifiedUser: notifiedUsers) {
+ for (var emailAddress: notifiedUser.getEmailAddresses()) {
+ if (emailAddress.isVerified())
+ notifiedEmailAddresses.add(emailAddress.getValue());
+ }
+ }
+ for (var participant: issue.getExternalParticipants()) {
+ if (!notifiedEmailAddresses.contains(participant.getAddress()))
+ bccEmailAddresses.add(participant.getAddress());
+ }
if (!bccEmailAddresses.isEmpty()) {
String subject = String.format(
diff --git a/server-core/src/main/java/io/onedev/server/notification/PullRequestNotificationManager.java b/server-core/src/main/java/io/onedev/server/notification/PullRequestNotificationManager.java
index 7d7a42d21a..42b3b8677e 100644
--- a/server-core/src/main/java/io/onedev/server/notification/PullRequestNotificationManager.java
+++ b/server-core/src/main/java/io/onedev/server/notification/PullRequestNotificationManager.java
@@ -126,9 +126,15 @@ public class PullRequestNotificationManager {
watchManager.watch(request, entry.getKey(), entry.getValue());
}
+ Collection<String> notifiedEmailAddresses;
+ if (event instanceof PullRequestCommentCreated)
+ notifiedEmailAddresses = ((PullRequestCommentCreated) event).getNotifiedEmailAddresses();
+ else
+ notifiedEmailAddresses = new HashSet<>();
+
Collection<User> notifiedUsers = Sets.newHashSet();
if (user != null) {
- if (!user.isNotifyOwnEvents())
+ if (!user.isNotifyOwnEvents() || isNotified(notifiedEmailAddresses, user))
notifiedUsers.add(user);
if (!user.isSystem())
watchManager.watch(request, user, true);
@@ -254,13 +260,7 @@ public class PullRequestNotificationManager {
notifiedUsers.add(reviewer);
}
}
-
- Collection<String> notifiedEmailAddresses;
- if (event instanceof PullRequestCommentCreated)
- notifiedEmailAddresses = ((PullRequestCommentCreated) event).getNotifiedEmailAddresses();
- else
- notifiedEmailAddresses = new ArrayList<>();
-
+
if (event.getCommentText() instanceof MarkdownText) {
MarkdownText markdown = (MarkdownText) event.getCommentText();
for (String userName : new MentionParser().parseMentions(markdown.getRendered())) {
@@ -291,7 +291,7 @@ public class PullRequestNotificationManager {
if (!event.isMinor()) {
Collection<String> bccEmailAddresses = new HashSet<>();
- if (user != null && user.isNotifyOwnEvents()
+ if (user != null && !notifiedUsers.contains(user)
&& user.getPrimaryEmailAddress() != null
&& user.getPrimaryEmailAddress().isVerified()) {
bccEmailAddresses.add(user.getPrimaryEmailAddress().getValue());
diff --git a/server-core/src/main/java/io/onedev/server/rest/resource/IssueCommentResource.java b/server-core/src/main/java/io/onedev/server/rest/resource/IssueCommentResource.java
index 51e5950bd5..b7807b6e35 100644
--- a/server-core/src/main/java/io/onedev/server/rest/resource/IssueCommentResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/resource/IssueCommentResource.java
@@ -47,7 +47,7 @@ public class IssueCommentResource {
|| !isAdministrator() && !comment.getUser().equals(getUser())) {
throw new UnauthorizedException();
}
- commentManager.create(comment, new ArrayList<>());
+ commentManager.create(comment);
return comment.getId();
}
diff --git a/server-core/src/main/java/io/onedev/server/security/SecurityUtils.java b/server-core/src/main/java/io/onedev/server/security/SecurityUtils.java
index ca32dc06d8..f4b5010db1 100644
--- a/server-core/src/main/java/io/onedev/server/security/SecurityUtils.java
+++ b/server-core/src/main/java/io/onedev/server/security/SecurityUtils.java
@@ -317,7 +317,11 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
}
public static boolean canReadCode(Project project) {
- return getSubject().isPermitted(new ProjectPermission(project, new ReadCode()));
+ return canReadCode(getSubject(), project);
+ }
+
+ public static boolean canReadCode(Subject subject, Project project) {
+ return subject.isPermitted(new ProjectPermission(project, new ReadCode()));
}
public static boolean canWriteCode(Project project) {
@@ -425,7 +429,11 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
}
public static boolean isAdministrator() {
- return getSubject().isPermitted(new SystemAdministration());
+ return isAdministrator(getSubject());
+ }
+
+ public static boolean isAdministrator(Subject subject) {
+ return subject.isPermitted(new SystemAdministration());
}
public static boolean canModifyOrDelete(CodeComment comment) {
diff --git a/server-core/src/main/java/io/onedev/server/util/EmailAddressUtils.java b/server-core/src/main/java/io/onedev/server/util/EmailAddressUtils.java
new file mode 100644
index 0000000000..7c7523de64
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/util/EmailAddressUtils.java
@@ -0,0 +1,14 @@
+package io.onedev.server.util;
+
+import javax.mail.internet.InternetAddress;
+
+public class EmailAddressUtils {
+
+ public static String describe(InternetAddress internetAddress) {
+ if (internetAddress.getPersonal() != null && !internetAddress.getPersonal().equalsIgnoreCase(internetAddress.getAddress()))
+ return internetAddress.getAddress() + " (" + internetAddress.getPersonal() + ")";
+ else
+ return internetAddress.getAddress();
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/IssueActivitiesPanel.java b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/IssueActivitiesPanel.java
index 274c557c44..6225615da6 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/IssueActivitiesPanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/IssueActivitiesPanel.java
@@ -281,7 +281,7 @@ public abstract class IssueActivitiesPanel extends Panel {
comment.setUser(SecurityUtils.getAuthUser());
comment.setDate(new Date());
comment.setIssue(getIssue());
- OneDev.getInstance(IssueCommentManager.class).create(comment, new ArrayList<>());
+ OneDev.getInstance(IssueCommentManager.class).create(comment);
if (showComments) {
((BasePage) getPage()).notifyObservablesChange(target, getIssue().getChangeObservables(false));
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueCommentedPanel.html b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueCommentedPanel.html
index c96412bf87..5cf9a25d1e 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueCommentedPanel.html
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueCommentedPanel.html
@@ -1,6 +1,6 @@
<wicket:panel>
<div class="head">
- <span wicket:id="user" class="user"></span> commented <span wicket:id="age"></span>
+ <span wicket:id="user" class="user"></span> commented <span wicket:id="age"></span> <span wicket:id="onBehalfOf"></span>
<a wicket:id="anchor" class="activity-anchor ml-2"><wicket:svg href="link" class="icon rotate-45"/></a>
</div>
<div wicket:id="body" class="body"></div>
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueCommentedPanel.java b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueCommentedPanel.java
index c9c02b9cbb..a0984b4f57 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueCommentedPanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueCommentedPanel.java
@@ -25,6 +25,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
+import static io.onedev.server.util.EmailAddressUtils.describe;
+import static org.unbescape.html.HtmlEscape.escapeHtml5;
+
@SuppressWarnings("serial")
class IssueCommentedPanel extends GenericPanel<IssueComment> {
@@ -42,6 +45,10 @@ class IssueCommentedPanel extends GenericPanel<IssueComment> {
add(new Label("user", getComment().getUser().getDisplayName()));
add(new Label("age", DateUtils.formatAge(getComment().getDate()))
.add(new AttributeAppender("title", DateUtils.formatDateTime(getComment().getDate()))));
+ if (getComment().getOnBehalfOf() != null)
+ add(new Label("onBehalfOf", " on behalf of <b>" + escapeHtml5(describe(getComment().getOnBehalfOf())) + "</b>").setEscapeModelStrings(false));
+ else
+ add(new WebMarkupContainer("onBehalfOf").setVisible(false));
add(new WebMarkupContainer("anchor") {
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueOpenedPanel.html b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueOpenedPanel.html
index 3d2fa63008..e2b9b304d4 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueOpenedPanel.html
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueOpenedPanel.html
@@ -1,6 +1,6 @@
<wicket:panel>
<div class="head">
- <span wicket:id="user" class="user"></span> opened <span wicket:id="age"></span>
+ <span wicket:id="user" class="user"></span> opened <span wicket:id="age"></span> <span wicket:id="onBehalfOf"></span>
</div>
<div wicket:id="body" class="body"></div>
</wicket:panel>
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueOpenedPanel.java b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueOpenedPanel.java
index 805de56713..e5359924f4 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueOpenedPanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/activities/activity/IssueOpenedPanel.java
@@ -15,6 +15,7 @@ import io.onedev.server.web.page.base.BasePage;
import io.onedev.server.web.util.DeleteCallback;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.model.IModel;
@@ -22,6 +23,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
+import static io.onedev.server.util.EmailAddressUtils.describe;
+import static org.unbescape.html.HtmlEscape.escapeHtml5;
+
@SuppressWarnings("serial")
class IssueOpenedPanel extends GenericPanel<Issue> {
@@ -37,6 +41,11 @@ class IssueOpenedPanel extends GenericPanel<Issue> {
add(new Label("user", issue.getSubmitter().getDisplayName()));
add(new Label("age", DateUtils.formatAge(issue.getSubmitDate()))
.add(new AttributeAppender("title", DateUtils.formatDateTime(issue.getSubmitDate()))));
+
+ if (issue.getOnBehalfOf() != null)
+ add(new Label("onBehalfOf", " on behalf of <b>" + escapeHtml5(describe(issue.getOnBehalfOf())) + "</b>").setEscapeModelStrings(false));
+ else
+ add(new WebMarkupContainer("onBehalfOf").setVisible(false));
add(new CommentPanel("body") {
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/authorizations/IssueAuthorizationsPanel.html b/server-core/src/main/java/io/onedev/server/web/component/issue/authorizations/IssueAuthorizationsPanel.html
index fa3487b722..22e105a0be 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/authorizations/IssueAuthorizationsPanel.html
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/authorizations/IssueAuthorizationsPanel.html
@@ -1,8 +1,8 @@
<wicket:panel>
<div class="issue-authorization-list">
<div class="alert alert-light alert-notice mb-5">
- Specify additional users able to access this confidential issue besides those granted permission via role.
- Users referenced in the issue will be authorized automatically
+ Specify additional users able to access this confidential issue besides those granted via role.
+ Users mentioned in the issue will be authorized automatically
</div>
<div class="head d-flex flex-wrap">
<div class="clearable-wrapper mr-3 mb-4">
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/side/IssueSidePanel.html b/server-core/src/main/java/io/onedev/server/web/component/issue/side/IssueSidePanel.html
index dd9ad240cc..a96583519c 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/side/IssueSidePanel.html
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/side/IssueSidePanel.html
@@ -58,6 +58,21 @@
</div>
</div>
<div wicket:id="watches" class="watches"></div>
+ <div wicket:id="externalParticipants" class="external-participants">
+ <div class="head">External Participants</div>
+ <ul class="body list-unstyled mb-0">
+ <li wicket:id="externalParticipants" class="pb-2">
+ <div class="d-flex">
+ <span wicket:id="label" class="mr-2"></span>
+ <a wicket:id="delete" class="flex-shrink-0 ml-auto" title="Remove this external participant from issue"><wicket:svg href="trash" class="icon icon-sm"></wicket:svg></a>
+ </div>
+ </li>
+ <span class="form-text font-size-sm text-muted">
+ <wicket:svg href="bulb" class="icon"></wicket:svg>
+ External participants do not have accounts and involve in the issue via email
+ </span>
+ </ul>
+ </div>
<div wicket:id="reference"></div>
<wicket:enclosure child="delete">
<div>
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/side/IssueSidePanel.java b/server-core/src/main/java/io/onedev/server/web/component/issue/side/IssueSidePanel.java
index 2eb20c7a3e..2f71b92a5b 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/side/IssueSidePanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/side/IssueSidePanel.java
@@ -1,17 +1,20 @@
package io.onedev.server.web.component.issue.side;
import com.google.common.collect.Lists;
+import com.hazelcast.shaded.org.snakeyaml.engine.v2.api.Load;
import io.onedev.server.OneDev;
import io.onedev.server.entitymanager.*;
import io.onedev.server.entityreference.EntityReference;
import io.onedev.server.model.*;
import io.onedev.server.model.support.EntityWatch;
+import io.onedev.server.persistence.TransactionManager;
import io.onedev.server.search.entity.EntityQuery;
import io.onedev.server.search.entity.issue.IssueQuery;
import io.onedev.server.search.entity.issue.IssueQueryLexer;
import io.onedev.server.search.entity.issue.IssueQueryParseOption;
import io.onedev.server.search.entity.issue.StateCriteria;
import io.onedev.server.security.SecurityUtils;
+import io.onedev.server.util.EmailAddressUtils;
import io.onedev.server.util.Input;
import io.onedev.server.util.LinkSide;
import io.onedev.server.util.Similarities;
@@ -76,12 +79,15 @@ import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import javax.annotation.Nullable;
+import javax.mail.internet.InternetAddress;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import static io.onedev.server.search.entity.issue.IssueQuery.parse;
import static io.onedev.server.security.SecurityUtils.canEditIssueLink;
+import static io.onedev.server.util.EmailAddressUtils.describe;
+import static java.util.Comparator.comparing;
@SuppressWarnings("serial")
public abstract class IssueSidePanel extends Panel {
@@ -138,6 +144,7 @@ public abstract class IssueSidePanel extends Panel {
}
});
+ addOrReplace(newExternalParticipantsContainer());
addOrReplace(new EntityReferencePanel("reference") {
@@ -859,6 +866,60 @@ public abstract class IssueSidePanel extends Panel {
return container;
}
+
+ private Component newExternalParticipantsContainer() {
+ WebMarkupContainer container = new WebMarkupContainer("externalParticipants") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(!getIssue().getExternalParticipants().isEmpty());
+ }
+
+ };
+ container.setOutputMarkupId(true);
+
+ container.add(new ListView<>("externalParticipants", new LoadableDetachableModel<List<InternetAddress>>() {
+
+ @Override
+ protected List<InternetAddress> load() {
+ var addresses = new ArrayList<>(getIssue().getExternalParticipants());
+ addresses.sort(comparing(EmailAddressUtils::describe));
+ return addresses;
+ }
+
+ }) {
+
+ @Override
+ protected void populateItem(ListItem<InternetAddress> item) {
+ item.add(new Label("label", describe(item.getModelObject())));
+ item.add(new AjaxLink<Void>("delete") {
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.getAjaxCallListeners().add(new ConfirmClickListener("'" + describe(item.getModelObject()) + "' will not be able to participate in this issue. Do you want to continue?"));
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(SecurityUtils.canManageIssues(getIssue().getProject()));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ OneDev.getInstance(TransactionManager.class).run(() -> {
+ getIssue().getExternalParticipants().remove(item.getModelObject());
+ });
+ target.add(container);
+ }
+ });
+ }
+
+ });
+
+ return container;
+ }
private Project getProject() {
return getIssue().getProject();
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/issues/boards/AbstractColumnPanel.java b/server-core/src/main/java/io/onedev/server/web/page/project/issues/boards/AbstractColumnPanel.java
index 15a70422a3..e1faa7af96 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/project/issues/boards/AbstractColumnPanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/project/issues/boards/AbstractColumnPanel.java
@@ -28,6 +28,7 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.visit.IVisitor;
import javax.annotation.Nullable;
+import java.util.HashSet;
@SuppressWarnings("serial")
abstract class AbstractColumnPanel extends Panel implements EditContext {
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/issues/create/NewIssuePage.java b/server-core/src/main/java/io/onedev/server/web/page/project/issues/create/NewIssuePage.java
index f2540942d3..780d9e5a6e 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/project/issues/create/NewIssuePage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/project/issues/create/NewIssuePage.java
@@ -32,6 +32,7 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import javax.annotation.Nullable;
+import java.util.HashSet;
import java.util.List;
@SuppressWarnings("serial")
diff --git a/server-ee b/server-ee
index ae7e17ffd0..7cf0c9adb4 160000
--- a/server-ee
+++ b/server-ee
@@ -1 +1 @@
-Subproject commit ae7e17ffd0af1f68d67a43ebe6530c958f5d8e89
+Subproject commit 7cf0c9adb48d39ffc055344025626ec704c65d02
diff --git a/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java b/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java
index 2b72fe4515..5f514a7d1b 100644
--- a/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java
+++ b/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java
@@ -7,7 +7,6 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-import io.onedev.agent.job.ImageMappingFacade;
import io.onedev.commons.bootstrap.Bootstrap;
import io.onedev.commons.utils.*;
import io.onedev.commons.utils.command.Commandline;
@@ -24,7 +23,6 @@ import io.onedev.server.entitymanager.SettingManager;
import io.onedev.server.job.JobContext;
import io.onedev.server.job.JobManager;
import io.onedev.server.job.JobRunnable;
-import io.onedev.server.model.support.ImageMapping;
import io.onedev.server.model.support.administration.jobexecutor.*;
import io.onedev.server.plugin.executor.kubernetes.KubernetesExecutor.TestData;
import io.onedev.server.terminal.CommandlineShell;
@@ -111,12 +109,8 @@ public class KubernetesExecutor extends JobExecutor implements RegistryLoginAwar
private boolean alwaysPullImage = true;
- private List<ImageMapping> imageMappings = new ArrayList<>();
-
private transient volatile String containerName;
- private transient List<ImageMappingFacade> imageMappingFacades;
-
@Editable(order=200, description="Specify registry logins if necessary. For built-in registry, " +
"use <code>@server_url@</code> for registry url, <code>@job_token@</code> for user name, and " +
"access token for password")
@@ -277,19 +271,6 @@ public class KubernetesExecutor extends JobExecutor implements RegistryLoginAwar
this.kubeCtlPath = kubeCtlPath;
}
- @Editable(order=28000, group="More Settings", description = "Optionally maps a docker image to a different " +
- "image. The first matching entry will take effect, or image will remain unchanged if no matching entries " +
- "found. For instance a mapping entry with <code>From</code> specified as <code>1dev/k8s-helper:(.*)</code>, " +
- "and <code>To</code> specified as <code>my-local-registry/k8s-helper:$1</code> will map the " +
- "k8s helper image from official docker registry to local registry, with repository and tag unchanged")
- public List<ImageMapping> getImageMappings() {
- return imageMappings;
- }
-
- public void setImageMappings(List<ImageMapping> imageMappings) {
- this.imageMappings = imageMappings;
- }
-
@Override
public boolean execute(JobContext jobContext, TaskLogger jobLogger) {
var clusterManager = OneDev.getInstance(ClusterManager.class);
@@ -701,7 +682,7 @@ public class KubernetesExecutor extends JobExecutor implements RegistryLoginAwar
Map<String, Object> podSpec = new LinkedHashMap<>();
Map<Object, Object> containerSpec = newLinkedHashMap(
"name", "default",
- "image", mapImage(jobService.getImage()));
+ "image", jobService.getImage());
if (isAlwaysPullImage())
containerSpec.put("imagePullPolicy", "Always");
Map<Object, Object> resourcesSpec = newLinkedHashMap(
@@ -963,7 +944,7 @@ public class KubernetesExecutor extends JobExecutor implements RegistryLoginAwar
List<String> containerNames = newArrayList("init");
- String helperImage = mapImage(IMAGE_REPO + ":" + KubernetesHelper.getVersion());
+ String helperImage = IMAGE_REPO + ":" + KubernetesHelper.getVersion();
ArrayList<Map<Object, Object>> commonEnvs = new ArrayList<>();
commonEnvs.add(newLinkedHashMap(
@@ -991,7 +972,7 @@ public class KubernetesExecutor extends JobExecutor implements RegistryLoginAwar
stepContainerSpec = newHashMap(
"name", containerName,
- "image", mapImage(commandFacade.getImage()));
+ "image", commandFacade.getImage());
if (isAlwaysPullImage())
stepContainerSpec.put("imagePullPolicy", "Always");
if (commandFacade.isUseTTY())
@@ -1526,16 +1507,6 @@ public class KubernetesExecutor extends JobExecutor implements RegistryLoginAwar
}
}
- private List<ImageMappingFacade> getImageMappingFacades() {
- if (imageMappingFacades == null)
- imageMappingFacades = getImageMappings().stream().map(it->it.getFacade()).collect(toList());
- return imageMappingFacades;
- }
-
- private String mapImage(String image) {
- return ImageMappingFacade.map(getImageMappingFacades(), image);
- }
-
private static interface AbortChecker {
@Nullable
diff --git a/server-plugin/server-plugin-executor-remotedocker/src/main/java/io/onedev/server/plugin/executor/remotedocker/RemoteDockerExecutor.java b/server-plugin/server-plugin-executor-remotedocker/src/main/java/io/onedev/server/plugin/executor/remotedocker/RemoteDockerExecutor.java
index afbe4f5b8f..d0c83c0a9f 100644
--- a/server-plugin/server-plugin-executor-remotedocker/src/main/java/io/onedev/server/plugin/executor/remotedocker/RemoteDockerExecutor.java
+++ b/server-plugin/server-plugin-executor-remotedocker/src/main/java/io/onedev/server/plugin/executor/remotedocker/RemoteDockerExecutor.java
@@ -15,7 +15,6 @@ import io.onedev.server.entitymanager.SettingManager;
import io.onedev.server.job.*;
import io.onedev.server.job.log.LogManager;
import io.onedev.server.job.log.ServerJobLogger;
-import io.onedev.server.model.support.ImageMapping;
import io.onedev.server.persistence.SessionManager;
import io.onedev.server.plugin.executor.serverdocker.ServerDockerExecutor;
import io.onedev.server.search.entity.agent.AgentQuery;
@@ -103,14 +102,13 @@ public class RemoteDockerExecutor extends ServerDockerExecutor {
String jobToken = jobContext.getJobToken();
var registryLogins = getRegistryLogins().stream().map(it->it.getFacade(jobToken)).collect(toList());
- var imageMappings = getImageMappings().stream().map(ImageMapping::getFacade).collect(toList());
DockerJobData jobData = new DockerJobData(jobToken, getName(), jobContext.getProjectPath(),
jobContext.getProjectId(), jobContext.getRefName(), jobContext.getCommitId().name(),
jobContext.getBuildNumber(), jobContext.getActions(), jobContext.getRetried(),
- jobContext.getServices(), registryLogins, imageMappings,
- isMountDockerSock(), getDockerSockPath(), getDockerBuilder(), getCpuLimit(),
- getMemoryLimit(), getRunOptions(), getNetworkOptions(), isAlwaysPullImage());
+ jobContext.getServices(), registryLogins, isMountDockerSock(), getDockerSockPath(),
+ getDockerBuilder(), getCpuLimit(), getMemoryLimit(), getRunOptions(),
+ getNetworkOptions(), isAlwaysPullImage());
try {
return call(agentSession, jobData, jobContext.getTimeout()*1000L);
diff --git a/server-plugin/server-plugin-executor-serverdocker/src/main/java/io/onedev/server/plugin/executor/serverdocker/ServerDockerExecutor.java b/server-plugin/server-plugin-executor-serverdocker/src/main/java/io/onedev/server/plugin/executor/serverdocker/ServerDockerExecutor.java
index 07ccf2a5f7..9b5a51f63d 100644
--- a/server-plugin/server-plugin-executor-serverdocker/src/main/java/io/onedev/server/plugin/executor/serverdocker/ServerDockerExecutor.java
+++ b/server-plugin/server-plugin-executor-serverdocker/src/main/java/io/onedev/server/plugin/executor/serverdocker/ServerDockerExecutor.java
@@ -3,7 +3,6 @@ package io.onedev.server.plugin.executor.serverdocker;
import com.google.common.base.Preconditions;
import io.onedev.agent.DockerExecutorUtils;
import io.onedev.agent.ExecutorUtils;
-import io.onedev.agent.job.ImageMappingFacade;
import io.onedev.commons.bootstrap.Bootstrap;
import io.onedev.commons.loader.AppLoader;
import io.onedev.commons.utils.ExplicitException;
@@ -20,7 +19,6 @@ import io.onedev.server.cluster.ClusterTask;
import io.onedev.server.entitymanager.SettingManager;
import io.onedev.server.git.location.GitLocation;
import io.onedev.server.job.*;
-import io.onedev.server.model.support.ImageMapping;
import io.onedev.server.model.support.administration.jobexecutor.JobExecutor;
import io.onedev.server.model.support.administration.jobexecutor.RegistryLogin;
import io.onedev.server.model.support.administration.jobexecutor.RegistryLoginAware;
@@ -78,16 +76,12 @@ public class ServerDockerExecutor extends JobExecutor implements RegistryLoginAw
private String concurrency;
- private List<ImageMapping> imageMappings = new ArrayList<>();
-
private transient volatile File hostBuildHome;
private transient volatile LeafFacade runningStep;
private transient volatile String containerName;
- private transient List<ImageMappingFacade> imageMappingFacades;
-
private static volatile String hostInstallPath;
@Editable(order=400, description="Specify registry logins if necessary. For built-in registry, " +
@@ -217,17 +211,6 @@ public class ServerDockerExecutor extends JobExecutor implements RegistryLoginAw
public void setDockerExecutable(String dockerExecutable) {
this.dockerExecutable = dockerExecutable;
}
-
- @Editable(order=50150, group="More Settings", description = "Optionally maps a docker image to a different " +
- "image. The first matching entry will take effect, or image will remain unchanged if no matching " +
- "entries found")
- public List<ImageMapping> getImageMappings() {
- return imageMappings;
- }
-
- public void setImageMappings(List<ImageMapping> imageMappings) {
- this.imageMappings = imageMappings;
- }
private Commandline newDocker() {
Commandline docker;
@@ -300,9 +283,9 @@ public class ServerDockerExecutor extends JobExecutor implements RegistryLoginAw
var docker = newDocker();
var registryLogins = merge(jobService.getRegistryLogins(), getRegistryLogins(jobToken));
callWithDockerConfig(docker, registryLogins, () -> {
- startService(docker, network, jobService, osInfo, getImageMappingFacades(),
+ startService(docker, network, jobService, osInfo,
getCpuLimit(), getMemoryLimit(), jobLogger);
- return null;
+ return null;
});
}
@@ -339,7 +322,6 @@ public class ServerDockerExecutor extends JobExecutor implements RegistryLoginAw
@Nullable String entrypoint, List<String> arguments,
Map<String, String> environments, @Nullable String workingDir,
Map<String, String> volumeMounts, List<Integer> position, boolean useTTY) {
- image = mapImage(image);
containerName = network + "-step-" + stringifyStepPosition(position);
try {
var useProcessIsolation = isUseProcessIsolation(docker, image, osInfo, jobLogger);
@@ -662,21 +644,11 @@ public class ServerDockerExecutor extends JobExecutor implements RegistryLoginAw
}
return hostInstallPath + path.substring(installPath.length());
}
-
- private List<ImageMappingFacade> getImageMappingFacades() {
- if (imageMappingFacades == null)
- imageMappingFacades = getImageMappings().stream().map(it->it.getFacade()).collect(toList());
- return imageMappingFacades;
- }
@Override
public List<RegistryLoginFacade> getRegistryLogins(String jobToken) {
return getRegistryLogins().stream().map(it->it.getFacade(jobToken)).collect(toList());
}
-
- private String mapImage(String image) {
- return ImageMappingFacade.map(getImageMappingFacades(), image);
- }
@Override
public void test(TestData testData, TaskLogger jobLogger) {