Skip to content
Snippets Groups Projects
Commit a8fc4c92 authored by Alexandre Eberhardt's avatar Alexandre Eberhardt
Browse files

Hide revoked: implement the button Hide revoked users

This button was not effective, this is the implementation
Add an atribute in UserProfile to check if revoked

Change-Id: I40a80c177e323627d1d76ceab8a41d2bf3f47594
parent bbe118f6
No related branches found
No related tags found
No related merge requests found
...@@ -190,6 +190,7 @@ ...@@ -190,6 +190,7 @@
"are_you_sure_want_revoke": "Are you sure you want to revoke", "are_you_sure_want_revoke": "Are you sure you want to revoke",
"revoke": "Revoke", "revoke": "Revoke",
"revoke_user": "Revoke user", "revoke_user": "Revoke user",
"hide_revoked_users": "Hide revoked users",
"edit_profile": "Edit profile", "edit_profile": "Edit profile",
"change_password": "Change password", "change_password": "Change password",
"minimum_3_characters": "Minimum 3 characters!", "minimum_3_characters": "Minimum 3 characters!",
......
...@@ -200,6 +200,7 @@ export interface UserProfile { ...@@ -200,6 +200,7 @@ export interface UserProfile {
faxNumber: string; faxNumber: string;
mobileNumber: string; mobileNumber: string;
id: string; id: string;
revoked?: boolean;
} }
export interface GroupMembership { export interface GroupMembership {
...@@ -236,6 +237,7 @@ const DisplayUserProfile: FC<DisplayUserProfileProps> = ({ ...@@ -236,6 +237,7 @@ const DisplayUserProfile: FC<DisplayUserProfileProps> = ({
faxNumber: "", faxNumber: "",
mobileNumber: "", mobileNumber: "",
id: "", id: "",
revoked: false,
}); });
const [groupMemberships, setGroupMemberships] = useState<GroupMembership[]>( const [groupMemberships, setGroupMemberships] = useState<GroupMembership[]>(
[] []
......
...@@ -38,8 +38,7 @@ import CardAvatar from "components/Card/CardAvatar"; ...@@ -38,8 +38,7 @@ import CardAvatar from "components/Card/CardAvatar";
import CardBody from "components/Card/CardBody"; import CardBody from "components/Card/CardBody";
import Search from "@mui/icons-material/Search"; import Search from "@mui/icons-material/Search";
import Checkbox from "@mui/material/Checkbox"; import { Checkbox, FormControlLabel, Chip } from "@mui/material";
import FormControlLabel from "@mui/material/FormControlLabel";
import axios from "axios"; import axios from "axios";
import configApiCall from "api"; import configApiCall from "api";
import auth from "auth"; import auth from "auth";
...@@ -98,13 +97,14 @@ const styles = { ...@@ -98,13 +97,14 @@ const styles = {
}, },
}; };
const useStyles = makeStyles(styles as any); const useStyles = makeStyles(styles as any);
const label = i18next.t("revoked", "Revoked") as string;
export default function Users() { export default function Users() {
const classes = useStyles(); const classes = useStyles();
const history = useHistory(); const history = useHistory();
const [users, setUsers] = useState<UserProfile[]>([]); const [users, setUsers] = useState<UserProfile[]>([]);
const [noUsersFound, setNoUsersFound] = useState(false); const [noUsersFound, setNoUsersFound] = useState(false);
const [noMatchFound, setNoMatchFound] = useState(false); const [noMatchFound, setNoMatchFound] = useState(false);
const [showRevokedUsers, setShowRevokedUsers] = useState(false); const [hideRevokedUsers, setHideRevokedUsers] = useState(true);
const [searchValue, setSearchValue] = useState(""); const [searchValue, setSearchValue] = useState("");
...@@ -200,8 +200,8 @@ export default function Users() { ...@@ -200,8 +200,8 @@ export default function Users() {
<FormControlLabel <FormControlLabel
control={ control={
<Checkbox <Checkbox
checked={showRevokedUsers} checked={hideRevokedUsers}
onChange={() => setShowRevokedUsers(!showRevokedUsers)} onChange={() => setHideRevokedUsers(!hideRevokedUsers)}
inputProps={{ "aria-label": "primary checkbox" }} inputProps={{ "aria-label": "primary checkbox" }}
color="primary" color="primary"
/> />
...@@ -211,7 +211,9 @@ export default function Users() { ...@@ -211,7 +211,9 @@ export default function Users() {
? { marginLeft: "1rem" } ? { marginLeft: "1rem" }
: { marginLeft: "-8px" } : { marginLeft: "-8px" }
} }
label="Display revoked users" label={
i18next.t("hide_revoked_users", "Hide revoked users") as string
}
/> />
<GridContainer> <GridContainer>
...@@ -265,6 +267,7 @@ export default function Users() { ...@@ -265,6 +267,7 @@ export default function Users() {
} }
return 0; return 0;
}) })
.filter((user) => !hideRevokedUsers || !user.revoked)
.map((user) => ( .map((user) => (
<GridItem xs={12} sm={6} md={3} lg={2} xl={2} key={user.username}> <GridItem xs={12} sm={6} md={3} lg={2} xl={2} key={user.username}>
<Card profile> <Card profile>
...@@ -273,17 +276,32 @@ export default function Users() { ...@@ -273,17 +276,32 @@ export default function Users() {
style={{ height: "100%" }} style={{ height: "100%" }}
> >
<CardBody profile> <CardBody profile>
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
<CardAvatar profile> <CardAvatar profile>
<img <img
src={ src={
user.profilePicture user.profilePicture
? "data:image/png;base64, " + user.profilePicture ? "data:image/png;base64, " +
user.profilePicture
: noProfilePicture : noProfilePicture
} }
alt="..." alt="..."
/> />
</CardAvatar> </CardAvatar>
{user.revoked && (
<Chip
label={i18next.t("revoked", "Revoked") as string}
variant="filled"
clickable={false}
/>
)}
</div>
<GridContainer <GridContainer
container container
direction="column" direction="column"
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*/ */
package net.jami.jams.server.servlets.api.auth.directory; package net.jami.jams.server.servlets.api.auth.directory;
import static net.jami.jams.server.Server.certificateAuthority;
import static net.jami.jams.server.Server.dataStore; import static net.jami.jams.server.Server.dataStore;
import static net.jami.jams.server.Server.nameServer; import static net.jami.jams.server.Server.nameServer;
import static net.jami.jams.server.Server.userAuthenticationModule; import static net.jami.jams.server.Server.userAuthenticationModule;
...@@ -43,6 +44,9 @@ import net.jami.jams.common.objects.user.User; ...@@ -43,6 +44,9 @@ import net.jami.jams.common.objects.user.User;
import net.jami.jams.common.objects.user.UserProfile; import net.jami.jams.common.objects.user.UserProfile;
import net.jami.jams.common.serialization.adapters.GsonFactory; import net.jami.jams.common.serialization.adapters.GsonFactory;
import org.bouncycastle.cert.X509CRLEntryHolder;
import org.bouncycastle.cert.X509CRLHolder;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
...@@ -152,6 +156,23 @@ public class SearchDirectoryServlet extends HttpServlet { ...@@ -152,6 +156,23 @@ public class SearchDirectoryServlet extends HttpServlet {
JsonObject obj = new JsonObject(); JsonObject obj = new JsonObject();
JsonArray profilesArray = gson.toJsonTree(userProfiles).getAsJsonArray(); JsonArray profilesArray = gson.toJsonTree(userProfiles).getAsJsonArray();
for (int i = 0; i < profilesArray.size(); i++) {
JsonObject profile = profilesArray.get(i).getAsJsonObject();
String usernamerev = profile.get("username").getAsString();
User user = dataStore.getUserDao().getByUsername(usernamerev).orElse(null);
if (user != null) {
X509CRLHolder crl = certificateAuthority.getLatestCRL().get();
if (crl != null) {
X509CRLEntryHolder revoked =
crl.getRevokedCertificate(user.getCertificate().getSerialNumber());
profile.addProperty("revoked", revoked != null);
} else {
profile.addProperty("revoked", false);
}
}
}
obj.add("profiles", profilesArray); obj.add("profiles", profilesArray);
obj.addProperty("numPages", DataStore.NUM_PAGES); obj.addProperty("numPages", DataStore.NUM_PAGES);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment