PurpleTurtleCreative / completionist

Asana integration plugin for WordPress.
https://purpleturtlecreative.com/completionist/
GNU General Public License v3.0
1 stars 0 forks source link

Fix singleton functionality of Asana_Interface::get_client() #143

Open MichelleBlanchette opened 1 year ago

MichelleBlanchette commented 1 year ago

Asana_Interface should instead maintain a map of its "instances" rather than having separate, individual static member variables. Additionally, I think get_client() and its counterparts should explicitly require a user ID be passed to it.

When authenticating multiple users within one session, such as when retrieving and testing "connected users", the authentication is lost each time the singleton loads a new client and user identity. This gets incredibly confusing and insecure as authentication happens across PHP files, function calls, and even processes (such as AJAX functionality).

This has been a problem I've repeatedly tried to fix, but it involves a massive amount of regression testing since this basically the core functionality.

While it's tempting to simply create an Asana_User instantiation class, you should keep in mind that an authenticated Asana client is often passed around between scripts. This is why a singleton was initially decided on being used, because it stores its instances in memory by default.

Additionally, I don't like all the uncaught exceptions, though it is important to distinguish errors (and their associated codes and messages) from actually empty or null data returns.

MichelleBlanchette commented 4 months ago

This would be a good opportunity to refactor/rewrite all Asana client-related code anyways since https://github.com/PurpleTurtleCreative/completionist/issues/217 and the PHP SDK seems to no longer be actively maintained...