-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from RocketChat/settings-users
Settings users
- Loading branch information
Showing
14 changed files
with
329 additions
and
3 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,4 @@ | ||
Meteor.methods | ||
setUserActiveStatus: (userId, active) -> | ||
Meteor.users.update userId, { $set: { active: active } } | ||
return 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
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
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
Template.settingsUsers.helpers | ||
isAdmin: -> | ||
return Meteor.user().admin is true | ||
isReady: -> | ||
return Template.instance().ready?.get() | ||
users: -> | ||
filter = _.trim Template.instance().filter?.get() | ||
if filter | ||
filterReg = new RegExp filter, "i" | ||
query = { $or: [ { username: filterReg }, { name: filterReg }, { "emails.address": filterReg } ] } | ||
else | ||
query = {} | ||
return Meteor.users.find(query, { limit: Template.instance().limit?.get(), sort: { username: 1 } }).fetch() | ||
name: -> | ||
return if @name then @name else TAPi18next.t 'project:Unnamed' | ||
email: -> | ||
return @emails?[0]?.address | ||
flexOpened: -> | ||
return 'opened' if Session.equals('flexOpened', true) | ||
arrowPosition: -> | ||
return 'left' unless Session.equals('flexOpened', true) | ||
userData: -> | ||
return Meteor.users.findOne Session.get 'settingsUsersSelected' | ||
phoneNumber: -> | ||
return '' unless @phoneNumber | ||
if @phoneNumber.length > 10 | ||
return "(#{@phoneNumber.substr(0,2)}) #{@phoneNumber.substr(2,5)}-#{@phoneNumber.substr(7)}" | ||
else | ||
return "(#{@phoneNumber.substr(0,2)}) #{@phoneNumber.substr(2,4)}-#{@phoneNumber.substr(6)}" | ||
lastLogin: -> | ||
if @lastLogin | ||
return moment(@lastLogin).format('LLL') | ||
utcOffset: -> | ||
if @utcOffset? | ||
if @utcOffset > 0 | ||
@utcOffset = "+#{@utcOffset}" | ||
|
||
return "UTC #{@utcOffset}" | ||
|
||
Template.settingsUsers.onCreated -> | ||
instance = @ | ||
@limit = new ReactiveVar 50 | ||
@filter = new ReactiveVar '' | ||
@ready = new ReactiveVar true | ||
|
||
@autorun -> | ||
filter = instance.filter.get() | ||
limit = instance.limit.get() | ||
subscription = instance.subscribe 'fullUsers', filter, limit | ||
instance.ready.set subscription.ready() | ||
|
||
Template.settingsUsers.onRendered -> | ||
Tracker.afterFlush -> | ||
SideNav.setFlex "settingsFlex" | ||
SideNav.openFlex() | ||
|
||
Template.settingsUsers.events | ||
'keydown #users-filter': (e) -> | ||
if e.which is 13 | ||
e.stopPropagation() | ||
e.preventDefault() | ||
|
||
'keyup #users-filter': (e, t) -> | ||
e.stopPropagation() | ||
e.preventDefault() | ||
t.filter.set e.currentTarget.value | ||
|
||
'click .flex-tab .more': -> | ||
if (Session.get('flexOpened')) | ||
Session.set('flexOpened',false) | ||
else | ||
Session.set('flexOpened', true) | ||
|
||
'click .user-info': (e) -> | ||
e.preventDefault() | ||
Session.set 'settingsUsersSelected', $(e.currentTarget).data('id') | ||
Session.set 'flexOpened', true | ||
|
||
'click .deactivate': -> | ||
Meteor.call 'setUserActiveStatus', Session.get('settingsUsersSelected'), false, (error, result) -> | ||
if result | ||
toastr.success t('User_has_been_deactivated') | ||
if error | ||
toastr.error error.reason | ||
|
||
'click .activate': -> | ||
Meteor.call 'setUserActiveStatus', Session.get('settingsUsersSelected'), true, (error, result) -> | ||
if result | ||
toastr.success t('User_has_been_activated') | ||
if error | ||
toastr.error error.reason | ||
|
||
'click .delete': -> | ||
swal { | ||
title: t('Are_you_sure') | ||
text: t('Delete_User_Warning') | ||
type: 'warning' | ||
showCancelButton: true | ||
confirmButtonColor: '#DD6B55' | ||
confirmButtonText: t('Yes_delete_it') | ||
cancelButtonText: t('Cancel') | ||
closeOnConfirm: false | ||
html: false | ||
}, -> | ||
swal | ||
title: t('Deleted') | ||
text: t('User_has_been_deleted') | ||
type: 'success' | ||
timer: 2000 | ||
showConfirmButton: false | ||
|
||
Meteor.call 'deleteUser', Session.get('settingsUsersSelected'), (error, result) -> | ||
if error | ||
toastr.error error.reason |
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,80 @@ | ||
<template name="settingsUsers"> | ||
<section class="page-container page-list"> | ||
<head class="fixed-title"> | ||
{{> burger}} | ||
<h2> | ||
<span class="room-title">{{_ "Users"}}</span> | ||
</h2> | ||
</head> | ||
<div class="content"> | ||
{{#unless isAdmin}} | ||
<p>You are not authorized to view this page.</p> | ||
{{else}} | ||
<form class="search-form" role="form"> | ||
<div class="input-line search"> | ||
<input type="text" id="users-filter" placeholder="{{_ "Search"}}" dir="auto"> | ||
<i class="icon-search"></i> | ||
{{#unless isReady}}<i class="icon-spin4"></i>{{/unless}} | ||
</div> | ||
</form> | ||
{{#if isReady}} | ||
<div class="results"> | ||
{{{_ "Showing_results" users.length}}} | ||
</div> | ||
<div class="list"> | ||
{{#each users}} | ||
<div class="user-info" data-id="{{_id}}"> | ||
<li class='user-image status-{{status}}'> | ||
{{> avatar username=username}} | ||
<h3>{{name}}</h3> | ||
</li> | ||
<ul> | ||
<li>@{{username}}</li> | ||
{{#if email}}<li>{{email}}</li>{{/if}} | ||
</ul> | ||
</div> | ||
{{/each}} | ||
</div> | ||
{{else}} | ||
<div class="results"> | ||
{{{_ "Loading..."}}} | ||
</div> | ||
{{/if}} | ||
{{/unless}} | ||
</div> | ||
</section> | ||
<section class="flex-tab"> | ||
<div class="control"> | ||
<button class="more"><span class="arrow {{arrowPosition}}"></span></button> | ||
</div> | ||
{{#if flexOpened}} | ||
<div class="content"> | ||
<div class="user-view"> | ||
{{#with userData}} | ||
<div class="about clearfix"> | ||
<div class="thumb"> | ||
{{> avatar username=username}} | ||
</div> | ||
<div class="info"> | ||
<h3>{{name}}</h3> | ||
<p><i class="icon-at"></i> {{username}}</p> | ||
{{#if utcOffset}}<p><i class="icon-location"></i> {{utcOffset}}</p>{{/if}} | ||
{{#each emails}} <p><i class="icon-mail"></i> {{address}}{{#if verified}} <i class="icon-ok"></i>{{/if}}</p> {{/each}} | ||
{{#each phone}} <p><i class="icon-phone"></i> {{phoneNumber}}</p> {{/each}} | ||
{{#if lastLogin}} <p><i class="icon-clock"></i> {{_ "Last_seen"}}: {{lastLogin}}</p> {{/if}} | ||
</div> | ||
</div> | ||
<nav> | ||
{{#if active}} | ||
<button class='button deactivate'><span><i class='icon-block'></i> {{_ "Deactivate"}}</span></button> | ||
{{else}} | ||
<button class='button activate'><span><i class='icon-ok-circled'></i> {{_ "Activate"}}</span></button> | ||
{{/if}} | ||
<button class='button delete red'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button> | ||
</nav> | ||
{{/with}} | ||
</div> | ||
</div> | ||
{{/if}} | ||
</section> | ||
</template> |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Meteor.methods | ||
deleteUser: (userId) -> | ||
if not Meteor.userId() | ||
throw new Meteor.Error('invalid-user', "[methods] deleteUser -> Invalid user") | ||
|
||
user = Meteor.users.findOne Meteor.userId() | ||
unless user?.admin is true | ||
throw new Meteor.Error 'not-authorized', '[methods] deleteUser -> Not authorized' | ||
|
||
return true | ||
# Meteor.users.remove userId |
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,15 @@ | ||
Meteor.methods | ||
setUserActiveStatus: (userId, active) -> | ||
if not Meteor.userId() | ||
throw new Meteor.Error 'invalid-user', '[methods] setUserActiveStatus -> Invalid user' | ||
|
||
user = Meteor.users.findOne Meteor.userId() | ||
unless user?.admin is true | ||
throw new Meteor.Error 'not-authorized', '[methods] setUserActiveStatus -> Not authorized' | ||
|
||
Meteor.users.update userId, { $set: { active: active } } | ||
|
||
if active is false | ||
Meteor.users.update userId, { $set: { "services.resume.loginTokens" : [] } } | ||
|
||
return true |
Oops, something went wrong.