Skip to content

Commit

Permalink
Added validation to prevent making group inactive if the group has ac…
Browse files Browse the repository at this point in the history
…tive roles (thewca#9697)

* Added validation to prevent making group inactive if the group has active roles

* Review chnages
  • Loading branch information
danieljames-dj authored Jul 22, 2024
1 parent 276635e commit 7d546f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/models/user_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class UserGroup < ApplicationRecord
scope :root_groups, -> { where(parent_group: nil) }
scope :active_groups, -> { where(is_active: true) }

validates :active_roles, absence: true, unless: :is_active?

def all_child_groups
[direct_child_groups, direct_child_groups.map(&:all_child_groups)].flatten
end
Expand Down
22 changes: 18 additions & 4 deletions app/webpacker/components/Panel/pages/RegionManager/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const defaultRegion = {
friendlyId: '',
};

function UserGroupVisibility({ userGroup, save, sync }) {
function UserGroupVisibility({
userGroup, save, sync, setSaveError,
}) {
const [open, setOpen] = React.useState(false);
const iconName = userGroup.is_active ? 'eye' : 'eye slash';
return (
Expand All @@ -42,6 +44,8 @@ function UserGroupVisibility({ userGroup, save, sync }) {
userGroupsUpdateUrl(userGroup.id),
{ is_active: !userGroup.is_active, is_hidden: userGroup.is_hidden },
sync,
{},
setSaveError,
);
}}
/>
Expand Down Expand Up @@ -76,7 +80,7 @@ export default function RegionManager() {
}, [data]);

if (loading || fetchLoading || saving) return <Loading />;
if (error || saveError) return <Errored />;
if (error || saveError) return <Errored error={error || saveError} />;

return (
<>
Expand Down Expand Up @@ -123,7 +127,12 @@ export default function RegionManager() {
<Table.Cell />
<Table.Cell />
<Table.Cell>
<UserGroupVisibility userGroup={region} save={save} sync={sync} />
<UserGroupVisibility
userGroup={region}
save={save}
sync={sync}
setSaveError={setSaveError}
/>
</Table.Cell>
</Table.Row>
{subRegions[region.id]?.map((subRegion) => (
Expand Down Expand Up @@ -153,7 +162,12 @@ export default function RegionManager() {
)}
</Table.Cell>
<Table.Cell>
<UserGroupVisibility userGroup={subRegion} save={save} sync={sync} />
<UserGroupVisibility
userGroup={subRegion}
save={save}
sync={sync}
setSaveError={setSaveError}
/>
</Table.Cell>
</Table.Row>
))}
Expand Down

0 comments on commit 7d546f6

Please sign in to comment.