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

[Cloud Apps] - StackScript Updates #4709

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixes
  • Loading branch information
martinmckenna committed Mar 26, 2019
commit 93b4be932bed7cbcf37c74444ed65acfaabe517d
40 changes: 22 additions & 18 deletions src/features/StackScripts/stackScriptUtils.ts
Original file line number Diff line number Diff line change
@@ -25,12 +25,12 @@ export const getMineAndAccountStackScripts = (
filter?: any,
stackScriptGrants?: Linode.Grant[]
) => {
/*
Secondary users can't see other account users but they have a list of
available account stackscripts in grant call.
If user is restricted we get the stackscripts for the list in grants.
Otherwise we pull all stackscripts for users on the account.
*/
/**
* Secondary users can't see other account users but they have a list of
* available account stackscripts in grant call.
* If user is restricted we get the stackscripts for the list in grants.
* Otherwise we pull all stackscripts for users on the account.
*/
if (stackScriptGrants) {
/**
* don't try to get another page of stackscripts because the request to /grants
@@ -54,6 +54,12 @@ export const getMineAndAccountStackScripts = (
};
});
} else {
/**
* in this case, we are unrestricted user, so instead of getting the
* StackScripts from the /grants meta data, need to get a list of all
* users on the account and make a GET /stackscripts call with the list
* of users as a filter
*/
return getUsers().then(response => {
return getStackscripts(params, {
...filter,
@@ -83,18 +89,16 @@ export const getCommunityStackscripts = (
params?: any,
filter?: any
) =>
getUsers()
.then(response => {
return getStackscripts(params, {
...filter,
'+and': response.data.reduce(
// pull all stackScripts except linode and account users
(acc, user) => [...acc, { username: { '+neq': user.username } }],
[{ username: { '+neq': 'linode' } }]
)
});
})
.catch(() => Promise.resolve(emptyResult));
getUsers().then(response => {
return getStackscripts(params, {
...filter,
'+and': response.data.reduce(
// pull all stackScripts except linode and account users
(acc, user) => [...acc, { username: { '+neq': user.username } }],
[{ username: { '+neq': 'linode' } }]
)
});
});

export type AcceptedFilters = 'username' | 'description' | 'label';