Skip to content

Commit

Permalink
Merge pull request #221 from hkad98/PSDK-138
Browse files Browse the repository at this point in the history
PSDK-138 Extend CatalogUser methods with user groups manipulation

Reviewed-by: Jan Soubusta
             https://github.com/jaceksan
  • Loading branch information
gdgate committed Feb 27, 2023
2 parents ba53804 + 19a4333 commit c2a471b
Show file tree
Hide file tree
Showing 6 changed files with 497 additions and 14 deletions.
48 changes: 38 additions & 10 deletions gooddata-sdk/gooddata_sdk/catalog/user/entity_model/user.py
Expand Up @@ -52,8 +52,32 @@ def init(
return cls(id=user_id, attributes=attributes, relationships=relationships)

@property
def get_user_groups(self) -> List[str]:
return self.relationships.get_user_groups if self.relationships is not None else []
def user_groups(self) -> List[CatalogUserGroup]:
if self.relationships and self.relationships.user_groups:
return self.relationships.user_groups.data
return []

def add_user_group(self, user_group: CatalogUserGroup) -> None:
if not self.relationships:
self.relationships = CatalogUserRelationships(user_groups=CatalogUserGroupsData(data=[user_group]))
else:
self.relationships.add_user_groups([user_group])

def add_user_groups(self, user_groups: list[CatalogUserGroup]) -> None:
if not self.relationships:
self.relationships = CatalogUserRelationships(user_groups=CatalogUserGroupsData(data=user_groups))
else:
self.relationships.add_user_groups(user_groups)

def remove_user_groups(self) -> None:
if self.relationships:
self.relationships.user_groups = None

def replace_user_groups(self, user_groups: list[CatalogUserGroup]) -> None:
if not self.relationships:
self.relationships = CatalogUserRelationships(user_groups=CatalogUserGroupsData(data=user_groups))
else:
self.relationships.replace_user_groups(user_groups)


@attr.s(auto_attribs=True, kw_only=True)
Expand All @@ -65,9 +89,17 @@ class CatalogUserAttributes(Base):
class CatalogUserRelationships(Base):
user_groups: Optional[CatalogUserGroupsData] = None

@property
def get_user_groups(self) -> List[str]:
return self.user_groups.get_user_groups if self.user_groups is not None else []
def add_user_groups(self, user_groups: list[CatalogUserGroup]) -> None:
if not self.user_groups:
self.user_groups = CatalogUserGroupsData(data=user_groups)
else:
self.user_groups.data.extend(user_groups)

def replace_user_groups(self, user_groups: list[CatalogUserGroup]) -> None:
if not self.user_groups:
self.user_groups = CatalogUserGroupsData(data=user_groups)
else:
self.user_groups.data = user_groups

@classmethod
def create_user_relationships(cls, user_group_ids: Optional[List[str]]) -> CatalogUserRelationships:
Expand All @@ -81,8 +113,4 @@ def create_user_relationships(cls, user_group_ids: Optional[List[str]]) -> Catal

@attr.s(auto_attribs=True, kw_only=True)
class CatalogUserGroupsData(Base):
data: Optional[List[CatalogUserGroup]] = None

@property
def get_user_groups(self) -> List[str]:
return [user_group.id for user_group in self.data] if self.data is not None else []
data: List[CatalogUserGroup] = attr.field(factory=list)
@@ -0,0 +1,91 @@
# (C) 2023 GoodData Corporation
version: 1
interactions:
- request:
method: GET
uri: http://localhost:3000/api/v1/entities/users/demo2?include=userGroups
body: null
headers:
Accept:
- application/vnd.gooddata.api+json
X-GDC-VALIDATE-RELATIONS:
- 'true'
X-Requested-With:
- XMLHttpRequest
response:
status:
code: 200
message: OK
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Expose-Headers:
- Content-Disposition, Content-Length, Content-Range, Set-Cookie
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Connection:
- keep-alive
Content-Length:
- '447'
Content-Security-Policy:
- 'default-src ''self'' *.wistia.com *.wistia.net; script-src ''self'' ''unsafe-inline''
''unsafe-eval'' *.wistia.com *.wistia.net src.litix.io matomo.anywhere.gooddata.com
code.jquery.com unpkg.com cdn.jsdelivr.net cdnjs.cloudflare.com; img-src
''self'' data: blob: *.wistia.com *.wistia.net embedwistia-a.akamaihd.net
privacy-policy.truste.com www.gooddata.com; style-src ''self'' ''unsafe-inline''
fonts.googleapis.com cdn.jsdelivr.net fast.fonts.net; font-src ''self''
data: fonts.gstatic.com *.alicdn.com *.wistia.com cdn.jsdelivr.net info.gooddata.com;
frame-src ''self''; object-src ''none''; worker-src ''self'' blob:; child-src
blob:; connect-src ''self'' *.tiles.mapbox.com *.mapbox.com *.litix.io
*.wistia.com embedwistia-a.akamaihd.net matomo.anywhere.gooddata.com;
media-src ''self'' blob: data: *.wistia.com *.wistia.net embedwistia-a.akamaihd.net'
Content-Type:
- application/vnd.gooddata.api+json
Date: &id001
- PLACEHOLDER
Expires:
- '0'
GoodData-Deployment:
- aio
Permission-Policy:
- geolocation 'none'; midi 'none'; sync-xhr 'none'; microphone 'none'; camera
'none'; magnetometer 'none'; gyroscope 'none'; fullscreen 'none'; payment
'none';
Pragma:
- no-cache
Referrer-Policy:
- no-referrer
Server:
- nginx
Set-Cookie:
- SPRING_REDIRECT_URI=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00
GMT; HttpOnly; SameSite=Lax
Vary:
- Origin
- Access-Control-Request-Method
- Access-Control-Request-Headers
X-Content-Type-Options:
- nosniff
X-GDC-TRACE-ID: *id001
X-XSS-Protection:
- 1 ; mode=block
body:
string:
data:
id: demo2
type: user
attributes:
authenticationId: CiQ1MjI0OWQwYi1lYmI4LTQ3OWUtOGFiZi1jNzEyNmQzNWUwZTcSBWxvY2Fs
relationships:
userGroups:
data:
- id: demoGroup
type: userGroup
included:
- id: demoGroup
type: userGroup
attributes: {}
links:
self: http://localhost:3000/api/v1/entities/userGroups/demoGroup
links:
self: http://localhost:3000/api/v1/entities/users/demo2?include=userGroups
@@ -0,0 +1,91 @@
# (C) 2023 GoodData Corporation
version: 1
interactions:
- request:
method: GET
uri: http://localhost:3000/api/v1/entities/users/demo2?include=userGroups
body: null
headers:
Accept:
- application/vnd.gooddata.api+json
X-GDC-VALIDATE-RELATIONS:
- 'true'
X-Requested-With:
- XMLHttpRequest
response:
status:
code: 200
message: OK
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Expose-Headers:
- Content-Disposition, Content-Length, Content-Range, Set-Cookie
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Connection:
- keep-alive
Content-Length:
- '447'
Content-Security-Policy:
- 'default-src ''self'' *.wistia.com *.wistia.net; script-src ''self'' ''unsafe-inline''
''unsafe-eval'' *.wistia.com *.wistia.net src.litix.io matomo.anywhere.gooddata.com
code.jquery.com unpkg.com cdn.jsdelivr.net cdnjs.cloudflare.com; img-src
''self'' data: blob: *.wistia.com *.wistia.net embedwistia-a.akamaihd.net
privacy-policy.truste.com www.gooddata.com; style-src ''self'' ''unsafe-inline''
fonts.googleapis.com cdn.jsdelivr.net fast.fonts.net; font-src ''self''
data: fonts.gstatic.com *.alicdn.com *.wistia.com cdn.jsdelivr.net info.gooddata.com;
frame-src ''self''; object-src ''none''; worker-src ''self'' blob:; child-src
blob:; connect-src ''self'' *.tiles.mapbox.com *.mapbox.com *.litix.io
*.wistia.com embedwistia-a.akamaihd.net matomo.anywhere.gooddata.com;
media-src ''self'' blob: data: *.wistia.com *.wistia.net embedwistia-a.akamaihd.net'
Content-Type:
- application/vnd.gooddata.api+json
Date: &id001
- PLACEHOLDER
Expires:
- '0'
GoodData-Deployment:
- aio
Permission-Policy:
- geolocation 'none'; midi 'none'; sync-xhr 'none'; microphone 'none'; camera
'none'; magnetometer 'none'; gyroscope 'none'; fullscreen 'none'; payment
'none';
Pragma:
- no-cache
Referrer-Policy:
- no-referrer
Server:
- nginx
Set-Cookie:
- SPRING_REDIRECT_URI=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00
GMT; HttpOnly; SameSite=Lax
Vary:
- Origin
- Access-Control-Request-Method
- Access-Control-Request-Headers
X-Content-Type-Options:
- nosniff
X-GDC-TRACE-ID: *id001
X-XSS-Protection:
- 1 ; mode=block
body:
string:
data:
id: demo2
type: user
attributes:
authenticationId: CiQ1MjI0OWQwYi1lYmI4LTQ3OWUtOGFiZi1jNzEyNmQzNWUwZTcSBWxvY2Fs
relationships:
userGroups:
data:
- id: demoGroup
type: userGroup
included:
- id: demoGroup
type: userGroup
attributes: {}
links:
self: http://localhost:3000/api/v1/entities/userGroups/demoGroup
links:
self: http://localhost:3000/api/v1/entities/users/demo2?include=userGroups
@@ -0,0 +1,91 @@
# (C) 2023 GoodData Corporation
version: 1
interactions:
- request:
method: GET
uri: http://localhost:3000/api/v1/entities/users/demo2?include=userGroups
body: null
headers:
Accept:
- application/vnd.gooddata.api+json
X-GDC-VALIDATE-RELATIONS:
- 'true'
X-Requested-With:
- XMLHttpRequest
response:
status:
code: 200
message: OK
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Expose-Headers:
- Content-Disposition, Content-Length, Content-Range, Set-Cookie
Cache-Control:
- no-cache, no-store, max-age=0, must-revalidate
Connection:
- keep-alive
Content-Length:
- '447'
Content-Security-Policy:
- 'default-src ''self'' *.wistia.com *.wistia.net; script-src ''self'' ''unsafe-inline''
''unsafe-eval'' *.wistia.com *.wistia.net src.litix.io matomo.anywhere.gooddata.com
code.jquery.com unpkg.com cdn.jsdelivr.net cdnjs.cloudflare.com; img-src
''self'' data: blob: *.wistia.com *.wistia.net embedwistia-a.akamaihd.net
privacy-policy.truste.com www.gooddata.com; style-src ''self'' ''unsafe-inline''
fonts.googleapis.com cdn.jsdelivr.net fast.fonts.net; font-src ''self''
data: fonts.gstatic.com *.alicdn.com *.wistia.com cdn.jsdelivr.net info.gooddata.com;
frame-src ''self''; object-src ''none''; worker-src ''self'' blob:; child-src
blob:; connect-src ''self'' *.tiles.mapbox.com *.mapbox.com *.litix.io
*.wistia.com embedwistia-a.akamaihd.net matomo.anywhere.gooddata.com;
media-src ''self'' blob: data: *.wistia.com *.wistia.net embedwistia-a.akamaihd.net'
Content-Type:
- application/vnd.gooddata.api+json
Date: &id001
- PLACEHOLDER
Expires:
- '0'
GoodData-Deployment:
- aio
Permission-Policy:
- geolocation 'none'; midi 'none'; sync-xhr 'none'; microphone 'none'; camera
'none'; magnetometer 'none'; gyroscope 'none'; fullscreen 'none'; payment
'none';
Pragma:
- no-cache
Referrer-Policy:
- no-referrer
Server:
- nginx
Set-Cookie:
- SPRING_REDIRECT_URI=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00
GMT; HttpOnly; SameSite=Lax
Vary:
- Origin
- Access-Control-Request-Method
- Access-Control-Request-Headers
X-Content-Type-Options:
- nosniff
X-GDC-TRACE-ID: *id001
X-XSS-Protection:
- 1 ; mode=block
body:
string:
data:
id: demo2
type: user
attributes:
authenticationId: CiQ1MjI0OWQwYi1lYmI4LTQ3OWUtOGFiZi1jNzEyNmQzNWUwZTcSBWxvY2Fs
relationships:
userGroups:
data:
- id: demoGroup
type: userGroup
included:
- id: demoGroup
type: userGroup
attributes: {}
links:
self: http://localhost:3000/api/v1/entities/userGroups/demoGroup
links:
self: http://localhost:3000/api/v1/entities/users/demo2?include=userGroups

0 comments on commit c2a471b

Please sign in to comment.