Alfresco / alfresco-js-api

This project provides a JavaScript client API into the Alfresco REST API and Activiti REST API.
Apache License 2.0
118 stars 62 forks source link

Legacy groups API doesn't expose membership methods #426

Closed tokewf closed 1 year ago

tokewf commented 5 years ago

Type of issue: (check with "[x]")

- [ ] New feature request
- [x] Bug  
- [x] Support request

Current behavior: Using the groups API via the AlfrescoApiService from @alfresco/adf-core in an Angular app like so:

import {Component, OnInit} from '@angular/core'
import {AlfrescoApiService} from '@alfresco/adf-core'

@Component({...})
export class FooComponent implements OnInit {
  constructor(private apiService: AlfrescoApiService) { }

  ngOnInit() {
    this.apiService.groupsApi.listGroupMembershipsForPerson('-me-').then(res => console.log(res))
  }
}

throws an error that property listGroupMembershipsForPerson does not exist on type GroupsApi, even though the documentation states that the endpoint is available in Alfresco 5.2.1 and up (https://github.com/Alfresco/alfresco-js-api/blob/development/src/api/content-rest-api/docs/GroupsApi.md#listGroupMembershipsForPerson). I an running Alfresco 6.x, ADF 3.3.0.

Digging through the code, it seems that AlfrescoApiService.groupsApi (and the other properties of the service) uses AlfrescoApiCompatibility from @alfresco/js-api. The legacyGroupsApi of this compatibility API is implemented in src/api-legacy/content-rest-api/src/api/groupsApi.ts. This maps most—but not all—methods of the new GroupsApi in src/api/content-rest-api/api/groups.api.ts (Indeed, the new groups API is even made privately available to the legacy groups API as NewGroupsApi)

Crucially for my use case, the methods listGroupMemberships, listGroupMembershipsForPerson and listGroups are not available in the legacy groups API, which is the one I have access to via this.apiService.groupsApi as in the example above. While I could (rather confusingly) do this.apiService.groupsApi.groupsApi.listGroupMembershipsForPerson('-me-')—since the member groupsApi of groupsApi is the NewGroupsApi :confounded:—this new groups API is a private member, so I can't use it.

How do I get access to these API methods in my app?

DenysVuika commented 3 years ago

You can use the GroupsApi from the newest APIs.

@Component({...})
export class FooComponent implements OnInit {
  constructor(private apiService: AlfrescoApiService) { }

  ngOnInit() {
    const groupsApi = new GroupsApi(this.apiService.getInstance());
    groupsApi.listGroupMembershipsForPerson('-me-').then(res => console.log(res))
  }
}