-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This partly reverts commit 5a8465a.
- Loading branch information
1 parent
87b420f
commit 0a59abc
Showing
8 changed files
with
33 additions
and
59 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
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,44 +1,21 @@ | ||
import { constant } from 'lodash'; | ||
|
||
import User from '../common-user/user-model'; | ||
import userChannel from '../common-user/user-radio'; | ||
import { staff } from '../common-rdf/ns'; | ||
import Model from '../core/model'; | ||
|
||
const user = new User(); | ||
let promise: PromiseLike<Model> = null; | ||
const returnUser = constant(user); | ||
const promise = user.fetch().then(returnUser); | ||
|
||
function getUserURI() { | ||
return fetchUser().then( () => { | ||
const username = user.get('username'); | ||
if (username) return staff(username); | ||
}) | ||
} | ||
|
||
function getPermission(permission: string) { | ||
return fetchUser().then( () => { | ||
return user.hasPermission(permission); | ||
}) | ||
} | ||
|
||
function fetchUser() { | ||
if (!promise) { | ||
promise = user.fetch().then(resolveUser, rejectUser); | ||
} | ||
return promise; | ||
} | ||
|
||
function resolveUser(): User { | ||
promise = Promise.resolve(user); | ||
return user; | ||
} | ||
|
||
function rejectUser(error) { | ||
promise = Promise.reject(error); | ||
return error; | ||
const username = user.get('username'); | ||
if (username) return staff(username); | ||
} | ||
|
||
userChannel.once('cache', fetchUser); | ||
userChannel.reply('user', fetchUser); | ||
userChannel.reply('user', returnUser); | ||
userChannel.reply('promise', constant(promise)); | ||
userChannel.reply('current-user-uri', getUserURI); | ||
userChannel.reply('permission', getPermission); | ||
userChannel.reply('permission', user.hasPermission, user); | ||
|
||
export default user; |
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