-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add an option to restrict which locales a user can edit #1004
Merged
+655
−32
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
25 changes: 25 additions & 0 deletions
25
restclient/src/main/java/com/box/l10n/mojito/rest/entity/UserLocale.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,25 @@ | ||
package com.box.l10n.mojito.rest.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonBackReference; | ||
|
||
public class UserLocale { | ||
@JsonBackReference private User user; | ||
|
||
private Locale locale; | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
public Locale getLocale() { | ||
return locale; | ||
} | ||
|
||
public void setLocale(Locale locale) { | ||
this.locale = locale; | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
webapp/src/main/java/com/box/l10n/mojito/entity/security/user/UserLocale.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,67 @@ | ||
package com.box.l10n.mojito.entity.security.user; | ||
|
||
import com.box.l10n.mojito.entity.BaseEntity; | ||
import com.box.l10n.mojito.entity.Locale; | ||
import com.box.l10n.mojito.rest.View; | ||
import com.fasterxml.jackson.annotation.JsonBackReference; | ||
import com.fasterxml.jackson.annotation.JsonView; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.ForeignKey; | ||
import jakarta.persistence.Index; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import java.io.Serializable; | ||
import org.hibernate.annotations.BatchSize; | ||
|
||
@Entity | ||
@Table( | ||
name = "user_locale", | ||
indexes = { | ||
@Index( | ||
name = "UK__USER_LOCALE__USER_ID__LOCALE_ID", | ||
columnList = "user_id, locale_id", | ||
unique = true) | ||
}) | ||
@BatchSize(size = 1000) | ||
public class UserLocale extends BaseEntity implements Serializable { | ||
|
||
@ManyToOne | ||
@JsonBackReference | ||
@JoinColumn( | ||
name = "user_id", | ||
foreignKey = @ForeignKey(name = "FK__USER_LOCALE__USER__ID"), | ||
nullable = false) | ||
User user; | ||
|
||
@JsonView(View.LocaleSummary.class) | ||
@ManyToOne | ||
@JoinColumn( | ||
name = "locale_id", | ||
foreignKey = @ForeignKey(name = "FK__USER_LOCALE__LOCALE__ID"), | ||
nullable = false) | ||
Locale locale; | ||
|
||
public UserLocale() {} | ||
|
||
public UserLocale(User user, Locale locale) { | ||
this.user = user; | ||
this.locale = locale; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
public Locale getLocale() { | ||
return locale; | ||
} | ||
|
||
public void setLocale(Locale locale) { | ||
this.locale = locale; | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the default user role is
USER
I think we should default this value to false, otherwise it might be confusing in the GUI that a basic user has this enabled but still can't translate any localesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, we should keep it as
true
. The default role for new users isUSER
, so it will likely be fairly common to accidentally createUSER
users instead ofTRANSLATOR
users. If theADMIN
then changes the role for the new user, then the new user will still be unable to translate anything, because thecanTranslateAllLocales
is nowfalse
. --> TheADMIN
now has to change two settings instead of one.Additionally, in your scenario, what is supposed to happen if the
ADMIN
downgrades aTRANSLATOR
toUSER
? ShouldcanTranslateAllLocales
also be disabled? In this case the role selection dropdown would effectively control two inputs, which feels inconsistent and unintuitive. If thecanTranslateAllLocales
field is not disabled it is inconsistent with creating a new user.So, I would rather solve this in the GUI, by disabling the checkbox for
USER
and displaying a short note explaining that this option won't have an effect because of the currently selected role. IMHO, this would have the least surprising behaviour for all users.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy for it to be handled in the GUI as you describe 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be implemented now.