Aqueduct 2.3.0: User-based Scoping, ORM Aggregate Functions

Aqueduct-server-side-Dart

This post details new exciting features for Aqueduct for Dart. Aqueduct 2.3.0 is now available on pub. This release offers additional behavior for the ORM and authorization libraries.

A new, optional method in AuthStorage allows you to limit scope based on some attribute of a user. For example, you might restrict certain scopes to only users that have admin privileges.

@override
List<AuthScope> allowedScopesForAuthenticatable(covariant User user) {
  if (user.role == "admin") {
    return AuthScope.Any;
  } else if (user.role == "user") {
    return [new AuthScope("profile"), new AuthScope("sensitive_data.readonly")];
  }

  return [];
}

Query instances may now use reduce functions like sumcount and average. Here’s an example:

var query = new Query<Book>()
  ..where.releasedOn = whereGreaterThan(new DateTime(2000));
var averagePriceOfBooksReleasedAfter2000 = await query.reduce.average((b) => b.price);

Persistent properties for ManagedObject can now be enumerated values. These values are stored as strings in the underlying database and have an implicit Validate.oneOf validator.

enum UserType {
  admin, user
}

class User extends ManagedObject<_User> implements _User {}
class _User {
  @managedPrimaryKey
  int id;

  String email;
  UserType type;
}

There are now more than 50 documentation guides available here with detailed explanations and examples.

See the full set of 2.3.0 changes here.

You can read more about Aqueduct for Dart here.

Say hello to your new mobile product team.

  • This field is for validation purposes and should be left unchanged.


0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *