-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
[NEW] Edit user permissions #7309
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
623f166
Edit roles work in progress.
MartinSchoeler 0c4d4f4
support for multiple roles
MartinSchoeler 024274b
Merge remote-tracking branch 'origin/develop' into edit-user-permissions
MartinSchoeler bc4fdc9
use chips instead of selects
MartinSchoeler 509642e
Add Translations
MartinSchoeler 8a123c6
Fix tests
MartinSchoeler 4bf0aa1
Show only user scoped roles
MartinSchoeler 87ea965
fix tests
MartinSchoeler a8ff1b2
use argument
MartinSchoeler ab192d3
Merge branch 'develop' into edit-user-permissions
rodrigok e53904d
Fix i18n
rodrigok 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3524,6 +3524,10 @@ body:not(.is-cordova) { | |
& #password { | ||
width: 70%; | ||
} | ||
|
||
& #roleSelect { | ||
width: 70%; | ||
} | ||
} | ||
|
||
& nav { | ||
|
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,18 @@ | ||
.chip-container { | ||
list-style-type: none; | ||
margin: 15px; | ||
} | ||
|
||
.chip-container li { | ||
display: inline-block; | ||
background-color: #dddddd; | ||
border-radius: 10px; | ||
padding: 2px 8px 2px 2px; | ||
margin: 1px 0; | ||
cursor: pointer; | ||
} | ||
|
||
.chip-container li .icon-plus-circled { | ||
opacity: 0.5; | ||
font-size: 0.8rem; | ||
} |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import toastr from 'toastr'; | ||
|
||
Template.userEdit.helpers({ | ||
|
||
disabled(cursor) { | ||
return cursor.count() === 0 ? 'disabled' : ''; | ||
}, | ||
canEditOrAdd() { | ||
return (Template.instance().user && RocketChat.authz.hasAtLeastOnePermission('edit-other-user-info')) || (!Template.instance().user && RocketChat.authz.hasAtLeastOnePermission('create-user')); | ||
}, | ||
|
@@ -14,13 +18,12 @@ Template.userEdit.helpers({ | |
}, | ||
|
||
role() { | ||
return RocketChat.models.Roles.find({}, { sort: { description: 1, _id: 1 } }); | ||
const roles = Template.instance().roles.get(); | ||
return RocketChat.models.Roles.find({_id: {$nin:roles}, scope: 'Users'}, { sort: { description: 1, _id: 1 } }); | ||
}, | ||
|
||
selectUserRole() { | ||
if (this._id === 'user') { | ||
return 'selected'; | ||
} | ||
userRoles() { | ||
return Template.instance().roles.get(); | ||
}, | ||
|
||
name() { | ||
|
@@ -32,26 +35,50 @@ Template.userEdit.events({ | |
'click .cancel'(e, t) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
return t.cancel(t.find('form')); | ||
Template.instance().roles.set([]); | ||
t.cancel(t.find('form')); | ||
}, | ||
|
||
'click .remove-role'(e) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
let roles = Template.instance().roles.get(); | ||
roles = roles.filter(el => el !== this.valueOf()); | ||
Template.instance().roles.set(roles); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can add a second parameter ( |
||
$(`[title=${ this }]`).remove(); | ||
}, | ||
|
||
'click #randomPassword'(e) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
return $('#password').val(Random.id()); | ||
$('#password').val(Random.id()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}, | ||
|
||
'submit form'(e, t) { | ||
'click #addRole'(e, instance) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
if ($('#roleSelect').find(':selected').is(':disabled')) { | ||
return; | ||
} | ||
const userRoles = [...instance.roles.get()]; | ||
userRoles.push($('#roleSelect').val()); | ||
instance.roles.set(userRoles); | ||
$('#roleSelect').val('placeholder'); | ||
}, | ||
|
||
return t.save(e.currentTarget); | ||
'submit form'(e, t) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
t.save(e.currentTarget); | ||
} | ||
}); | ||
|
||
|
||
Template.userEdit.onCreated(function() { | ||
let userData; | ||
this.user = this.data != null ? this.data.user : undefined; | ||
this.roles = this.user ? new ReactiveVar(this.user.roles) : new ReactiveVar([]); | ||
|
||
|
||
const { tabBar } = Template.currentData(); | ||
|
||
|
@@ -75,7 +102,15 @@ Template.userEdit.onCreated(function() { | |
userData.requirePasswordChange = this.$('#changePassword:checked').length > 0; | ||
userData.joinDefaultChannels = this.$('#joinDefaultChannels:checked').length > 0; | ||
userData.sendWelcomeEmail = this.$('#sendWelcomeEmail:checked').length > 0; | ||
if (this.$('#role').val()) { userData.roles = [this.$('#role').val()]; } | ||
const roleSelect = this.$('.remove-role').toArray(); | ||
|
||
if (roleSelect.length > 0) { | ||
const notSorted = roleSelect.map(role => { | ||
return role.title; | ||
}); | ||
//Remove duplicate strings from the array | ||
userData.roles = notSorted.filter((el, index) => notSorted.indexOf(el) === index); | ||
} | ||
return userData; | ||
}; | ||
|
||
|
@@ -93,6 +128,10 @@ Template.userEdit.onCreated(function() { | |
errors.push('Email'); | ||
} | ||
|
||
if (!userData.roles) { | ||
errors.push('Roles'); | ||
} | ||
|
||
for (const error of Array.from(errors)) { | ||
toastr.error(TAPi18n.__('error-the-field-is-required', { field: TAPi18n.__(error) })); | ||
} | ||
|
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
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.
you can use
t
instead ofTemplate.instance()
, right?