mirror of
https://github.com/documize/community.git
synced 2025-07-24 07:39:43 +02:00
Problem: we are showing inactive users in lists
Solution: allow optional parameter to show/hide inactive users
This commit is contained in:
parent
90eb4f9517
commit
fa0f176613
5 changed files with 73 additions and 10 deletions
|
@ -11,10 +11,12 @@
|
|||
|
||||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||
import constants from '../../../utils/constants';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
userService: Ember.inject.service('user'),
|
||||
global: Ember.inject.service('global'),
|
||||
appMeta: Ember.inject.service(),
|
||||
|
||||
beforeModel: function () {
|
||||
if (!this.session.isAdmin) {
|
||||
|
@ -24,11 +26,17 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
|||
|
||||
model() {
|
||||
return new Ember.RSVP.Promise((resolve) => {
|
||||
if (this.get('appMeta.authProvider') == constants.AuthProvider.Keycloak) {
|
||||
this.get('global').syncExternalUsers().then(() => {
|
||||
this.get('userService').getAll().then((users) =>{
|
||||
this.get('userService').getComplete().then((users) =>{
|
||||
resolve(users);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.get('userService').getComplete().then((users) =>{
|
||||
resolve(users);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -46,9 +46,9 @@ export default Ember.Service.extend({
|
|||
});
|
||||
},
|
||||
|
||||
// Returns all users for organization.
|
||||
// Returns all active users for organization.
|
||||
getAll() {
|
||||
return this.get('ajax').request(`users`).then((response) => {
|
||||
return this.get('ajax').request(`users?active=1`).then((response) => {
|
||||
return response.map((obj) => {
|
||||
let data = this.get('store').normalize('user', obj);
|
||||
return this.get('store').push(data);
|
||||
|
@ -56,6 +56,17 @@ export default Ember.Service.extend({
|
|||
});
|
||||
},
|
||||
|
||||
// Returns all active and inactive users for organization.
|
||||
getComplete() {
|
||||
return this.get('ajax').request(`users?active=0`).then((response) => {
|
||||
return response.map((obj) => {
|
||||
let data = this.get('store').normalize('user', obj);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
// Returns all users that can see folder.
|
||||
getFolderUsers(folderId) {
|
||||
let url = `users/folder/${folderId}`;
|
||||
|
|
|
@ -191,6 +191,14 @@ func SyncKeycloak(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Exit if not using Keycloak
|
||||
if org.AuthProvider != "keycloak" {
|
||||
result.Message = "Skipping user sync with Keycloak as it is not the configured option"
|
||||
log.Info(result.Message)
|
||||
util.WriteJSON(w, result)
|
||||
return
|
||||
}
|
||||
|
||||
// Make Keycloak auth provider config
|
||||
c := keycloakConfig{}
|
||||
err = json.Unmarshal([]byte(org.AuthConfig), &c)
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/documize/community/core/utility"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// AddUser is the endpoint that enables an administrator to add a new user for their orgaisation.
|
||||
|
@ -212,19 +213,37 @@ func GetOrganizationUsers(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
users, err := p.GetUsersForOrganization()
|
||||
active, err := strconv.ParseBool(r.URL.Query().Get("active"))
|
||||
if err != nil {
|
||||
active = false
|
||||
}
|
||||
|
||||
users := []entity.User{}
|
||||
|
||||
if active {
|
||||
users, err = p.GetActiveUsersForOrganization()
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
writeServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
users, err = p.GetUsersForOrganization()
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
writeServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(users) == 0 {
|
||||
users = []entity.User{}
|
||||
}
|
||||
|
||||
for i := range users {
|
||||
attachUserAccounts(p, p.Context.OrgID, &users[i])
|
||||
}
|
||||
|
||||
json, err := json.Marshal(users)
|
||||
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "user", err)
|
||||
return
|
||||
|
|
|
@ -155,6 +155,23 @@ func (p *Persister) GetUserBySerial(serial string) (user entity.User, err error)
|
|||
return
|
||||
}
|
||||
|
||||
// GetActiveUsersForOrganization returns a slice containing of active user records for the organization
|
||||
// identified in the Persister.
|
||||
func (p *Persister) GetActiveUsersForOrganization() (users []entity.User, err error) {
|
||||
err = Db.Select(&users,
|
||||
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.created, u.revised
|
||||
FROM user u
|
||||
WHERE u.refid IN (SELECT userid FROM account WHERE orgid = ? AND active=1) ORDER BY u.firstname,u.lastname`,
|
||||
p.Context.OrgID)
|
||||
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("Unable to get all users for org %s", p.Context.OrgID), err)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetUsersForOrganization returns a slice containing all of the user records for the organizaiton
|
||||
// identified in the Persister.
|
||||
func (p *Persister) GetUsersForOrganization() (users []entity.User, err error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue