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

Commit

Permalink
Merge branch 'issue-1855' of dlab/hive
Browse files Browse the repository at this point in the history
from pull-request 1413

* refs/heads/issue-1855:
  refactors codes
  fixes a bug that site admin does not have group admin authorization.

Reviewed-by: 채수원 <sw.chae@navercorp.com>
Reviewed-by: 백기선 <keesun.baik@navercorp.com>
Reviewed-by: 이응준 <eungjun.yi@navercorp.com>
  • Loading branch information
이응준 committed Jan 27, 2015
2 parents 9086c94 + 8caf892 commit fb98846
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
23 changes: 14 additions & 9 deletions app/controllers/OrganizationApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package controllers;

import controllers.annotation.AnonymousCheck;
import controllers.annotation.IsAllowed;
import models.*;
import models.enumeration.Operation;
import models.enumeration.RequestState;
Expand All @@ -46,10 +45,7 @@
import javax.validation.ConstraintViolation;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.*;

import static play.data.Form.form;
import static utils.LogoUtil.*;
Expand Down Expand Up @@ -152,7 +148,7 @@ private static Result validateForAddMember(Form<User> addMemberForm, String orga
}

User currentUser = UserApp.currentUser();
if (!OrganizationUser.isAdmin(organization.id, currentUser.id)) {
if (!AccessControl.isAllowed(currentUser, organization.asResource(), Operation.UPDATE)) {
flash(Constants.WARNING, "organization.member.needManagerRole");
return redirect(routes.OrganizationApp.members(organizationName));
}
Expand Down Expand Up @@ -243,7 +239,8 @@ private static Result validateForEditMember(Form<Role> roleForm, String organiza
flash(Constants.WARNING, "organization.member.needManagerRole");
return okWithLocation(routes.OrganizationApp.members(organizationName).url());
}
if (OrganizationUser.isAdmin(organization.id, userId) && organization.getAdmins().size() == 1) {

if (organization.isLastAdmin(currentUser) && roleForm.get().id.equals(RoleType.ORG_MEMBER.roleType())) {
flash(Constants.WARNING, "organization.member.atLeastOneAdmin");
return okWithLocation(routes.OrganizationApp.members(organizationName).url());
}
Expand All @@ -270,7 +267,7 @@ public static ValidationResult validateForLeave(String organizationName) {
return new ValidationResult(notFound(getJsonErrorMsg("organization.member.unknownOrganization")), true);
}

if (OrganizationUser.isAdmin(organization.id, UserApp.currentUser().id)) {
if (!AccessControl.isAllowed(UserApp.currentUser(), organization.asResource(), Operation.LEAVE)) {
if (OrganizationUser.findAdminsOf(organization).size() == 1) {
return new ValidationResult(forbidden(getJsonErrorMsg("organization.member.atLeastOneAdmin")), true);
}
Expand Down Expand Up @@ -303,7 +300,7 @@ private static Result validateForSetting(String organizationName) {
}

User currentUser = UserApp.currentUser();
if (!OrganizationUser.isAdmin(organization.id, currentUser.id)) {
if (!AccessControl.isAllowed(currentUser, organization.asResource(), Operation.UPDATE)) {
return forbidden(ErrorViews.Forbidden.render("error.forbidden", organization));
}

Expand Down Expand Up @@ -363,6 +360,11 @@ private static Result validateForUpdate(Form<Organization> organizationForm, Org
return notFound(ErrorViews.NotFound.render("organization.member.unknownOrganization"));
}

if (!AccessControl.isAllowed(UserApp.currentUser(), organization.asResource(), Operation.UPDATE)) {
flash(Constants.WARNING, "organization.member.needManagerRole");
return forbidden(ErrorViews.Forbidden.render("error.forbidden", organization));
}

if (isDuplicateName(organization, modifiedOrganization)) {
organizationForm.reject("name", "organization.name.duplicate");
return badRequest(setting.render(organization, organizationForm));
Expand Down Expand Up @@ -435,6 +437,9 @@ private static ValidationResult validateForDelete(Organization organization) {
if (organization == null) {
return new ValidationResult(notFound(getJsonErrorMsg("organization.member.unknownOrganization")), true);
}
if (!AccessControl.isAllowed(UserApp.currentUser(), organization.asResource(), Operation.DELETE)) {
return new ValidationResult(notFound(getJsonErrorMsg("organization.member.needManagerRole")), true);
}
if (organization.projects != null && organization.projects.size() > 0) {
return new ValidationResult(notFound(getJsonErrorMsg("organization.delete.impossible.project.exist")), true);
}
Expand Down
5 changes: 5 additions & 0 deletions app/models/Organization.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public static boolean isNameExist(String name) {
return (findRowCount != 0);
}

public boolean isLastAdmin(User currentUser) {
return OrganizationUser.isAdmin(this, currentUser) && getAdmins().size() == 1;
}

@Transactional
public void cleanEnrolledUsers() {
List<User> enrolledUsers = this.enrolledUsers;
Expand Down Expand Up @@ -180,5 +184,6 @@ private void updateProjects(String newOwner) throws IOException, ServletExceptio
project.update();
}
}

}

11 changes: 7 additions & 4 deletions app/views/error/forbidden_organization.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**@
@(messageKey:String = "error.forbidden", organization: Organization)
@(messageKey:String = "error.forbidden", org: Organization)

@siteLayout(organization.name, utils.MenuType.NONE) {
<div class="site-breadcrumb-outer">
<div class="site-breadcrumb-inner">
@organizationLayout(org.name, utils.MenuType.NONE, org) {
@organization.header(org)
@organization.menu(org)

<div class="page-wrap-outer">
<div class="project-page-wrap">
<div class="error-wrap">
<i class="ico ico-err2"></i>
<p>@Messages(messageKey)</p>
Expand Down
3 changes: 1 addition & 2 deletions app/views/organization/menu.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
</ul>
<div class="project-setting">
<ul class="project-menu-nav">
@if(OrganizationUser.isAdmin(org, UserApp.currentUser)) {
@if(OrganizationUser.isAdmin(org, UserApp.currentUser) || UserApp.currentUser().isSiteManager) {
<li class="">
<a href="@routes.OrganizationApp.settingForm(org.name)">
<i class="yobicon-cog"></i>
<span class="blind">@Messages("menu.admin")</span>

</a>
<li>
}
Expand Down

0 comments on commit fb98846

Please sign in to comment.