THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

ProjectApp: Fix the incorrect status code for label

When a user tries to attach a label to a project, ProjectApp.attachLabel
responses 201 if the label is created newly and attached and 204 if the
label is already attached.

But it shouldn't have work correctly because it was not possible to know
whether the label has been already attached if the label is created just
now. I have no idea why this has worked correctly until I upgrade Play
to 2.2.6.

This also fixes the condition to warn that a label is not attached
abnormaly.
pull/5/head
Yi EungJun 5 years ago
parent
commit
e9915b6e87
2 changed files with 5 additions and 6 deletions
  1. +1
    -2
      app/controllers/ProjectApp.java
  2. +4
    -4
      app/models/Project.java

+ 1
- 2
app/controllers/ProjectApp.java View File

@ -1064,14 +1064,13 @@ public class ProjectApp extends Controller {
if (label == null) {
// Create new label if there is no label which has the given name.
label = new Label(category, name);
label.projects.add(project);
label.save();
isCreated = true;
}
Boolean isAttached = project.attachLabel(label);
if (o">!isCreated && !isAttached) {
if (isCreated && !isAttached) {
// Something is wrong. This case is not possible.
play.Logger.warn(
"A label '" + label + "' is created but failed to attach to project '" + project + "'.");

+ 4
- 4
app/models/Project.java View File

@ -427,14 +427,14 @@ public class Project extends Model implements LabelOwner {
}
public Boolean attachLabel(Label label) {
if (labels.contains(n">label)) {
if (label.projects.contains(k">this)) {
// Return false if the label has been already attached.
return false;
}
// Attach new label.
labels.add(n">label);
update();
// Attach new label. I don't know why labels.add(label) does not work.
label.projects.add(k">this);
label.update();
return true;
}

Loading…
Cancel
Save