package edu.ucsf.lava.crms.auth.model;

import edu.ucsf.lava.core.auth.AuthorizationContext;
import edu.ucsf.lava.core.auth.model.AuthRole;
import edu.ucsf.lava.core.auth.model.AuthUserRole;
import edu.ucsf.lava.core.model.EntityBase;
import edu.ucsf.lava.core.model.EntityManager;
import edu.ucsf.lava.core.session.CoreSessionUtils;
import edu.ucsf.lava.crms.auth.CrmsAuthorizationContext;
import edu.ucsf.lava.crms.enrollment.ProjectUnitUtils;
import edu.ucsf.lava.crms.session.CrmsSessionUtils;

public class CrmsAuthUserRole extends AuthUserRole {

	public static EntityManager MANAGER = new EntityBase.Manager(CrmsAuthUserRole.class);
	
	private String project;
	private String unit;

	
	public CrmsAuthUserRole(){
		super();
	}
	
	public String getProject() {
		return project;
	}
	public void setProject(String project) {
		this.project = project;
	}
	public String getUnit() {
		return unit;
	}
	public void setUnit(String unit) {
		this.unit = unit;
	}
	
	public AuthorizationContext getAuthorizationContext() {
		return new CrmsAuthorizationContext(this.project,this.unit);
	}
	
	public String getProjUnitDesc(){
		return ProjectUnitUtils.getDescription(this.project, this.unit);
	}

	
	public String getSummaryInfo() {
		
		return new StringBuffer(super.getSummaryInfo()).append("Project: ").append(ProjectUnitUtils.getDescription(this.project, this.unit)).append("\n").toString();
	}


	
}

@@ -93,56 +93,8 @@
 t;%0D%0A
-import edu.ucsf.lava.core.auth.model.AuthRole;%0D%0A
 impo
@@ -137,24 +137,24 @@
 hUserRole;%0D%0A
+
 import edu.u
@@ -238,61 +238,8 @@
 r;%0D%0A
-import edu.ucsf.lava.core.session.CoreSessionUtils;%0D%0A
 impo
@@ -284,32 +284,32 @@
 zationContext;%0D%0A
+
 import edu.ucsf.
@@ -351,61 +351,8 @@
 ls;%0D
-%0Aimport edu.ucsf.lava.crms.session.CrmsSessionUtils;%0D
 %0A%0D%0Ap
@@ -1290,13 +1290,339 @@
 %7D%0D%0A%0D%0A%0D%0A%09
+public boolean isContextAuthorized(AuthorizationContext authorizationContext) %7B%0D%0A%09%09if (((CrmsAuthorizationContext)authorizationContext).getScope().equals(CrmsAuthorizationContext.CRMS_SCOPE)%0D%0A%09%09%09%09&& this.getAuthorizationContext().matches(authorizationContext)) %7B%0D%0A%09%09%09return true;%0D%0A%09%09%7D%0D%0A%09%09else %7B%0D%0A%09%09%09return false;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09%0D%0A
 %0D%0A%7D%0D%0A

add isContextAuthorized method as part of bug fix where the AuthorizationContext of AuthUserRole was not being considered when authorizing actions