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({ ...@@ -53,10 +53,10 @@ function AnnotationHeader({
settings, settings,
}) { }) {
const store = useStoreProxy(); const store = useStoreProxy();
const authDomain = store.authDomain(); const defaultAuthority = store.defaultAuthority();
const displayNamesEnabled = store.isFeatureEnabled('client_display_names'); const displayNamesEnabled = store.isFeatureEnabled('client_display_names');
const isThirdParty = isThirdPartyUser(annotation.user, authDomain); const isThirdParty = isThirdPartyUser(annotation.user, defaultAuthority);
const authorDisplayName = annotationDisplayName( const authorDisplayName = annotationDisplayName(
annotation, annotation,
isThirdParty, isThirdParty,
......
...@@ -51,7 +51,7 @@ describe('AnnotationHeader', () => { ...@@ -51,7 +51,7 @@ describe('AnnotationHeader', () => {
fakeSettings = { usernameUrl: 'http://foo.bar/' }; fakeSettings = { usernameUrl: 'http://foo.bar/' };
fakeStore = { fakeStore = {
authDomain: sinon.stub().returns('foo.com'), defaultAuthority: sinon.stub().returns('foo.com'),
isFeatureEnabled: sinon.stub().returns(false), isFeatureEnabled: sinon.stub().returns(false),
route: sinon.stub().returns('sidebar'), route: sinon.stub().returns('sidebar'),
setExpanded: sinon.stub(), setExpanded: sinon.stub(),
......
...@@ -52,7 +52,7 @@ describe('sidebar/components/hooks/use-user-filter-options', () => { ...@@ -52,7 +52,7 @@ describe('sidebar/components/hooks/use-user-filter-options', () => {
fakeStore = { fakeStore = {
allAnnotations: sinon.stub().returns([]), allAnnotations: sinon.stub().returns([]),
authDomain: sinon.stub().returns('foo.com'), defaultAuthority: sinon.stub().returns('foo.com'),
getFocusFilters: sinon.stub().returns({}), getFocusFilters: sinon.stub().returns({}),
isFeatureEnabled: sinon.stub().returns(false), isFeatureEnabled: sinon.stub().returns(false),
profile: sinon.stub().returns({}), profile: sinon.stub().returns({}),
......
...@@ -15,7 +15,7 @@ import { annotationDisplayName } from '../../helpers/annotation-user'; ...@@ -15,7 +15,7 @@ import { annotationDisplayName } from '../../helpers/annotation-user';
export function useUserFilterOptions() { export function useUserFilterOptions() {
const store = useStoreProxy(); const store = useStoreProxy();
const annotations = store.allAnnotations(); const annotations = store.allAnnotations();
const authDomain = store.authDomain(); const defaultAuthority = store.defaultAuthority();
const displayNamesEnabled = store.isFeatureEnabled('client_display_names'); const displayNamesEnabled = store.isFeatureEnabled('client_display_names');
const focusFilters = store.getFocusFilters(); const focusFilters = store.getFocusFilters();
const currentUsername = username(store.profile().userid); const currentUsername = username(store.profile().userid);
...@@ -27,7 +27,7 @@ export function useUserFilterOptions() { ...@@ -27,7 +27,7 @@ export function useUserFilterOptions() {
const username_ = username(annotation.user); const username_ = username(annotation.user);
users[username_] = annotationDisplayName( users[username_] = annotationDisplayName(
annotation, annotation,
isThirdPartyUser(annotation.user, authDomain), isThirdPartyUser(annotation.user, defaultAuthority),
displayNamesEnabled displayNamesEnabled
); );
}); });
...@@ -64,8 +64,8 @@ export function useUserFilterOptions() { ...@@ -64,8 +64,8 @@ export function useUserFilterOptions() {
return userOptions; return userOptions;
}, [ }, [
annotations, annotations,
authDomain,
currentUsername, currentUsername,
defaultAuthority,
displayNamesEnabled, displayNamesEnabled,
focusFilters.user, focusFilters.user,
]); ]);
......
...@@ -31,17 +31,19 @@ export function username(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} 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); const account = parseAccountID(user);
if (!account) { if (!account) {
return false; return false;
} }
return account.provider !== authDomain; return account.provider !== defaultAuthority;
} }
...@@ -26,13 +26,14 @@ const initialProfile = { ...@@ -26,13 +26,14 @@ const initialProfile = {
function init(settings) { function init(settings) {
return { 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 * FIXME: This returns an empty string when `authDomain` is missing
* because other app logic has long assumed its string-y presence: * because other app logic has long assumed its string-y presence:
* behavior when it's missing is undefined. This setting should be * behavior when it's missing is undefined. This setting should be
* enforced similarly to how `apiUrl` is enforced. * enforced similarly to how `apiUrl` is enforced.
*/ */
authDomain: settings?.authDomain ?? '', defaultAuthority: settings?.authDomain ?? '',
/** /**
* Profile object fetched from the `/api/profile` endpoint. * Profile object fetched from the `/api/profile` endpoint.
*/ */
...@@ -62,10 +63,10 @@ function updateProfile(profile) { ...@@ -62,10 +63,10 @@ function updateProfile(profile) {
/** /**
* *
* @returns {string} * @return {string}
*/ */
function authDomain(state) { function defaultAuthority(state) {
return state.authDomain; return state.defaultAuthority;
} }
/** /**
...@@ -119,7 +120,7 @@ export default storeModule({ ...@@ -119,7 +120,7 @@ export default storeModule({
}, },
selectors: { selectors: {
authDomain, defaultAuthority,
hasFetchedProfile, hasFetchedProfile,
isFeatureEnabled, isFeatureEnabled,
isLoggedIn, isLoggedIn,
......
...@@ -18,12 +18,12 @@ describe('sidebar/store/modules/session', () => { ...@@ -18,12 +18,12 @@ describe('sidebar/store/modules/session', () => {
}); });
}); });
describe('#authDomain', () => { describe('#defaultAuthority', () => {
it('returns the authDomain from the settings', () => { it('returns the default authority from the settings', () => {
fakeSettings.authDomain = 'foo.com'; fakeSettings.authDomain = 'foo.com';
store = createStore([session], [fakeSettings]); 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