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 Ember from 'ember';
|
||||||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
|
||||||
|
import constants from '../../../utils/constants';
|
||||||
|
|
||||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||||
userService: Ember.inject.service('user'),
|
userService: Ember.inject.service('user'),
|
||||||
global: Ember.inject.service('global'),
|
global: Ember.inject.service('global'),
|
||||||
|
appMeta: Ember.inject.service(),
|
||||||
|
|
||||||
beforeModel: function () {
|
beforeModel: function () {
|
||||||
if (!this.session.isAdmin) {
|
if (!this.session.isAdmin) {
|
||||||
|
@ -24,11 +26,17 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
return new Ember.RSVP.Promise((resolve) => {
|
return new Ember.RSVP.Promise((resolve) => {
|
||||||
this.get('global').syncExternalUsers().then(() => {
|
if (this.get('appMeta.authProvider') == constants.AuthProvider.Keycloak) {
|
||||||
this.get('userService').getAll().then((users) =>{
|
this.get('global').syncExternalUsers().then(() => {
|
||||||
|
this.get('userService').getComplete().then((users) =>{
|
||||||
|
resolve(users);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.get('userService').getComplete().then((users) =>{
|
||||||
resolve(users);
|
resolve(users);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,9 @@ export default Ember.Service.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns all users for organization.
|
// Returns all active users for organization.
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.get('ajax').request(`users`).then((response) => {
|
return this.get('ajax').request(`users?active=1`).then((response) => {
|
||||||
return response.map((obj) => {
|
return response.map((obj) => {
|
||||||
let data = this.get('store').normalize('user', obj);
|
let data = this.get('store').normalize('user', obj);
|
||||||
return this.get('store').push(data);
|
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.
|
// Returns all users that can see folder.
|
||||||
getFolderUsers(folderId) {
|
getFolderUsers(folderId) {
|
||||||
let url = `users/folder/${folderId}`;
|
let url = `users/folder/${folderId}`;
|
||||||
|
|
|
@ -191,6 +191,14 @@ func SyncKeycloak(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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
|
// Make Keycloak auth provider config
|
||||||
c := keycloakConfig{}
|
c := keycloakConfig{}
|
||||||
err = json.Unmarshal([]byte(org.AuthConfig), &c)
|
err = json.Unmarshal([]byte(org.AuthConfig), &c)
|
||||||
|
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/documize/community/core/utility"
|
"github.com/documize/community/core/utility"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddUser is the endpoint that enables an administrator to add a new user for their orgaisation.
|
// AddUser is the endpoint that enables an administrator to add a new user for their orgaisation.
|
||||||
|
@ -212,11 +213,30 @@ func GetOrganizationUsers(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
users, err := p.GetUsersForOrganization()
|
active, err := strconv.ParseBool(r.URL.Query().Get("active"))
|
||||||
|
if err != nil {
|
||||||
|
active = false
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
users := []entity.User{}
|
||||||
writeServerError(w, method, err)
|
|
||||||
return
|
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 {
|
for i := range users {
|
||||||
|
@ -224,7 +244,6 @@ func GetOrganizationUsers(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
json, err := json.Marshal(users)
|
json, err := json.Marshal(users)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeJSONMarshalError(w, method, "user", err)
|
writeJSONMarshalError(w, method, "user", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -155,6 +155,23 @@ func (p *Persister) GetUserBySerial(serial string) (user entity.User, err error)
|
||||||
return
|
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
|
// GetUsersForOrganization returns a slice containing all of the user records for the organizaiton
|
||||||
// identified in the Persister.
|
// identified in the Persister.
|
||||||
func (p *Persister) GetUsersForOrganization() (users []entity.User, err error) {
|
func (p *Persister) GetUsersForOrganization() (users []entity.User, err error) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue