Skip to content

Commit

Permalink
Fixed a bug in member.dart - it was using the base onepub url rather …
Browse files Browse the repository at this point in the history
…than the api url to fetch dart pub tokens.

The auth command was using the old name for the System Administrator role
  • Loading branch information
bsutton committed Feb 18, 2024
1 parent 0d1fc5e commit 37789f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/src/api/member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class Member {
/// Returns true if the currently logged in and active user is a system
/// administrator
static Future<bool> isSystemAdministrator() async {
final onepubUrl = OnePubSettings.use().onepubUrl!;
final onepubApiUrl = OnePubSettings.use().onepubApiUrl;

final tokenStore = OnePubTokenStore();

final token = tokenStore.getToken(onepubUrl);
final token = tokenStore.getToken(onepubApiUrl.toString());
if (token != null) {
final member = await API().fetchMember(token);
return member.roles.contains('System Administrator');
return member.roles.contains(RoleEnum.SystemAdministrator.name);
}

return false;
Expand Down
12 changes: 11 additions & 1 deletion tool/critical_test/pre_hook/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,22 @@ Future<void> main(List<String> args) async {
/// Check that the user is logged in before we proceed.
Future<void> preConditionIsLoggedIn() async {
final tokenStore = OnePubTokenStore();
if (!tokenStore.isLoggedIn(OnePubSettings.use().onepubApiUrl)) {
final onepubApiUrl = OnePubSettings.use().onepubApiUrl;
if (!tokenStore.isLoggedIn(onepubApiUrl)) {
printerr(red('Please use onepub import to import a '
'System Administrator from the test db'));
exit(1);
}

final token =
tokenStore.getToken(onepubApiUrl.toString());
if (token == null) {
printerr(red('''
Token store is in an inconsistent state - no credential found for logged in user.
Delete tokens using `dart pub token remove` and then re-auth'''));
exit(1);
}

if (!(await Member.isSystemAdministrator())) {
printerr(red('The Imported user is not a System Administrator'));
exit(1);
Expand Down

0 comments on commit 37789f2

Please sign in to comment.