Nicole Lopez
03/16/2022, 12:19 PMMichal Hauzírek
03/16/2022, 12:49 PMGET /gdc/projects/PROJECT_ID/users/USER_PROFILE_ID/permissions
for a particular user and workspace and then in the response check the value of associatedPermissions/permissions/canManageProject
If it is equal to “1” that means the particular user is administrator in that particular workspace. Technically, this call returns values of all the permissions of a particular user in that workspace, so you can also use that to check other things. But canManageProject is a permission which only admins have, so that should be safe to use.
if you do not know the USER_PROFILE_ID, you can get it for currently logged-in user by calling
GET /gdc/account/profile/current
Nicole Lopez
03/16/2022, 1:46 PMconst loginToGD = async () => {
const url = ’https://brandranalytics-dev.on.gooddata.com/gdc/account/login';
fetch(url, {
method: ‘POST’,
mode: ‘no-cors’,
headers: {
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
postUserLogin: {
login:“nicole.lopez@hackberry.se”,
password:“XXXXXX”,
remember:1,
},
})
})
.then(async response => {
const data = await response.json();
console.log(‘URL Response: ’, data);
})
.catch(error => {
console.log(‘Response Error: ’, error);
})
}Michal Hauzírek
03/16/2022, 2:27 PMNicole Lopez
03/16/2022, 2:43 PMNicole Lopez
03/16/2022, 2:43 PMAccess to fetch at '<https://brandranalytics-dev.on.gooddata.com/gdc/account/login>' from origin '<https://localhost:3000>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Nicole Lopez
03/16/2022, 2:44 PMMichal Hauzírek
03/16/2022, 3:00 PMNicole Lopez
03/16/2022, 3:13 PMMichal Hauzírek
03/16/2022, 4:34 PMNicole Lopez
03/16/2022, 4:42 PMDan Homola
03/17/2022, 10:31 AMNicole Lopez
03/17/2022, 1:36 PMMichal Hauzírek
03/17/2022, 6:25 PMNicole Lopez
03/17/2022, 6:33 PMMichal Hauzírek
03/17/2022, 9:30 PMDan Homola
03/18/2022, 8:32 AMbackend
object to communicate with the platform, see its API reference for more information on what the provided functions are.
Hope this helpsNicole Lopez
03/18/2022, 12:22 PMexport const GDAuthContextPrvider: FC = (props) => {
//const [isUserSignedIn, setIsUserSignedIn] = useState(false);
const backend = createBackend();
const fetchTest = async () => {
console.log(‘IS the user authenticated? : ’, await backend.isAuthenticated());
console.log(‘ORGANISATIONS: ’, await backend.organizations());
console.log(‘Current User: ’, await backend.currentUser());
console.log(‘WORKSPACES: ’, await backend.workspaces());
}Nicole Lopez
03/18/2022, 12:23 PMNicole Lopez
03/18/2022, 12:23 PMDan Homola
03/18/2022, 1:07 PM// the organizations API is simpler, it has just one method that gives you the current organization
const currentOrganization = await backend.organizations().getCurrentOrganization();
// the workspaces API is paginated so to get all the workspaces in an array, we must do it in two steps
const firstPageOfWorkspaces = await backend.workspaces().forCurrentUser().query();
const allPagesOfWorkspaces = await firstPageOfWorkspaces.all();
Does that make sense? Your IDE should be of assistance suggesting available members of the different parts of the API.Nicole Lopez
03/18/2022, 2:41 PMNicole Lopez
03/18/2022, 2:41 PMNicole Lopez
03/18/2022, 2:42 PMDan Homola
03/18/2022, 2:46 PMbackend.
your IDE should automatically suggest what is next. So when playing with the API, try to put a full-stop after everything and see if your IDE offers some more items.
As for your second question, the Bear part is correct, you are running your application against the GoodData platform which we codename bear in our developer facing libraries (more on that in our docs). But the objects you should be getting should be simpler, are you really calling the proper functions as per my previous example?Nicole Lopez
03/20/2022, 7:39 PMDan Homola
03/21/2022, 8:29 AMconst permissions = await backend.workspace("WORKSPACE").permissions().getPermissionsForCurrentUser();
const isAdmin = !!permissions.canManageProject; // or some other permission applicable to your use case
Nicole Lopez
03/21/2022, 4:26 PMDan Homola
03/21/2022, 4:30 PMNicole Lopez
03/23/2022, 9:43 AM