Skip to content
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
60 changes: 60 additions & 0 deletions portal-ui/src/screens/Console/Policies/PolicyDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const PolicyDetails = ({
const [selectedTab, setSelectedTab] = useState<number>(0);
const [policy, setPolicy] = useState<Policy | null>(null);
const [userList, setUserList] = useState<string[]>([]);
const [groupList, setGroupList] = useState<string[]>([]);
const [addLoading, setAddLoading] = useState<boolean>(false);
const [policyName, setPolicyName] = useState<string>(
match.params["policyName"]
Expand All @@ -174,6 +175,8 @@ const PolicyDetails = ({
const [loadingPolicy, setLoadingPolicy] = useState<boolean>(true);
const [filterUsers, setFilterUsers] = useState<string>("");
const [loadingUsers, setLoadingUsers] = useState<boolean>(true);
const [filterGroups, setFilterGroups] = useState<string>("");
const [loadingGroups, setLoadingGroups] = useState<boolean>(true);

const saveRecord = (event: React.FormEvent) => {
event.preventDefault();
Expand Down Expand Up @@ -211,6 +214,20 @@ const PolicyDetails = ({
});
}
};
const loadGroupsForPolicy = () => {
if (loadingGroups) {
api
.invoke("GET", `/api/v1/policies/${policyName}/groups`)
.then((result: any) => {
setGroupList(result);
setLoadingGroups(false);
})
.catch((err) => {
setErrorSnackMessage(err);
setLoadingGroups(false);
});
}
};
const loadPolicyDetails = () => {
if (loadingPolicy) {
api
Expand All @@ -234,16 +251,20 @@ const PolicyDetails = ({
if (loadingPolicy) {
loadPolicyDetails();
loadUsersForPolicy();
loadGroupsForPolicy();
}
}, [
policyName,
loadingPolicy,
loadingUsers,
loadingGroups,
setErrorSnackMessage,
setUserList,
setGroupList,
setPolicyDefinition,
setPolicy,
setLoadingUsers,
setLoadingGroups,
]);

const resetForm = () => {
Expand All @@ -262,6 +283,10 @@ const PolicyDetails = ({
elementItem.includes(filterUsers)
);

const filteredGroups = groupList.filter((elementItem) =>
elementItem.includes(filterGroups)
);

return (
<React.Fragment>
<PageHeader
Expand All @@ -287,6 +312,7 @@ const PolicyDetails = ({
>
<Tab label="Details" />
<Tab label="Users" />
<Tab label="Groups" />
</Tabs>
</Grid>
{selectedTab === 0 && (
Expand Down Expand Up @@ -374,6 +400,40 @@ const PolicyDetails = ({
/>
</Grid>
)}
{selectedTab === 2 && (
<Grid container>
<Grid item xs={12} className={classes.actionsTray}>
<TextField
placeholder="Search Groups"
className={classes.searchField}
id="search-resource"
label=""
onChange={(val) => {
setFilterGroups(val.target.value);
}}
InputProps={{
disableUnderline: true,
startAdornment: (
<InputAdornment position="start">
<SearchIcon />
</InputAdornment>
),
}}
/>
</Grid>
<Grid item xs={12} className={classes.actionsTray}>
<br />
</Grid>
<TableWrapper
itemActions={[]}
columns={[{ label: "Name", elementKey: "name" }]}
isLoading={loadingGroups}
records={filteredGroups}
entityName="Groups"
idField="name"
/>
</Grid>
)}
</Grid>
</React.Fragment>
);
Expand Down
36 changes: 36 additions & 0 deletions restapi/admin_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ func registersPoliciesHandler(api *operations.ConsoleAPI) {
}
return admin_api.NewListUsersForPolicyOK().WithPayload(policyUsersResponse)
})
api.AdminAPIListGroupsForPolicyHandler = admin_api.ListGroupsForPolicyHandlerFunc(func(params admin_api.ListGroupsForPolicyParams, session *models.Principal) middleware.Responder {
policyGroupsResponse, err := getListGroupsForPolicyResponse(session, params.Policy)
if err != nil {
return admin_api.NewListGroupsForPolicyDefault(int(err.Code)).WithPayload(err)
}
return admin_api.NewListGroupsForPolicyOK().WithPayload(policyGroupsResponse)
})
}

func getListPoliciesWithBucketResponse(session *models.Principal, bucket string) (*models.ListPoliciesResponse, *models.Error) {
Expand Down Expand Up @@ -220,6 +227,35 @@ func getListUsersForPolicyResponse(session *models.Principal, policy string) ([]
return filteredUsers, nil
}

func getListGroupsForPolicyResponse(session *models.Principal, policy string) ([]string, *models.Error) {
ctx := context.Background()
mAdmin, err := newAdminClient(session)
if err != nil {
return nil, prepareError(err)
}
// create a minioClient interface implementation
// defining the client to be used
adminClient := adminClient{client: mAdmin}

groups, err := adminClient.listGroups(ctx)
if err != nil {
return nil, prepareError(err)
}

var filteredGroups []string
for _, group := range groups {
info, err := groupInfo(ctx, adminClient, group)
if err != nil {
LogError("unable to fetch group info %s: %v", group, err)
}
if info.Policy == policy {
filteredGroups = append(filteredGroups, group)
}
}
sort.Strings(filteredGroups)
return filteredGroups, nil
}

// removePolicy() calls MinIO server to remove a policy based on name.
func removePolicy(ctx context.Context, client MinioAdmin, name string) error {
err := client.removePolicy(ctx, name)
Expand Down
68 changes: 68 additions & 0 deletions restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions restapi/operations/admin_api/list_groups_for_policy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading