[IMPROVE] Refactor Bridges#399
Conversation
Codecov Report
@@ Coverage Diff @@
## alpha #399 +/- ##
==========================================
- Coverage 51.68% 49.16% -2.53%
==========================================
Files 74 109 +35
Lines 2790 3513 +723
Branches 421 532 +111
==========================================
+ Hits 1442 1727 +285
- Misses 1348 1786 +438
Continue to review full report at Codecov.
|
d-gubert
left a comment
There was a problem hiding this comment.
-
Do we still need the bridge interfaces? For instance
IUserBridgeorILivechatBridge. Considering now we have other definitions of the bridges in the form of abstract classes, it looks to me that we can safely remove their interface counterparts. -
Some bridges don't require permissions to execute their actions (
AppActivationBridgefor instance). Do they still need thedoStuff()andstuff()method definitions? -
With the new changes, no error is thrown when an app tries to do something it doesn't have permission to. This can make troubleshooting much harder.
@thassiov what do you think?
…ge abstract class
|
|
||
| private hasReadPermission(appId: string): boolean { | ||
| if (AppPermissionManager.hasPermission(appId, AppPermissions.message.read)) { | ||
| console.log('message read permissions has', appId); |
There was a problem hiding this comment.
@d-gubert , that's an necessary console.log or we can remove them in a future PR?
There was a problem hiding this comment.
Oops. Yeah, I guess we can remove it in the next release. Thanks for the heads up :)
Using a
Proxyto check for permissions in the bridges ended up being too loosely coupled with the bridges themselves. For instance, to create a new bridge, one is required to:AppPermissionManager, which wraps the bridge with aProxyat runtime when the engine gets it via thegetNewBridge()method.Another example of this is that the
Proxyused in theAppPermissionManagerrelies on the name of the bridge to be exactly the same both in the host implementation and the permission checker, which is very loosely coupled and error-prone.Conversely, the
AppPermissionManageris too tied up to the concept of bridges by providing a method to wrap only bridge objects.Basically, there is no mechanism in the code linking these components, even though they are conceptually linked.
Solution Proposal
One possible way to tie up these knots is by refactoring the bridges to be classes instead of interfaces. This will allow us to require the host system to extend these classes when implementing the bridges, which will provide us with a more reliable way of asserting that the host's implementation is correct and will also help the host with this implementation. Another benefit will be the possibility of colocating the permission checking with the actual bridge definition, by employing the Template Method pattern.
For example, let's take the message bridge: instead of having an
IMessageBridgeinterface, anAppMessageBridgepermission checker and theAppPermissionManagertying them up with aProxy, we could have: