-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add population of the service links table (#536)
- Loading branch information
Showing
16 changed files
with
284 additions
and
75 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
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 |
---|---|---|
|
@@ -40,10 +40,6 @@ public void restrictedResultWithoutScope() throws Exception { | |
.andExpect(jsonPath("$.data[1].attributes", not(hasKey("email")))) | ||
.andExpect(jsonPath("$.data[2].attributes", not(hasKey("email")))) | ||
.andExpect(jsonPath("$.data[3].attributes", not(hasKey("email")))) | ||
.andExpect(jsonPath("$.data[0].attributes", not(hasKey("steamId")))) | ||
.andExpect(jsonPath("$.data[1].attributes", not(hasKey("steamId")))) | ||
.andExpect(jsonPath("$.data[2].attributes", not(hasKey("steamId")))) | ||
.andExpect(jsonPath("$.data[3].attributes", not(hasKey("steamId")))) | ||
.andExpect(jsonPath("$.data[0].attributes", not(hasKey("recentIpAddress")))) | ||
.andExpect(jsonPath("$.data[1].attributes", not(hasKey("recentIpAddress")))) | ||
.andExpect(jsonPath("$.data[2].attributes", not(hasKey("recentIpAddress")))) | ||
|
@@ -59,7 +55,6 @@ public void restrictedResultWithoutScope() throws Exception { | |
// you are allowed to see your own stuff | ||
.andExpect(jsonPath("$.data[4].attributes.email", is("[email protected]"))) | ||
.andExpect(jsonPath("$.data[4].attributes.recentIpAddress", is("127.0.0.1"))) | ||
.andExpect(jsonPath("$.data[4].attributes", hasKey("steamId"))) | ||
.andExpect(jsonPath("$.data[4].attributes", hasKey("lastLogin"))) | ||
// you cannot see your uuid | ||
.andExpect(jsonPath("$.data[4].relationships", not(hasKey("uniqueIds")))) | ||
|
@@ -97,10 +92,6 @@ public void restrictedResultWithoutRole() throws Exception { | |
.andExpect(jsonPath("$.data[1].attributes", not(hasKey("email")))) | ||
.andExpect(jsonPath("$.data[2].attributes", not(hasKey("email")))) | ||
.andExpect(jsonPath("$.data[3].attributes", not(hasKey("email")))) | ||
.andExpect(jsonPath("$.data[0].attributes", not(hasKey("steamId")))) | ||
.andExpect(jsonPath("$.data[1].attributes", not(hasKey("steamId")))) | ||
.andExpect(jsonPath("$.data[2].attributes", not(hasKey("steamId")))) | ||
.andExpect(jsonPath("$.data[3].attributes", not(hasKey("steamId")))) | ||
.andExpect(jsonPath("$.data[0].attributes", not(hasKey("recentIpAddress")))) | ||
.andExpect(jsonPath("$.data[1].attributes", not(hasKey("recentIpAddress")))) | ||
.andExpect(jsonPath("$.data[2].attributes", not(hasKey("recentIpAddress")))) | ||
|
@@ -116,7 +107,6 @@ public void restrictedResultWithoutRole() throws Exception { | |
// you are allowed to see your own stuff | ||
.andExpect(jsonPath("$.data[4].attributes.email", is("[email protected]"))) | ||
.andExpect(jsonPath("$.data[4].attributes.recentIpAddress", is("127.0.0.1"))) | ||
.andExpect(jsonPath("$.data[4].attributes", hasKey("steamId"))) | ||
.andExpect(jsonPath("$.data[4].attributes", hasKey("lastLogin"))) | ||
.andExpect(jsonPath("$.data[4].relationships", hasKey("reporterOnModerationReports"))) | ||
.andExpect(jsonPath("$.data[4].relationships", hasKey("userGroups"))) | ||
|
@@ -167,11 +157,6 @@ public void canSeePrivateDetailsWithScopeAndRole() throws Exception { | |
.andExpect(jsonPath("$.data[2].attributes", hasKey("lastLogin"))) | ||
.andExpect(jsonPath("$.data[3].attributes", hasKey("lastLogin"))) | ||
.andExpect(jsonPath("$.data[4].attributes", hasKey("lastLogin"))) | ||
.andExpect(jsonPath("$.data[0].attributes", hasKey("steamId"))) | ||
.andExpect(jsonPath("$.data[1].attributes", hasKey("steamId"))) | ||
.andExpect(jsonPath("$.data[2].attributes", hasKey("steamId"))) | ||
.andExpect(jsonPath("$.data[3].attributes", hasKey("steamId"))) | ||
.andExpect(jsonPath("$.data[4].attributes", hasKey("steamId"))) | ||
.andExpect(jsonPath("$.data[0].relationships", hasKey("uniqueIds"))) | ||
.andExpect(jsonPath("$.data[1].relationships", hasKey("uniqueIds"))) | ||
.andExpect(jsonPath("$.data[2].relationships", hasKey("uniqueIds"))) | ||
|
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
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
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 |
---|---|---|
|
@@ -3,15 +3,17 @@ VALUES ('test', 'test', '{noop}test', 'public', 'http://localhost https://www.ge | |
'http://localhost', | ||
'read_events read_achievements upload_map upload_mod upload_avatar write_account_data vote read_sensible_userdata'); | ||
|
||
INSERT INTO login (id, login, email, password, steamid, ip) | ||
VALUES (1, 'USER', '[email protected]', '92b7b421992ef490f3b75898ec0e511f1a5c02422819d89719b20362b023ee4f', NULL, | ||
INSERT INTO login (id, login, email, password, ip) | ||
VALUES (1, 'USER', '[email protected]', '92b7b421992ef490f3b75898ec0e511f1a5c02422819d89719b20362b023ee4f', | ||
'127.0.0.1'), | ||
(2, 'MODERATOR', '[email protected]', '778ac5b81fa251b450f827846378739caee510c31b01cfa9d31822b88bed8441', | ||
1234, '127.0.0.1'), | ||
(3, 'ADMIN', '[email protected]', '835d6dc88b708bc646d6db82c853ef4182fabbd4a8de59c213f2b5ab3ae7d9be', NULL, | ||
'127.0.0.1'), | ||
(4, 'BANNED', '[email protected]', '', NULL, '127.0.0.1'), | ||
(5, 'ACTIVE_USER', '[email protected]', '', null, '127.0.0.1'); | ||
(2, 'MODERATOR', '[email protected]', '778ac5b81fa251b450f827846378739caee510c31b01cfa9d31822b88bed8441', '127.0.0.1'), | ||
(3, 'ADMIN', '[email protected]', '835d6dc88b708bc646d6db82c853ef4182fabbd4a8de59c213f2b5ab3ae7d9be', '127.0.0.1'), | ||
(4, 'BANNED', '[email protected]', '', '127.0.0.1'), | ||
(5, 'ACTIVE_USER', '[email protected]', '', '127.0.0.1'); | ||
|
||
INSERT INTO service_links (id, user_id, service_id, type, public, ownership) | ||
VALUES (UUID(), 2, '1234', 'STEAM', false, true), | ||
(UUID(), 2, 'username', 'GOG', false, true); | ||
|
||
INSERT INTO user_group (id, technical_name, name_key, parent_group_id, public) | ||
VALUES (1, 'ADMINISTRATOR', 'administrator', null, true), | ||
|
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
84 changes: 84 additions & 0 deletions
84
src/main/java/com/faforever/api/data/domain/AccountLink.java
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,84 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.IsEntityOwner; | ||
import com.faforever.api.data.checks.Prefab; | ||
import com.faforever.api.security.elide.permission.ReadAccountPrivateDetailsCheck; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import com.yahoo.elide.annotation.UpdatePermission; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
import javax.persistence.Transient; | ||
|
||
@Entity | ||
@Table(name = "service_links") | ||
@Include(name = "accountLink") | ||
@Setter | ||
@ReadPermission(expression = IsEntityOwner.EXPRESSION + " OR " + ReadAccountPrivateDetailsCheck.EXPRESSION) | ||
public class AccountLink implements OwnableEntity { | ||
|
||
private String id; | ||
private User user; | ||
private LinkedServiceType serviceType; | ||
private String serviceId; | ||
private boolean public_; | ||
private boolean ownership; | ||
|
||
@Id | ||
@Column(name = "id") | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Column(name = "type") | ||
@Enumerated(EnumType.STRING) | ||
public LinkedServiceType getServiceType() { | ||
return serviceType; | ||
} | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
public User getUser() { | ||
return user; | ||
} | ||
|
||
@Column(name = "service_id") | ||
@UpdatePermission(expression = Prefab.NONE) | ||
public String getServiceId() { | ||
return serviceId; | ||
} | ||
|
||
@Column(name = "public") | ||
@ReadPermission(expression = ReadAccountPrivateDetailsCheck.EXPRESSION) | ||
public boolean getPublic() { | ||
return public_; | ||
} | ||
|
||
public AccountLink setPublic(boolean public_) { | ||
this.public_ = public_; | ||
return this; | ||
} | ||
|
||
@Column(name = "ownership") | ||
@ReadPermission(expression = ReadAccountPrivateDetailsCheck.EXPRESSION) | ||
public boolean getOwnership() { | ||
return ownership; | ||
} | ||
|
||
@Override | ||
@Transient | ||
@JsonIgnore | ||
public Login getEntityOwner() { | ||
return user; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/faforever/api/data/domain/LinkedServiceType.java
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,5 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
public enum LinkedServiceType { | ||
STEAM, GOG, DISCORD, PATREON; | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/faforever/api/user/AccountLinkRepository.java
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,16 @@ | ||
package com.faforever.api.user; | ||
|
||
import com.faforever.api.data.domain.AccountLink; | ||
import com.faforever.api.data.domain.LinkedServiceType; | ||
import com.faforever.api.data.domain.Login; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface AccountLinkRepository extends JpaRepository<AccountLink, String> { | ||
Optional<AccountLink> findOneByServiceIdAndServiceType(String serviceId, LinkedServiceType serviceType); | ||
|
||
boolean existsByUserAndServiceType(Login login, LinkedServiceType serviceType); | ||
} |
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
Oops, something went wrong.