Implement implied permissions (selecting CREATE_CRATE automatically selects PUBLISH_VERSION)
Fixes #21
Diff
chartered-db/src/permissions.rs | 11 +++++++++++
chartered-frontend/src/pages/crate/CrateView.tsx | 6 ++++--
chartered-frontend/src/pages/crate/Members.tsx | 15 +++++++++++++++
chartered-frontend/src/pages/crate/OrganisationView.tsx | 7 +++++++
chartered-web/src/endpoints/web_api/crates/members.rs | 6 ++++--
chartered-web/src/endpoints/web_api/organisations/info.rs | 2 ++
6 files changed, 43 insertions(+), 4 deletions(-)
@@ -17,6 +17,17 @@
pub fn names() -> &'static [&'static str] {
Self::NAMES
}
#[must_use]
pub fn implications() -> &'static [[UserPermission; 2]] {
&[
[Self::CREATE_CRATE, Self::PUBLISH_VERSION],
]
}
}
impl<B: diesel::backend::Backend> diesel::deserialize::FromSql<diesel::sql_types::Integer, B>
@@ -270,7 +270,8 @@
}
interface CratesMembersResponse {
allowed_permissions: string[];
possible_permissions: string[];
implied_permissions: string[];
members: Member[];
}
@@ -405,7 +406,8 @@
return (
<CommonMembers
members={response.members}
possiblePermissions={response.allowed_permissions}
possiblePermissions={response.possible_permissions}
impliedPermssions={response.implied_permissions}
saveMemberPermissions={saveMemberPermissions}
deleteMember={deleteMember}
/>
@@ -16,11 +16,13 @@
export default function Members({
members,
possiblePermissions,
impliedPermissions,
saveMemberPermissions,
deleteMember,
}: {
members: Member[];
possiblePermissions?: string[];
impliedPermissions?: string[][][];
saveMemberPermissions: (
prospectiveMember: boolean,
uuid: string,
@@ -53,6 +55,7 @@
member={member}
prospectiveMember={false}
possiblePermissions={possiblePermissions}
impliedPermissions={impliedPermissions}
saveMemberPermissions={saveMemberPermissions}
deleteMember={deleteMember}
/>
@@ -64,6 +67,7 @@
member={member}
prospectiveMember={true}
possiblePermissions={possiblePermissions}
impliedPermissions={impliedPermissions}
saveMemberPermissions={saveMemberPermissions}
deleteMember={deleteMember}
/>
@@ -96,12 +100,14 @@
member,
prospectiveMember,
possiblePermissions,
impliedPermissions,
saveMemberPermissions,
deleteMember,
}: {
member: Member;
prospectiveMember: boolean;
possiblePermissions?: string[];
impliedPermissions?: string[][][];
saveMemberPermissions: (
prospectiveMember: boolean,
uuid: string,
@@ -225,6 +231,7 @@
<td className="align-middle">
<RenderPermissions
possiblePermissions={possiblePermissions}
impliedPermissions={impliedPermissions}
selectedPermissions={selectedPermissions}
userUuid={member.uuid}
onChange={setSelectedPermissions}
@@ -368,11 +375,13 @@
function RenderPermissions({
possiblePermissions,
selectedPermissions,
impliedPermissions,
userUuid,
onChange,
}: {
possiblePermissions: string[];
selectedPermissions: string[];
impliedPermissions: string[][][];
userUuid: string;
onChange: (permissions: string[]) => any;
}) {
@@ -394,6 +403,12 @@
if (e.target.checked) {
newUserPermissions.add(permission);
for (const [a, b] of impliedPermissions) {
if (a[0] === permission) {
newUserPermissions.add(b[0]);
}
}
} else {
newUserPermissions.delete(permission);
}
@@ -16,6 +16,7 @@
interface OrganisationDetails {
possible_permissions?: string[];
implied_permissions?: string[][][];
crates: Crate[];
members: Member[];
description: string;
@@ -153,6 +154,9 @@
possiblePermissions={
organisationDetails.possible_permissions
}
impliedPermissions={
organisationDetails.implied_permissions
}
reload={() => setReload(reload + 1)}
/>
) : (
@@ -219,6 +223,7 @@
organisation: string;
members: Member[];
possiblePermissions?: string[];
impliedPermissions?: string[][][];
reload: () => any;
}
@@ -226,6 +231,7 @@
organisation,
members,
possiblePermissions,
impliedPermissions,
reload,
}: ListMemberParams) {
const auth = useAuth();
@@ -289,6 +295,7 @@
<Members
members={members}
possiblePermissions={possiblePermissions}
impliedPermissions={impliedPermissions}
saveMemberPermissions={saveMemberPermissions}
deleteMember={deleteMember}
/>
@@ -36,7 +36,8 @@
.collect();
Ok(Json(GetResponse {
allowed_permissions: UserPermission::names(),
possible_permissions: UserPermission::names(),
implied_permissions: UserPermission::implications(),
members,
}))
}
@@ -109,7 +110,8 @@
#[derive(Serialize)]
pub struct GetResponse {
allowed_permissions: &'static [&'static str],
possible_permissions: &'static [&'static str],
implied_permissions: &'static [[UserPermission; 2]],
members: Vec<GetResponseMember>,
}
@@ -34,6 +34,7 @@
description: organisation.organisation().description.to_string(),
possible_permissions: can_manage_users.then(UserPermission::all),
implied_permissions: can_manage_users.then(UserPermission::implications),
crates: crates
.into_iter()
.map(|v| ResponseCrate {
@@ -57,6 +58,7 @@
pub struct Response {
description: String,
possible_permissions: Option<UserPermission>,
implied_permissions: Option<&'static [[UserPermission; 2]]>,
crates: Vec<ResponseCrate>,
members: Vec<ResponseUser>,
}