Commit ba15a2b1 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Rename `authDomain` to `defaultAuthority` on store.session

Rename `authDomain` and extend comments to clarify
parent b1ce8485
......@@ -53,10 +53,10 @@ function AnnotationHeader({
settings,
}) {
const store = useStoreProxy();
const authDomain = store.authDomain();
const defaultAuthority = store.defaultAuthority();
const displayNamesEnabled = store.isFeatureEnabled('client_display_names');
const isThirdParty = isThirdPartyUser(annotation.user, authDomain);
const isThirdParty = isThirdPartyUser(annotation.user, defaultAuthority);
const authorDisplayName = annotationDisplayName(
annotation,
isThirdParty,
......
......@@ -51,7 +51,7 @@ describe('AnnotationHeader', () => {
fakeSettings = { usernameUrl: 'http://foo.bar/' };
fakeStore = {
authDomain: sinon.stub().returns('foo.com'),
defaultAuthority: sinon.stub().returns('foo.com'),
isFeatureEnabled: sinon.stub().returns(false),
route: sinon.stub().returns('sidebar'),
setExpanded: sinon.stub(),
......
......@@ -52,7 +52,7 @@ describe('sidebar/components/hooks/use-user-filter-options', () => {
fakeStore = {
allAnnotations: sinon.stub().returns([]),
authDomain: sinon.stub().returns('foo.com'),
defaultAuthority: sinon.stub().returns('foo.com'),
getFocusFilters: sinon.stub().returns({}),
isFeatureEnabled: sinon.stub().returns(false),
profile: sinon.stub().returns({}),
......
......@@ -15,7 +15,7 @@ import { annotationDisplayName } from '../../helpers/annotation-user';
export function useUserFilterOptions() {
const store = useStoreProxy();
const annotations = store.allAnnotations();
const authDomain = store.authDomain();
const defaultAuthority = store.defaultAuthority();
const displayNamesEnabled = store.isFeatureEnabled('client_display_names');
const focusFilters = store.getFocusFilters();
const currentUsername = username(store.profile().userid);
......@@ -27,7 +27,7 @@ export function useUserFilterOptions() {
const username_ = username(annotation.user);
users[username_] = annotationDisplayName(
annotation,
isThirdPartyUser(annotation.user, authDomain),
isThirdPartyUser(annotation.user, defaultAuthority),
displayNamesEnabled
);
});
......@@ -64,8 +64,8 @@ export function useUserFilterOptions() {
return userOptions;
}, [
annotations,
authDomain,
currentUsername,
defaultAuthority,
displayNamesEnabled,
focusFilters.user,
]);
......
......@@ -31,17 +31,19 @@ export function username(user) {
}
/**
* Returns true if the authority is of a 3rd party user.
* Returns true if the user's provider (authority) differs from the default
* authority for the application.
*
* @param {string} user
* @param {string} authDomain
* @param {string} defaultAuthority - The application's default authority
* (user identity provider)
*/
export function isThirdPartyUser(user, authDomain) {
export function isThirdPartyUser(user, defaultAuthority) {
const account = parseAccountID(user);
if (!account) {
return false;
}
return account.provider !== authDomain;
return account.provider !== defaultAuthority;
}
......@@ -26,13 +26,14 @@ const initialProfile = {
function init(settings) {
return {
/**
* The app's authentication domain, from settings
* The app's default authority (user identity provider), from settings,
* e.g. `hypothes.is` or `localhost`
* FIXME: This returns an empty string when `authDomain` is missing
* because other app logic has long assumed its string-y presence:
* behavior when it's missing is undefined. This setting should be
* enforced similarly to how `apiUrl` is enforced.
*/
authDomain: settings?.authDomain ?? '',
defaultAuthority: settings?.authDomain ?? '',
/**
* Profile object fetched from the `/api/profile` endpoint.
*/
......@@ -62,10 +63,10 @@ function updateProfile(profile) {
/**
*
* @returns {string}
* @return {string}
*/
function authDomain(state) {
return state.authDomain;
function defaultAuthority(state) {
return state.defaultAuthority;
}
/**
......@@ -119,7 +120,7 @@ export default storeModule({
},
selectors: {
authDomain,
defaultAuthority,
hasFetchedProfile,
isFeatureEnabled,
isLoggedIn,
......
......@@ -18,12 +18,12 @@ describe('sidebar/store/modules/session', () => {
});
});
describe('#authDomain', () => {
it('returns the authDomain from the settings', () => {
describe('#defaultAuthority', () => {
it('returns the default authority from the settings', () => {
fakeSettings.authDomain = 'foo.com';
store = createStore([session], [fakeSettings]);
assert.equal(store.authDomain(), 'foo.com');
assert.equal(store.defaultAuthority(), 'foo.com');
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment