Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge to main #70

Merged
merged 7 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 98 additions & 8 deletions src/components/Activity/ModLogAccordians.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ export default function ModLogAccordians({ modLogData }) {
return <BannedRow item={modLogItem} />;
}

if (modLogItem.type === "admin_purged_persons") {
return <AdminPurgedPersonsRow item={modLogItem} />;
}
if (modLogItem.type === "admin_purged_communities") {
return <AdminPurgedCommunitiesRow item={modLogItem} />;
}
if (modLogItem.type === "admin_purged_posts") {
return <AdminPurgedPostsRow item={modLogItem} />;
}
if (modLogItem.type === "admin_purged_comments") {
return <AdminPurgedCommentsRow item={modLogItem} />;
}

return (
<Accordion>
<AccordionSummary indicator={<AddIcon />}>Unknown Action: {modLogItem.type}</AccordionSummary>
Expand Down Expand Up @@ -117,10 +130,8 @@ function ModDisplayName({ moderator }) {
return (
<Box sx={{ overflow: "hidden" }}>
{moderator.admin && (
<SquareChip color="danger" variant="solid" tooltip={"Site Admin"}>
<SecurityIcon />
</SquareChip>
)}{" "}
<SquareChip color="danger" variant="solid" tooltip={"Site Admin"} iconOnly={<SecurityIcon />} />
)}
{moderator.display_name ? moderator.display_name : moderator.name}
</Box>
);
Expand All @@ -134,16 +145,21 @@ function RemovedPostRow({ item }) {
headerIcon={<RemoveCircleOutlineIcon />}
headerContent={
<>
<ModDisplayName moderator={item.moderator} /> removed post from {item.community.actor_id}
<ModDisplayName moderator={item.moderator} /> removed post from {item.community.actor_id}{" "}
{item.mod_remove_post.reason ? `with reason: "${item.mod_remove_post.reason}"` : ""}
</>
}
>
<Typography variant="h6" component="h2">
Mod: {item.moderator?.display_name} ({item.moderator?.actor_id})
</Typography>
{item.moderator && (
<Typography variant="h6" component="h2">
Mod: {item.moderator?.display_name} ({item.moderator?.actor_id})
</Typography>
)}

<Typography component="span">Reason: "{item.mod_remove_post.reason}"</Typography>
<Typography component="span">removed: {item.mod_remove_post.removed ? "True" : "false"}</Typography>
<Typography component="span">when_: {item.mod_remove_post.when_}</Typography>

<pre>{JSON.stringify(item, null, 2)}</pre>
</BaseAccordian>
);
Expand All @@ -162,6 +178,15 @@ function RemovedCommentRow({ item }) {
</>
}
>
{item.moderator && (
<Typography variant="h6" component="h2">
Mod: {item.moderator?.display_name} ({item.moderator?.actor_id})
</Typography>
)}

<Typography component="span">Reason: "{item.mod_remove_comment.reason}"</Typography>
<Typography component="span">removed: {item.mod_remove_comment.removed ? "True" : "false"}</Typography>
<Typography component="span">when_: {item.mod_remove_comment.when_}</Typography>
<pre>{JSON.stringify(item, null, 2)}</pre>
</BaseAccordian>
);
Expand Down Expand Up @@ -314,3 +339,68 @@ function AddedRow({ item }) {
</BaseAccordian>
);
}

// import SecurityIcon from "@mui/icons-material/Security";
function AdminPurgedPersonsRow({ item }) {
return (
<BaseAccordian
item={item}
headerIcon={<SecurityIcon />}
headerContent={
<>
<ModDisplayName moderator={item.moderator} /> admin purged person {item.admin_purge_person.reason}
</>
}
>
<pre>{JSON.stringify(item, null, 2)}</pre>
</BaseAccordian>
);
}
function AdminPurgedCommunitiesRow({ item }) {
return (
<BaseAccordian
item={item}
headerIcon={<SecurityIcon />}
headerContent={
<>
<ModDisplayName moderator={item.moderator} /> admin purged community {item.admin_purge_community.id}
: "{item.admin_purge_community.reason}"
</>
}
>
<pre>{JSON.stringify(item, null, 2)}</pre>
</BaseAccordian>
);
}
function AdminPurgedPostsRow({ item }) {
return (
<BaseAccordian
item={item}
headerIcon={<SecurityIcon />}
headerContent={
<>
<ModDisplayName moderator={item.moderator} /> admin purged posts {item.actorId} "
{item.admin_purge_post.reason}"
</>
}
>
<pre>{JSON.stringify(item, null, 2)}</pre>
</BaseAccordian>
);
}
function AdminPurgedCommentsRow({ item }) {
return (
<BaseAccordian
item={item}
headerIcon={<SecurityIcon />}
headerContent={
<>
<ModDisplayName moderator={item.moderator} /> admin purged comment "
{item.admin_purge_comment.reason}"
</>
}
>
<pre>{JSON.stringify(item, null, 2)}</pre>
</BaseAccordian>
);
}
6 changes: 0 additions & 6 deletions src/components/Filters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ export function FilterTypeSelect() {
export function FilterModLogType() {
const dispatch = useDispatch();
const modLogType = useSelector((state) => state.configReducer.modLogType);
{
/* "All" | "ModRemovePost" | "ModLockPost" | "ModFeaturePost" | "ModRemoveComment" |
"ModRemoveCommunity" | "ModBanFromCommunity" | "ModAddCommunity" | "ModTransferCommunity"
| "ModAdd" | "ModBan" | "ModHideCommunity" | "AdminPurgePerson" | "AdminPurgeCommunity" |
"AdminPurgePost" | "AdminPurgeComment" */
}

const modlogTypes = getModLogTypeNames();

Expand Down
162 changes: 109 additions & 53 deletions src/pages/Actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,67 +65,126 @@ export default function Actions() {
if (!modlogData) return [];

let allModActions = [];

// for each page of results, extract a flat list with the action type on each
for (let i = 0; i < modlogData.pages.length; i++) {
// for each array, get all objects
// look through the results in this page's data
// this is because the modlog comes back as a object with an array for each type of mod action
let thisItems = [];
for (const [modlogType, modLogPageData] of Object.entries(modlogData.pages[i].data)) {
// flatten the array of mod actions into a single array
thisItems = thisItems.concat(
modLogPageData.map((modLogItem) => {
// extract time from the type of mod action
let time;

if (modlogType === "removed_posts") time = modLogItem.mod_remove_post.when_;
if (modlogType === "locked_posts") time = modLogItem.mod_lock_post.when_;
if (modlogType === "featured_posts") time = modLogItem.mod_feature_post.when_;
if (modlogType === "removed_comments") time = modLogItem.mod_remove_comment.when_;
if (modlogType === "removed_communities") time = modLogItem.mod_remove_community.when_;
if (modlogType === "banned_from_community") time = modLogItem.mod_ban_from_community.when_;
if (modlogType === "added_to_community") time = modLogItem.mod_add_community.when_;
if (modlogType === "transferred_to_community") time = modLogItem.mod_transfer_community.when_;
if (modlogType === "added") time = modLogItem.mod_add.when_;
if (modlogType === "banned") time = modLogItem.mod_ban.when_;

if (modlogType === "admin_purged_persons") time = modLogItem.admin_purge_person.when_;
if (modlogType === "admin_purged_communities") time = modLogItem.admin_purge_community.when_;
if (modlogType === "admin_purged_posts") time = modLogItem.admin_purge_post.when_;
if (modlogType === "admin_purged_comments") time = modLogItem.admin_purge_comment.when_;

return {
type: modlogType,
time,
...modLogItem,
};
}),
);
}

// add this page's mod actions to the array of all mod actions
allModActions = allModActions.concat(thisItems);
}

// add metadata for each activity
allModActions = allModActions.map((modLogItem) => {
let actionTime = null;
let affectedActorId = null;

switch (modLogItem.type) {
case "removed_posts":
actionTime = modLogItem.mod_remove_post.when_;
affectedActorId = modLogItem.community.actor_id;
break;
case "locked_posts":
actionTime = modLogItem.mod_lock_post.when_;
affectedActorId = modLogItem.community.actor_id;
break;
case "featured_posts":
actionTime = modLogItem.mod_feature_post.when_;
affectedActorId = modLogItem.community.actor_id;
break;
case "removed_comments":
actionTime = modLogItem.mod_remove_comment.when_;
affectedActorId = modLogItem.community.actor_id;
break;
case "removed_communities":
actionTime = modLogItem.mod_remove_community.when_;
affectedActorId = modLogItem.community.actor_id;
break;
case "banned_from_community":
actionTime = modLogItem.mod_ban_from_community.when_;
affectedActorId = modLogItem.community.actor_id;
break;
case "added_to_community":
actionTime = modLogItem.mod_add_community.when_;
affectedActorId = modLogItem.community.actor_id;
break;
case "transferred_to_community":
actionTime = modLogItem.mod_transfer_community.when_;
affectedActorId = modLogItem.community.actor_id;
break;
case "added":
actionTime = modLogItem.mod_add.when_;
// affectedActorId = modLogItem.mod_add.local_community;
break;
case "banned":
actionTime = modLogItem.mod_ban.when_;
affectedActorId = modLogItem.banned_person.actor_id;
break;

case "admin_purged_persons":
actionTime = modLogItem.admin_purge_person.when_;
// affectedActorId = modLogItem.admin_purge_person.local_community;
break;
case "admin_purged_communities":
actionTime = modLogItem.admin_purge_community.when_;
// affectedActorId = modLogItem.admin_purge_community.local_community;
break;
case "admin_purged_posts":
actionTime = modLogItem.admin_purge_post.when_;
affectedActorId = modLogItem.community.actor_id;
break;
case "admin_purged_comments":
actionTime = modLogItem.admin_purge_comment.when_;
// affectedActorId = modLogItem.admin_purge_comment.local_community;
break;
}

let localAction = true;
if (affectedActorId) {
localAction = parseActorId(affectedActorId).actorBaseUrl == locaUserParsedActor.actorBaseUrl;
}

console.log("affectedActorId", affectedActorId, "localAction", localAction);

// override with known
// if (item.moderator)
// locaUserParsedActor.actorBaseUrl === parseActorId(item.moderator.actor_id).actorBaseUrl;

return {
...modLogItem,
time: actionTime,
actorId: affectedActorId,
localAction,
};
});

if (modLogType !== "all") {
console.log("filtering by type", modLogType);
allModActions = allModActions.filter((item) => {
return item.type === modLogType;
});
}

// this is hard since `moderator is not visible for non-admins
// which means we'd have to extract the actor id from the object, which is different for each action
// for now they get removed when we attempt to render them
if (limitLocalInstance) {
console.log("filtering by local instance");
allModActions = allModActions.filter((item) => {
// this only works for site admins
if (item.moderator)
locaUserParsedActor.actorBaseUrl === parseActorId(item.moderator.actor_id).actorBaseUrl;

return !item.localCommunity;

// let time;
// if (modlogType === "removed_posts") time = modLogItem.mod_remove_post.when_;
// if (modlogType === "locked_posts") time = modLogItem.mod_lock_post.when_;
// if (modlogType === "featured_posts") time = modLogItem.mod_feature_post.when_;
// if (modlogType === "removed_comments") time = modLogItem.mod_remove_comment.when_;
// if (modlogType === "removed_communities") time = modLogItem.mod_remove_community.when_;
// if (modlogType === "banned_from_community") time = modLogItem.mod_ban_from_community.when_;
// if (modlogType === "added_to_community") time = modLogItem.mod_add_community.when_;
// if (modlogType === "transferred_to_community") time = modLogItem.mod_transfer_community.when_;
// if (modlogType === "added") time = modLogItem.mod_add.when_;
// if (modlogType === "banned") time = modLogItem.mod_ban.when_;

return false;
return item.localAction;
});
}

Expand Down Expand Up @@ -212,19 +271,16 @@ export default function Actions() {
>
<FilterModLogType />

{/* temp. hidden because non-admins can't see the `moderator` field */}
{userRole == "admin" && (
<Checkbox
label="Show Local Instance Only"
variant="outlined"
checked={limitLocalInstance}
onChange={() => {
// dispatch(setConfigItem("hideReadApprovals", !hideReadApprovals));
console.log("toggle", !limitLocalInstance);
setLimitLocalInstance(!limitLocalInstance);
}}
/>
)}
<Checkbox
label="Show Local Instance Only"
variant="outlined"
checked={limitLocalInstance}
onChange={() => {
// dispatch(setConfigItem("hideReadApprovals", !hideReadApprovals));
console.log("toggle", !limitLocalInstance);
setLimitLocalInstance(!limitLocalInstance);
}}
/>
</Sheet>

<AccordionGroup
Expand Down
Loading