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

Commit

Permalink
fixes a bug that site admin does not have group admin authorization.
Browse files Browse the repository at this point in the history
* Issue
    - Logics for site admin authroization are omitted in organization codes.
    - Some validations does not check authroizations and have bugs.

* Solution
    - Bugs are fixed and site admin authroization logics are added.

Private-issue: 1855
  • Loading branch information
ChangsungKim committed Jan 22, 2015
1 parent 9751305 commit bd17dce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
28 changes: 17 additions & 11 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,9 +239,11 @@ 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) {
flash(Constants.WARNING, "organization.member.atLeastOneAdmin");
return okWithLocation(routes.OrganizationApp.members(organizationName).url());

if (OrganizationUser.isAdmin(organization.id, userId) && organization.getAdmins().size() == 1
&& roleForm.get().id.equals(RoleType.ORG_MEMBER.roleType())) {
flash(Constants.WARNING, "organization.member.atLeastOneAdmin");
return okWithLocation(routes.OrganizationApp.members(organizationName).url());
}

return null;
Expand All @@ -270,7 +268,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 +301,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 +361,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 +438,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
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 bd17dce

Please sign in to comment.