client/src/selectors/authSelectors.js
author ymh <ymh.work@gmail.com>
Fri, 30 Nov 2018 10:53:15 +0100
changeset 183 f8f3af9e5c83
parent 170 7da1d5137b0b
permissions -rw-r--r--
Change the settings to avoid using Session authentication for rest framework as it raise exceptions in case client and backend are on the same domain On the filter, adapt to take into account new version of django_filters
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
// Selectors linked to the authentication status
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
     2
import * as R from 'ramda';
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
     4
export const getOnline = R.path(["status", 'online'])
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
     6
export const getToken = R.path(['authStatus','token'])
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
     8
export const isAuthenticated = R.path(['authStatus', 'isAuthenticated'])
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    10
export const getCurrentUser = R.path(['authStatus', 'currentUser'])
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    12
export const getClientId = R.path(['authStatus', 'clientId'])
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    14
export const getCurrentGroupName = R.path(['authStatus', 'currentGroup'])
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    15
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    16
export const getGroups = R.prop('groups')
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    18
const findByName = R.compose(R.find, R.propEq('name'));
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    19
const findByGroupName = R.compose(findByName, getCurrentGroupName);
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    21
// export const getCurrentGroup = state => {
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    22
//   const groupName = getCurrentGroupName(state);
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    23
//   const groups = getGroups(state);
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    24
//   if(groups) {
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    25
//     return groups.find( g => g['name'] === groupName );
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    26
//   } else {
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    27
//     return null;
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    28
//   }
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    29
// }
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    30
// https://stackoverflow.com/a/48924396
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    32
export const getCurrentGroup = R.unnest(R.converge(R.compose, [findByGroupName, R.always(getGroups)]))
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    34
export const getCreateGroup = R.prop('createGroup')
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    35
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 137
diff changeset
    36
export const getAutoSubmit = R.prop('autoSubmit')
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
170
7da1d5137b0b Upgrade dependencies and correct theme colors
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    38
export const getLoginErrorMessages = R.path(['login', 'errorMessages'])
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
137
279e1dffa213 session is now created with current group and protocol
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
    40
170
7da1d5137b0b Upgrade dependencies and correct theme colors
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    41