-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83d69b9
commit 8e2a396
Showing
2 changed files
with
80 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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,70 @@ | ||
package auth | ||
|
||
import "github.com/cthit/goldapps/internal/pkg/model" | ||
|
||
type AuthSuperGroup struct { | ||
Name string `json:"name"` | ||
PrettyName string `json:"prettyName"` | ||
Type string `json:"type"` | ||
Members []struct { | ||
Post struct { | ||
PostID string `json:"postId"` | ||
SvText string `json:"svText"` | ||
EnText string `json:"enText"` | ||
EmailPrefix string `json:"emailPrefix"` | ||
} `json:"post"` | ||
User AuthUser `json:"user"` | ||
} `json:"members"` | ||
} | ||
|
||
type AuthUser struct { | ||
Email string `json:"email"` | ||
Cid string `json:"cid"` | ||
FirstName string `json:"firstName"` | ||
LastName string `json:"lastName"` | ||
Nick string `json:"nick"` | ||
} | ||
|
||
type AuthSuperGroups []AuthSuperGroup | ||
|
||
type AuthUsers []AuthUser | ||
|
||
func (user AuthUser) ToUser() model.Users { | ||
return model.Users{ | ||
model.User{ | ||
Cid: user.Cid, | ||
FirstName: user.FirstName, | ||
SecondName: user.LastName, | ||
Nick: user.Nick, | ||
Mail: user.Email, | ||
}, | ||
} | ||
} | ||
|
||
func (users AuthUsers) ToUsers() model.Users { | ||
usersList := model.Users{} | ||
for _, user := range users { | ||
usersList = append(usersList, user.ToUser()...) | ||
} | ||
return usersList | ||
} | ||
|
||
func (superGroup AuthSuperGroup) ToGroup() model.Group { | ||
group := model.Group{ | ||
Email: superGroup.Name + "@chalmers.it", | ||
Type: superGroup.Type, | ||
Aliases: []string{}, | ||
} | ||
for _, member := range superGroup.Members { | ||
group.Members = append(group.Members, member.User.Email) | ||
} | ||
return group | ||
} | ||
|
||
func (superGroups AuthSuperGroups) ToGroups() model.Groups { | ||
groupsList := model.Groups{} | ||
for _, superGroup := range superGroups { | ||
groupsList = append(groupsList, superGroup.ToGroup()) | ||
} | ||
return groupsList | ||
} |
This file contains 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