-
Notifications
You must be signed in to change notification settings - Fork 143
feat: add B2B organization directory group synchronization through RabbitMQ. #4828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dc091d0
feat: RabbitMQ contract for group changed events
shepilov 92d6484
feat: index to list instances by org id
shepilov 3fc319d
feat: add org directory metadata for groups and contacts
shepilov c347786
feat: add org instance find functions
shepilov 5ae18f3
feat: add org directory groups operations
shepilov 15dcdd2
feat: add RabbitMQ handler for org directory
shepilov 31f28f3
feat: change user creations to support org groups as well
shepilov 814bcc4
feat: add pagination to all org find queries
shepilov 57b41b8
refactor: code improvements for the org directory management
shepilov b82f6e6
test: fix error message assertion in tests
shepilov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package orgdirectory | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/cozy/cozy-stack/model/contact" | ||
| "github.com/cozy/cozy-stack/model/instance" | ||
| "github.com/cozy/cozy-stack/pkg/utils" | ||
| ) | ||
|
|
||
| // ContactPatch describes a B2B contact replica to create or update. | ||
| type ContactPatch struct { | ||
| OrganizationID string | ||
| Username string | ||
| Email string | ||
| FirstName string | ||
| LastName string | ||
| WorkplaceFQDN string | ||
| Name string | ||
| CozyURL string | ||
| Phone string | ||
| } | ||
|
|
||
| func (patch ContactPatch) validate() error { | ||
| if strings.TrimSpace(patch.Email) == "" { | ||
| return fmt.Errorf("contact missing email") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (patch ContactPatch) shouldSkipOwn(inst *instance.Instance) bool { | ||
| if patch.WorkplaceFQDN != "" && inst.HasDomain(utils.ExtractInstanceHost(patch.WorkplaceFQDN)) { | ||
| return true | ||
| } | ||
| if patch.Email == "" { | ||
| return false | ||
| } | ||
| email, err := inst.SettingsEMail() | ||
| if err != nil { | ||
| return false | ||
| } | ||
| return strings.EqualFold(strings.TrimSpace(email), patch.Email) | ||
| } | ||
|
|
||
| func (patch ContactPatch) displayName() string { | ||
| if patch.Name != "" { | ||
| return patch.Name | ||
| } | ||
| name := strings.TrimSpace(patch.FirstName + " " + patch.LastName) | ||
| if name != "" { | ||
| return name | ||
| } | ||
| if patch.Username != "" { | ||
| return patch.Username | ||
| } | ||
| if patch.Email != "" { | ||
| parts := strings.SplitN(patch.Email, "@", 2) | ||
| return parts[0] | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func contactPatchFromMember(organizationID string, member GroupMember) ContactPatch { | ||
| workplaceFQDN := strings.TrimSpace(member.WorkplaceFQDN) | ||
| return ContactPatch{ | ||
| OrganizationID: strings.TrimSpace(organizationID), | ||
| Username: strings.TrimSpace(member.Username), | ||
| Email: strings.TrimSpace(member.Email), | ||
| FirstName: strings.TrimSpace(member.FirstName), | ||
| LastName: strings.TrimSpace(member.LastName), | ||
| WorkplaceFQDN: workplaceFQDN, | ||
| CozyURL: cozyURLFromWorkplaceFQDN(workplaceFQDN), | ||
| } | ||
| } | ||
|
|
||
| func contactPatchFromContact(organizationID string, contactDoc *contact.Contact) ContactPatch { | ||
| meta := directoryMetadata(&contactDoc.JSONDoc) | ||
| patch := ContactPatch{OrganizationID: organizationID} | ||
| patch.Username = meta.Username | ||
| patch.Email = meta.Email | ||
| patch.WorkplaceFQDN = meta.WorkplaceFQDN | ||
| patch.CozyURL = contactDoc.PrimaryCozyURL() | ||
| if patch.CozyURL == "" { | ||
| patch.CozyURL = cozyURLFromWorkplaceFQDN(patch.WorkplaceFQDN) | ||
| } | ||
| patch.Name = primaryContactName(contactDoc) | ||
| patch.Phone = contactDoc.PrimaryPhoneNumber() | ||
| return patch | ||
| } | ||
|
|
||
| func primaryContactName(contactDoc *contact.Contact) string { | ||
| name := contactDoc.PrimaryName() | ||
| if name != "" { | ||
| return name | ||
| } | ||
| displayName, _ := contactDoc.M["displayName"].(string) | ||
| return displayName | ||
| } | ||
|
|
||
| func cozyURLFromWorkplaceFQDN(workplaceFQDN string) string { | ||
| domain := utils.ExtractInstanceHost(workplaceFQDN) | ||
| if domain == "" { | ||
| return "" | ||
| } | ||
| return "https://" + domain | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.