Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Organization: find by name in case-insensitive
Browse files Browse the repository at this point in the history
Usages of `findByOrganizationName` replaced with `findByName`
as `findByName` which finds target with name in case-insensitive
is exactly same with `findByOrganizationName`.

and this commit includes fix incorrect method name
`getVisiableProjects` to `getVisibleProjects`.
  • Loading branch information
laziel committed Aug 4, 2014
1 parent 9018993 commit 4e94308
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
8 changes: 4 additions & 4 deletions app/controllers/EnrollOrganizationApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Result enroll(String organizationName) {
return result.getResult();
}

Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
if (!User.enrolled(organization)) {
User user = UserApp.currentUser();
user.enroll(organization);
Expand All @@ -47,7 +47,7 @@ public static Result enroll(String organizationName) {
}

private static ValidationResult validateForEnroll(String organizationName) {
Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
if (organization == null) {
return new ValidationResult(badRequest(), true);
}
Expand All @@ -67,7 +67,7 @@ public static Result cancelEnroll(String organizationName) {
return result.getResult();
}

Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
if (User.enrolled(organization)) {
User user = UserApp.currentUser();
user.cancelEnroll(organization);
Expand All @@ -78,7 +78,7 @@ public static Result cancelEnroll(String organizationName) {
}

private static ValidationResult validateForCancelEnroll(String organizationName) {
Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
if (organization == null) {
return new ValidationResult(badRequest(), true);
}
Expand Down
18 changes: 9 additions & 9 deletions app/controllers/OrganizationApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static Result addMember(String organizationName) {
}

User user = User.findByLoginId(addMemberForm.get().loginId);
Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
OrganizationUser.assignRole(user.id, organization.id, RoleType.ORG_MEMBER.roleType());
organization.cleanEnrolledUsers();
NotificationEvent.afterOrganizationMemberRequest(organization, user, RequestState.ACCEPT);
Expand All @@ -146,7 +146,7 @@ private static Result validateForAddMember(Form<User> addMemberForm, String orga
return redirect(routes.OrganizationApp.members(organizationName));
}

Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
if (organization == null) {
flash(Constants.WARNING, "organization.member.unknownOrganization");
return redirect(routes.OrganizationApp.members(organizationName));
Expand All @@ -173,7 +173,7 @@ public static Result deleteMember(String organizationName, Long userId) {
return result;
}

Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
OrganizationUser.delete(organization.id, userId);

if (UserApp.currentUser().id.equals(userId)) {
Expand All @@ -184,7 +184,7 @@ public static Result deleteMember(String organizationName, Long userId) {
}

private static Result validateForDeleteMember(String organizationName, Long userId) {
Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
if (organization == null) {
return notFound(ErrorViews.NotFound.render("organization.member.unknownOrganization", organization));
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public static Result editMember(String organizationName, Long userId) {
return result;
}

Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
OrganizationUser.assignRole(userId, organization.id, roleForm.get().id);

return status(Http.Status.NO_CONTENT);
Expand All @@ -229,7 +229,7 @@ private static Result validateForEditMember(Form<Role> roleForm, String organiza
return okWithLocation(routes.OrganizationApp.members(organizationName).url());
}

Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
if (organization == null) {
return notFound(ErrorViews.NotFound.render("organization.member.unknownOrganization", organization));
}
Expand Down Expand Up @@ -258,13 +258,13 @@ public static Result members(String organizationName) {
return result;
}

Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);

return ok(members.render(organization, Role.findOrganizationRoles()));
}

private static Result validateForSetting(String organizationName) {
Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);
if (organization == null) {
return notFound(ErrorViews.NotFound.render("organization.member.unknownOrganization", organization));
}
Expand All @@ -283,7 +283,7 @@ public static Result settingForm(String organizationName) {
return result;
}

Organization organization = Organization.findByOrganizationName(organizationName);
Organization organization = Organization.findByName(organizationName);

return ok(setting.render(organization, form(Organization.class).fill(organization)));
}
Expand Down
8 changes: 2 additions & 6 deletions app/models/Organization.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void add(OrganizationUser ou) {
}

public static Organization findByName(String name) {
return find.where().eq("name", name).findUnique();
return find.where().ieq("name", name).findUnique();
}

public static boolean isNameExist(String name) {
Expand All @@ -93,7 +93,7 @@ public void cleanEnrolledUsers() {
}
}

public List<Project> getVisiableProjects(User user) {
public List<Project> getVisibleProjects(User user) {
List<Project> result = new ArrayList<>();
if(OrganizationUser.isAdmin(this.id, user.id)) {
result.addAll(this.projects);
Expand Down Expand Up @@ -121,10 +121,6 @@ public int compare(Project p1, Project p2) {
return result;
}

public static Organization findByOrganizationName(String organizationName) {
return find.where().ieq("name", organizationName).findUnique();
}

/**
* Find organizations which contains {@code userLoginId} as member.
*
Expand Down
2 changes: 1 addition & 1 deletion app/views/organization/view.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h3><span id="project-description">@org.descr</span></h3>
</div>
</div>
<ul class="all-projects">
@for(project <- org.getVisiableProjects(UserApp.currentUser())) {
@for(project <- org.getVisibleProjects(UserApp.currentUser())) {
<li class="project" data-item="project-item" data-value="@project.name @project.overview">
<div class="info-wrap">
<div class="owner-avatar-wrap">
Expand Down

0 comments on commit 4e94308

Please sign in to comment.