Skip to content

Commit

Permalink
issue: Fix missing assignee editing
Browse files Browse the repository at this point in the history
  • Loading branch information
doortts committed Aug 10, 2017
1 parent 5dfac4d commit 5ce4306
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 24 deletions.
26 changes: 23 additions & 3 deletions app/controllers/IssueApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ public static Result newIssue(String ownerName, String projectName) {
project = toAnotherProject;
}
}
removeAnonymousAssignee(newIssue);

if (newIssue.body == null) {
return status(REQUEST_ENTITY_TOO_LARGE,
Expand All @@ -497,6 +496,19 @@ public static Result newIssue(String ownerName, String projectName) {
newIssue.setAuthor(UserApp.currentUser());
newIssue.project = project;

String assineeLoginId = null;
String[] assigneeLoginIds = request().body().asMultipartFormData().asFormUrlEncoded().get("assigneeLoginId");
if(assigneeLoginIds != null && assigneeLoginIds.length > 0) {
assineeLoginId = assigneeLoginIds[0];
}

User assigneeUser = User.findByLoginId(assineeLoginId);

if(!assigneeUser.isAnonymous()){
newIssue.assignee = new Assignee(assigneeUser.id, project.id);
} else {
newIssue.assignee = null;
}
newIssue.state = State.OPEN;

if (newIssue.project.id.equals(Project.findByOwnerAndProjectName(ownerName, projectName).id)) {
Expand Down Expand Up @@ -605,8 +617,16 @@ public static Result editIssue(String ownerName, String projectName, Long number

final Issue issue = issueForm.get();

setAssignee(issueForm, issue, project);
removeAnonymousAssignee(issue);
String assineeLoginId = request().body().asMultipartFormData()
.asFormUrlEncoded().get("assigneeLoginId")[0];

User assigneeUser = User.findByLoginId(assineeLoginId);
if(!assigneeUser.isAnonymous()){
issue.assignee = new Assignee(assigneeUser.id, project.id);
} else {
issue.assignee = null;
}

setMilestone(issueForm, issue);
issue.dueDate = JodaDateUtil.lastSecondOfDay(issue.dueDate);

Expand Down
56 changes: 46 additions & 10 deletions app/controllers/api/IssueApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,51 @@ public static Date parseDateString(JsonNode dateStringNode){
return null;
}

@IsAllowed(Operation.READ)
public static Result findAssignableUsersOfProject(String ownerName, String projectName, String query) {
if (!request().accepts("application/json")) {
return status(Http.Status.NOT_ACCEPTABLE);
}

Project project = Project.findByOwnerAndProjectName(ownerName, projectName);
List<ObjectNode> users = new ArrayList<>();

if(StringUtils.isEmpty(query)){
addUserToUsersWithCustomName(UserApp.currentUser(), users, Messages.get("issue.assignToMe"));

for(User user: project.getAssignableUsers()){
addUserToUsers(user, users);
}

return ok(toJson(users));
}

ExpressionList<User> el = getUserExpressionList(query, request().getQueryString("type"));

int total = el.findRowCount();
if (total > MAX_FETCH_USERS) {
el.setMaxRows(MAX_FETCH_USERS);
response().setHeader("Content-Range", "items " + MAX_FETCH_USERS + "/" + total);
}

gatheringUsersFromExpressionList(project, users, el);

return ok(toJson(users));
}

private static void gatheringUsersFromExpressionList(Project project, List<ObjectNode> users, ExpressionList<User> el) {
for (User user : el.findList()) {
if (project.isPublic()) {
addUserToUsers(user, users);
} else {
if (user.isMemberOf(project)
|| project.hasGroup() && user.isMemberOf(project.organization)) {
addUserToUsers(user, users);
}
}
}
}

@IsAllowed(Operation.READ)
public static Result findAssignableUsers(String ownerName, String projectName, Long number, String query) {
if (!request().accepts("application/json")) {
Expand Down Expand Up @@ -299,16 +344,7 @@ public static Result findAssignableUsers(String ownerName, String projectName, L
response().setHeader("Content-Range", "items " + MAX_FETCH_USERS + "/" + total);
}

for (User user : el.findList()) {
if (project.isPublic()) {
addUserToUsers(user, users);
} else {
if (user.isMemberOf(project)
|| project.hasGroup() && user.isMemberOf(project.organization)) {
addUserToUsers(user, users);
}
}
}
gatheringUsersFromExpressionList(project, users, el);

return ok(toJson(users));
}
Expand Down
7 changes: 7 additions & 0 deletions app/views/issue/create.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<script type="text/javascript" src="@routes.Assets.at("javascripts/lib/atjs/jquery.caret.min.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("javascripts/lib/atjs/jquery.atwho.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("javascripts/common/yona.Subtask.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("javascripts/service/yona.issue.Assginee.js")"></script>
<script type="text/javascript">
$(function(){
// yobi.issue.Write
Expand All @@ -166,6 +167,12 @@
if(@isFromGlobalMenuNew) {
$(".subtask-message").trigger("click");
}

yonaAssgineeModule(
"@api.routes.IssueApi.findAssignableUsersOfProject(project.owner, project.name)",
"",
"@Messages("issue.assignee")"
);
});
</script>
}
7 changes: 7 additions & 0 deletions app/views/issue/edit.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<script type="text/javascript" src="@routes.Assets.at("javascripts/lib/atjs/jquery.caret.min.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("javascripts/lib/atjs/jquery.atwho.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("javascripts/common/yona.Subtask.js")"></script>
<script type="text/javascript" src="@routes.Assets.at("javascripts/service/yona.issue.Assginee.js")"></script>
<script type="text/javascript">
$(function(){
// yobi.issue.Write
Expand All @@ -202,6 +203,12 @@
"target": "textarea[id^=editor-]",
"url" : "@routes.ProjectApp.mentionList(project.owner, project.name)"
});

yonaAssgineeModule(
"@api.routes.IssueApi.findAssignableUsersOfProject(project.owner, project.name)",
"",
"@Messages("issue.assignee")"
);
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion app/views/issue/partial_assignee.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
}
}

<input type="hidden" class="bigdrop" id="assignee" placeholder="@Messages("issue.noAssignee")" value="@assignee" style="width: 100%" title="">
<input type="hidden" class="bigdrop" id="assignee" name="assigneeLoginId" placeholder="@Messages("issue.noAssignee")" value="@assignee" style="width: 100%" title="">
1 change: 1 addition & 0 deletions app/views/user/view.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h3>@Messages("userinfo.profile")</h3>
<div class="whoami usf-group">
<span class="name">@user.name</span>
<span class="loginid">@{"@"}@user.loginId</span>
<span class="email">@user.email</span>
@if(user != null && requestHeader.session != null && user.loginId == UserApp.currentUser.loginId){
<div class="edit">
<a href="@routes.UserApp.editUserInfoForm()" class="ybtn ybtn-default ybtn-mini"><i class="yobicon-edit"></i> @Messages("userinfo.editProfile")</a>
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ POST /-_-api/v1/favoriteProjects/:projectId
GET /-_-api/v1/favoriteOrganizations controllers.api.UserApi.getFoveriteOrganizations
POST /-_-api/v1/favoriteOrganizations/:organizationId controllers.api.UserApi.toggleFoveriteOrganization(organizationId:String)
GET /-_-api/v1/owners/:owner/projects/:projectName/issues/:number/assignableUsers controllers.api.IssueApi.findAssignableUsers(owner:String, projectName:String, number:Long, query: String ?= "")
GET /-_-api/v1/owners/:owner/projects/:projectName/assignableUsers controllers.api.IssueApi.findAssignableUsersOfProject(owner:String, projectName:String, query: String ?= "")
POST /-_-api/v1/owners/:owner/projects/:projectName/issues/:number/assignees controllers.api.IssueApi.updateAssginees(owner:String, projectName:String, number:Long)
GET /-_-api/v1/users controllers.UserApp.users(query: String ?= "")
POST /-_-api/v1/users controllers.api.UserApi.newUser()
Expand Down
21 changes: 11 additions & 10 deletions public/javascripts/service/yona.issue.Assginee.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function yonaAssgineeModule(findAssignableUsersApiUrl, updateAssgineesApiUrl, me
// using its formatResult renderer - that way the repository name is shown preselected
var id = $(element).val();

console.log((id !== "") + "id: " + id);
if (id !== "") {
$.ajax(findAssignableUsersApiUrl + "?query=" + id + "&type=loginId", {
dataType: "json"
Expand All @@ -82,13 +81,15 @@ function yonaAssgineeModule(findAssignableUsersApiUrl, updateAssgineesApiUrl, me
$assignee.on("select2-selecting", function(selected) {
var data = { assignees: [selected.val] };

$.ajax(updateAssgineesApiUrl, {
method: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(data)
}).done(function(response){
$yobi.notify(message + ": " + response.assignee.name, 3000);
});
if(updateAssgineesApiUrl){
$.ajax(updateAssgineesApiUrl, {
method: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(data)
}).done(function(response){
$yobi.notify(message + ": " + response.assignee.name, 3000);
});
}
});
};
}

0 comments on commit 5ce4306

Please sign in to comment.