[FIX] App always sends auth for Avatar requests (#2517)
* [FIX] Sending auth for Avatar requests when not necessary * fix storybook * Fix ShareListView not updating avatars Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
52850cbccc
commit
857707fc61
|
@ -18,6 +18,7 @@ export const LOGIN = createRequestTypes('LOGIN', [
|
||||||
export const SHARE = createRequestTypes('SHARE', [
|
export const SHARE = createRequestTypes('SHARE', [
|
||||||
'SELECT_SERVER',
|
'SELECT_SERVER',
|
||||||
'SET_USER',
|
'SET_USER',
|
||||||
|
'SET_SETTINGS',
|
||||||
'SET_SERVER_INFO'
|
'SET_SERVER_INFO'
|
||||||
]);
|
]);
|
||||||
export const USER = createRequestTypes('USER', ['SET']);
|
export const USER = createRequestTypes('USER', ['SET']);
|
||||||
|
|
|
@ -7,6 +7,13 @@ export function shareSelectServer(server) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shareSetSettings(settings) {
|
||||||
|
return {
|
||||||
|
type: SHARE.SET_SETTINGS,
|
||||||
|
settings
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function shareSetUser(user) {
|
export function shareSetUser(user) {
|
||||||
return {
|
return {
|
||||||
type: SHARE.SET_USER,
|
type: SHARE.SET_USER,
|
||||||
|
|
|
@ -20,6 +20,9 @@ export default {
|
||||||
Accounts_AllowUsernameChange: {
|
Accounts_AllowUsernameChange: {
|
||||||
type: 'valueAsBoolean'
|
type: 'valueAsBoolean'
|
||||||
},
|
},
|
||||||
|
Accounts_AvatarBlockUnauthenticatedAccess: {
|
||||||
|
type: 'valueAsBoolean'
|
||||||
|
},
|
||||||
Accounts_CustomFields: {
|
Accounts_CustomFields: {
|
||||||
type: 'valueAsString'
|
type: 'valueAsString'
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,7 +24,8 @@ const Avatar = React.memo(({
|
||||||
getCustomEmoji,
|
getCustomEmoji,
|
||||||
avatarETag,
|
avatarETag,
|
||||||
isStatic,
|
isStatic,
|
||||||
rid
|
rid,
|
||||||
|
blockUnauthenticatedAccess
|
||||||
}) => {
|
}) => {
|
||||||
if ((!text && !avatar && !emoji && !rid) || !server) {
|
if ((!text && !avatar && !emoji && !rid) || !server) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -59,7 +60,8 @@ const Avatar = React.memo(({
|
||||||
avatar,
|
avatar,
|
||||||
server,
|
server,
|
||||||
avatarETag,
|
avatarETag,
|
||||||
rid
|
rid,
|
||||||
|
blockUnauthenticatedAccess
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +113,8 @@ Avatar.propTypes = {
|
||||||
getCustomEmoji: PropTypes.func,
|
getCustomEmoji: PropTypes.func,
|
||||||
avatarETag: PropTypes.string,
|
avatarETag: PropTypes.string,
|
||||||
isStatic: PropTypes.bool,
|
isStatic: PropTypes.bool,
|
||||||
rid: PropTypes.string
|
rid: PropTypes.string,
|
||||||
|
blockUnauthenticatedAccess: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
Avatar.defaultProps = {
|
Avatar.defaultProps = {
|
||||||
|
|
|
@ -12,7 +12,8 @@ class AvatarContainer extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
rid: PropTypes.string,
|
rid: PropTypes.string,
|
||||||
text: PropTypes.string,
|
text: PropTypes.string,
|
||||||
type: PropTypes.string
|
type: PropTypes.string,
|
||||||
|
blockUnauthenticatedAccess: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
|
@ -93,6 +94,10 @@ class AvatarContainer extends React.Component {
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
user: getUserSelector(state),
|
user: getUserSelector(state),
|
||||||
server: state.share.server || state.server.server
|
server: state.share.server || state.server.server,
|
||||||
|
blockUnauthenticatedAccess:
|
||||||
|
state.share.settings?.Accounts_AvatarBlockUnauthenticatedAccess
|
||||||
|
?? state.settings.Accounts_AvatarBlockUnauthenticatedAccess
|
||||||
|
?? true
|
||||||
});
|
});
|
||||||
export default connect(mapStateToProps)(AvatarContainer);
|
export default connect(mapStateToProps)(AvatarContainer);
|
||||||
|
|
|
@ -116,6 +116,7 @@ class DB {
|
||||||
Permission,
|
Permission,
|
||||||
CustomEmoji,
|
CustomEmoji,
|
||||||
FrequentlyUsedEmoji,
|
FrequentlyUsedEmoji,
|
||||||
|
Setting,
|
||||||
User
|
User
|
||||||
],
|
],
|
||||||
actionsEnabled: true
|
actionsEnabled: true
|
||||||
|
|
|
@ -19,9 +19,7 @@ import fetch from '../utils/fetch';
|
||||||
import { encryptionInit } from '../actions/encryption';
|
import { encryptionInit } from '../actions/encryption';
|
||||||
import { setUser, setLoginServices, loginRequest } from '../actions/login';
|
import { setUser, setLoginServices, loginRequest } from '../actions/login';
|
||||||
import { disconnect, connectSuccess, connectRequest } from '../actions/connect';
|
import { disconnect, connectSuccess, connectRequest } from '../actions/connect';
|
||||||
import {
|
import { shareSelectServer, shareSetUser, shareSetSettings } from '../actions/share';
|
||||||
shareSelectServer, shareSetUser
|
|
||||||
} from '../actions/share';
|
|
||||||
|
|
||||||
import subscribeRooms from './methods/subscriptions/rooms';
|
import subscribeRooms from './methods/subscriptions/rooms';
|
||||||
import getUsersPresence, { getUserPresence, subscribeUsersPresence } from './methods/getUsersPresence';
|
import getUsersPresence, { getUserPresence, subscribeUsersPresence } from './methods/getUsersPresence';
|
||||||
|
@ -324,8 +322,23 @@ const RocketChat = {
|
||||||
|
|
||||||
RocketChat.setCustomEmojis();
|
RocketChat.setCustomEmojis();
|
||||||
|
|
||||||
// set User info
|
|
||||||
try {
|
try {
|
||||||
|
// set Settings
|
||||||
|
const settings = ['Accounts_AvatarBlockUnauthenticatedAccess'];
|
||||||
|
const db = database.active;
|
||||||
|
const settingsCollection = db.collections.get('settings');
|
||||||
|
const settingsRecords = await settingsCollection.query(Q.where('id', Q.oneOf(settings))).fetch();
|
||||||
|
const parsed = Object.values(settingsRecords).map(item => ({
|
||||||
|
_id: item.id,
|
||||||
|
valueAsString: item.valueAsString,
|
||||||
|
valueAsBoolean: item.valueAsBoolean,
|
||||||
|
valueAsNumber: item.valueAsNumber,
|
||||||
|
valueAsArray: item.valueAsArray,
|
||||||
|
_updatedAt: item._updatedAt
|
||||||
|
}));
|
||||||
|
reduxStore.dispatch(shareSetSettings(this.parseSettings(parsed)));
|
||||||
|
|
||||||
|
// set User info
|
||||||
const userId = await UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`);
|
const userId = await UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`);
|
||||||
const userCollections = serversDB.collections.get('users');
|
const userCollections = serversDB.collections.get('users');
|
||||||
let user = null;
|
let user = null;
|
||||||
|
@ -353,6 +366,7 @@ const RocketChat = {
|
||||||
database.share = null;
|
database.share = null;
|
||||||
|
|
||||||
reduxStore.dispatch(shareSetUser({}));
|
reduxStore.dispatch(shareSetUser({}));
|
||||||
|
reduxStore.dispatch(shareSetSettings({}));
|
||||||
},
|
},
|
||||||
|
|
||||||
async e2eFetchMyKeys() {
|
async e2eFetchMyKeys() {
|
||||||
|
|
|
@ -2,7 +2,8 @@ import { SHARE } from '../actions/actionsTypes';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
user: {},
|
user: {},
|
||||||
server: ''
|
server: '',
|
||||||
|
settings: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function share(state = initialState, action) {
|
export default function share(state = initialState, action) {
|
||||||
|
@ -17,6 +18,11 @@ export default function share(state = initialState, action) {
|
||||||
...state,
|
...state,
|
||||||
user: action.user
|
user: action.user
|
||||||
};
|
};
|
||||||
|
case SHARE.SET_SETTINGS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
settings: action.settings
|
||||||
|
};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const formatUrl = (url, size, query) => `${ url }?format=png&size=${ size }${ query }`;
|
const formatUrl = (url, size, query) => `${ url }?format=png&size=${ size }${ query }`;
|
||||||
|
|
||||||
export const avatarURL = ({
|
export const avatarURL = ({
|
||||||
type, text, size, user = {}, avatar, server, avatarETag, rid
|
type, text, size, user = {}, avatar, server, avatarETag, rid, blockUnauthenticatedAccess
|
||||||
}) => {
|
}) => {
|
||||||
let room;
|
let room;
|
||||||
if (type === 'd') {
|
if (type === 'd') {
|
||||||
|
@ -16,7 +16,7 @@ export const avatarURL = ({
|
||||||
|
|
||||||
const { id, token } = user;
|
const { id, token } = user;
|
||||||
let query = '';
|
let query = '';
|
||||||
if (id && token) {
|
if (id && token && blockUnauthenticatedAccess) {
|
||||||
query += `&rc_token=${ token }&rc_uid=${ id }`;
|
query += `&rc_token=${ token }&rc_uid=${ id }`;
|
||||||
}
|
}
|
||||||
if (avatarETag) {
|
if (avatarETag) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { themes } from '../../constants/colors';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
|
|
||||||
const SelectChannel = ({
|
const SelectChannel = ({
|
||||||
server, token, userId, onChannelSelect, initial, theme
|
server, token, userId, onChannelSelect, initial, blockUnauthenticatedAccess, theme
|
||||||
}) => {
|
}) => {
|
||||||
const [channels, setChannels] = useState([]);
|
const [channels, setChannels] = useState([]);
|
||||||
|
|
||||||
|
@ -31,7 +31,8 @@ const SelectChannel = ({
|
||||||
user: { id: userId, token },
|
user: { id: userId, token },
|
||||||
server,
|
server,
|
||||||
avatarETag: item.avatarETag,
|
avatarETag: item.avatarETag,
|
||||||
rid: item.rid
|
rid: item.rid,
|
||||||
|
blockUnauthenticatedAccess
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -61,6 +62,7 @@ SelectChannel.propTypes = {
|
||||||
userId: PropTypes.string,
|
userId: PropTypes.string,
|
||||||
initial: PropTypes.object,
|
initial: PropTypes.object,
|
||||||
onChannelSelect: PropTypes.func,
|
onChannelSelect: PropTypes.func,
|
||||||
|
blockUnauthenticatedAccess: PropTypes.bool,
|
||||||
theme: PropTypes.string
|
theme: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import styles from './styles';
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
|
|
||||||
const SelectUsers = ({
|
const SelectUsers = ({
|
||||||
server, token, userId, selected, onUserSelect, theme
|
server, token, userId, selected, onUserSelect, blockUnauthenticatedAccess, theme
|
||||||
}) => {
|
}) => {
|
||||||
const [users, setUsers] = useState([]);
|
const [users, setUsers] = useState([]);
|
||||||
|
|
||||||
|
@ -48,7 +48,12 @@ const SelectUsers = ({
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
const getAvatar = item => avatarURL({
|
const getAvatar = item => avatarURL({
|
||||||
text: RocketChat.getRoomAvatar(item), type: 'd', user: { id: userId, token }, server, avatarETag: item.avatarETag
|
text: RocketChat.getRoomAvatar(item),
|
||||||
|
type: 'd',
|
||||||
|
user: { id: userId, token },
|
||||||
|
server,
|
||||||
|
avatarETag: item.avatarETag,
|
||||||
|
blockUnauthenticatedAccess
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -78,6 +83,7 @@ SelectUsers.propTypes = {
|
||||||
userId: PropTypes.string,
|
userId: PropTypes.string,
|
||||||
selected: PropTypes.array,
|
selected: PropTypes.array,
|
||||||
onUserSelect: PropTypes.func,
|
onUserSelect: PropTypes.func,
|
||||||
|
blockUnauthenticatedAccess: PropTypes.bool,
|
||||||
theme: PropTypes.string
|
theme: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@ class CreateChannelView extends React.Component {
|
||||||
failure: PropTypes.bool,
|
failure: PropTypes.bool,
|
||||||
error: PropTypes.object,
|
error: PropTypes.object,
|
||||||
theme: PropTypes.string,
|
theme: PropTypes.string,
|
||||||
isMasterDetail: PropTypes.bool
|
isMasterDetail: PropTypes.bool,
|
||||||
|
blockUnauthenticatedAccess: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -143,7 +144,7 @@ class CreateChannelView extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
const { name, users } = this.state;
|
const { name, users } = this.state;
|
||||||
const {
|
const {
|
||||||
server, user, loading, theme
|
server, user, loading, blockUnauthenticatedAccess, theme
|
||||||
} = this.props;
|
} = this.props;
|
||||||
return (
|
return (
|
||||||
<KeyboardView
|
<KeyboardView
|
||||||
|
@ -161,6 +162,7 @@ class CreateChannelView extends React.Component {
|
||||||
token={user.token}
|
token={user.token}
|
||||||
initial={this.channel && { text: RocketChat.getRoomTitle(this.channel) }}
|
initial={this.channel && { text: RocketChat.getRoomTitle(this.channel) }}
|
||||||
onChannelSelect={this.selectChannel}
|
onChannelSelect={this.selectChannel}
|
||||||
|
blockUnauthenticatedAccess={blockUnauthenticatedAccess}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
|
@ -177,6 +179,7 @@ class CreateChannelView extends React.Component {
|
||||||
token={user.token}
|
token={user.token}
|
||||||
selected={users}
|
selected={users}
|
||||||
onUserSelect={this.selectUsers}
|
onUserSelect={this.selectUsers}
|
||||||
|
blockUnauthenticatedAccess={blockUnauthenticatedAccess}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
|
@ -203,6 +206,7 @@ const mapStateToProps = state => ({
|
||||||
failure: state.createDiscussion.failure,
|
failure: state.createDiscussion.failure,
|
||||||
loading: state.createDiscussion.isFetching,
|
loading: state.createDiscussion.isFetching,
|
||||||
result: state.createDiscussion.result,
|
result: state.createDiscussion.result,
|
||||||
|
blockUnauthenticatedAccess: state.settings.Accounts_AvatarBlockUnauthenticatedAccess ?? true,
|
||||||
isMasterDetail: state.app.isMasterDetail
|
isMasterDetail: state.app.isMasterDetail
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -108,10 +108,13 @@ class ShareListView extends React.Component {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { server, theme } = this.props;
|
const { server, theme, userId } = this.props;
|
||||||
if (server !== nextProps.server) {
|
if (server !== nextProps.server) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (userId !== nextProps.userId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (theme !== nextProps.theme) {
|
if (theme !== nextProps.theme) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ const reducers = combineReducers({
|
||||||
username: 'diego.mello'
|
username: 'diego.mello'
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
share: () => ({ settings: {} }),
|
||||||
meteor: () => ({ connected: true }),
|
meteor: () => ({ connected: true }),
|
||||||
activeUsers: () => ({ abc: { status: 'online', statusText: 'dog' } })
|
activeUsers: () => ({ abc: { status: 'online', statusText: 'dog' } })
|
||||||
});
|
});
|
||||||
|
@ -61,6 +62,7 @@ storiesOf('RoomItem', module)
|
||||||
.addDecorator(story => <Provider store={store}>{story()}</Provider>)
|
.addDecorator(story => <Provider store={store}>{story()}</Provider>)
|
||||||
.add('list roomitem', () => <RoomItem theme={theme} />);
|
.add('list roomitem', () => <RoomItem theme={theme} />);
|
||||||
storiesOf('Message', module)
|
storiesOf('Message', module)
|
||||||
|
.addDecorator(story => <Provider store={store}>{story()}</Provider>)
|
||||||
.addDecorator(messageDecorator)
|
.addDecorator(messageDecorator)
|
||||||
.add('list message', () => <Message theme={theme} />);
|
.add('list message', () => <Message theme={theme} />);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue