Skip to content

Commit

Permalink
Toggle custom expiration date Role
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Feb 15, 2024
1 parent 7fc6497 commit fec54fb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/src/components/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const User = ({user, other, config, currentUser}) => {
);
}

user.highestAuthority = I18n.t(`access.${highestAuthority(user)}`);
user.highestAuthority = I18n.t(`access.${highestAuthority(user, false)}`);
const attributes = [["name"], ["sub"], ["eduPersonPrincipalName"], ["schacHomeOrganization"], ["email"], ["highestAuthority"],
["lastActivity", true]];
const filteredUserRoles = user.userRoles.filter(filterUserRole).filter(role => role.authority !== AUTHORITIES.GUEST || currentUser.superUser);
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/UserMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const UserMenu = ({user, config, actions}) => {
});
}

const renderMenu = (adminLinks) => {
const renderMenu = adminLinks => {
return (<>
<ul>
{user.superUser && adminLinks.map(l => <li key={l}>
Expand Down Expand Up @@ -60,7 +60,7 @@ export const UserMenu = ({user, config, actions}) => {
onBlur={() => setTimeout(() => setDropDownActive(false), 250)}>
<UserInfo isOpen={dropDownActive}
children={renderMenu(adminLinks)}
organisationName={I18n.t(`access.${highestAuthority(user)}`)}
organisationName={I18n.t(`access.${highestAuthority(user, false)}`)}
userName={user.name}
toggle={() => setDropDownActive(!dropDownActive)}
/>
Expand Down
2 changes: 1 addition & 1 deletion client/src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const en = {
roles: "Roles",
applications: "Applications",
noRolesInfo: "You have no roles (which means you must be super-user)",
noRolesInstitutionAdmin: "As an institution admin you have no roles (but you do have access to applications)",
noRolesInstitutionAdmin: "As an institution admin you have no roles (but you might have access to applications)",
guestRoleOnly: "You are a guest user. Are you looking for the <a href='{{welcomeUrl}}'>inviter app for guests</a>?",
rolesInfo: "You have the following roles",
applicationsInfo: "You have access to the following applications",
Expand Down
6 changes: 4 additions & 2 deletions client/src/pages/RoleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ConfirmationDialog from "../components/ConfirmationDialog";
import SwitchField from "../components/SwitchField";
import {displayExpiryDate, futureDate} from "../utils/Date";

const DEFAULT_EXPIRY_DAYS = 365;
export const RoleForm = () => {

const navigate = useNavigate();
Expand All @@ -30,7 +31,7 @@ export const RoleForm = () => {
const [role, setRole] = useState({
name: "",
shortName: "",
defaultExpiryDays: 365,
defaultExpiryDays: DEFAULT_EXPIRY_DAYS,
identifier: crypto.randomUUID()
});
const [providers, setProviders] = useState([]);
Expand Down Expand Up @@ -58,7 +59,8 @@ export const RoleForm = () => {
}
Promise.all(promises).then(res => {
if (!newRole) {
setRole(res[0])
setRole(res[0]);
setCustomRoleExpiryDate(res[0].defaultExpiryDays !== DEFAULT_EXPIRY_DAYS)
}
if (user.superUser) {
setProviders(providersToOptions(res[newRole ? 0 : 1]));
Expand Down
4 changes: 3 additions & 1 deletion server/src/main/java/access/security/InstitutionAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public static boolean isInstitutionAdmin(Map<String, Object> attributes,
}

public static boolean isInstitutionAdmin(User user) {
return user.isInstitutionAdmin() && StringUtils.hasText(user.getOrganizationGUID()) && user.isInstitutionAdminByInvite();
return user.isInstitutionAdmin() &&
StringUtils.hasText(user.getOrganizationGUID()) &&
user.isInstitutionAdminByInvite();
}

public static Optional<String> getOrganizationGuid(Map<String, Object> attributes,
Expand Down
4 changes: 3 additions & 1 deletion server/src/main/java/access/security/UserPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import access.model.Role;
import access.model.User;
import access.model.UserRole;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;
Expand All @@ -23,7 +24,8 @@ public static void assertSuperUser(User user) {
}

public static void assertInstitutionAdmin(User user) {
if (user.isSuperUser() || InstitutionAdmin.isInstitutionAdmin(user)) {
if (user.isSuperUser() || (user.isInstitutionAdmin() &&
StringUtils.hasText(user.getOrganizationGUID()))) {
return;
}
throw new UserRestrictionException();
Expand Down

0 comments on commit fec54fb

Please sign in to comment.