Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose user avatar URL field in the UI #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jeena
Copy link

@jeena jeena commented Aug 4, 2020

To be able to change a avatar the URL field needs to be exposed but changing the URL alone is difficult. This patch adds a image upload field to the edit view of a user. If there is a file detected it uploads it to the servers media repository and sets that new URL as the avatar URL one. This way a admin can change any users avatar which is especially nice for bridged users like in the IRC bridge and bots.

avatar-synapse-admin

Fixes #60

To be able to change a avatar the URL field needs to be exposed but
changing the URL alone is difficult. This patch adds a image upload
field to the edit view of a user. If there is a file detected it
uploads it to the servers media repository and sets that new URL
as the avatar URL one. This way a admin can change any users avatar
which is especially nice for bridged users like in the IRC bridge
and bots.
Copy link
Member

@awesome-manuel awesome-manuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comments.

@@ -32,6 +32,7 @@ const resourceMap = {
...u,
id: u.name,
avatar_src: mxcUrlToHttp(u.avatar_url),
avatar_url: u.avatar_url,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implicitly handled by line 32

Comment on lines +206 to +230

// In case there is a avatar_file object, save it in the media repository
// and update the avatar_url.
const f = params?.data?.avatar_file?.rawFile;
if (f instanceof File) {
const file_endpoint =
homeserver + "/_matrix/media/r0/upload?filename=" + f.name;
const headers = new Headers();
headers.append("Content-Type", f.type);
const options = {
method: "POST",
body: f,
headers: headers,
};
return jsonClient(file_endpoint, options).then(r => {
params.data.avatar_url = r.json.content_uri;

return jsonClient(`${endpoint_url}/${params.data.id}`, {
method: "PUT",
body: JSON.stringify(params.data, filterNullValues),
}).then(({ json }) => ({
data: res.map(json),
}));
});
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the update function pretty complicated. I suggest to add another function upload to the DataProvider and use it directly in the UserEdit component (https://marmelab.com/react-admin/Actions.html#usedataprovider-hook). Then you can upload the file directly when it's selected and provide appropriate feedback (e.g. file is too large).

@awesome-manuel awesome-manuel added the enhancement New feature or request label Apr 21, 2021
@awesome-manuel awesome-manuel added the help wanted Extra attention is needed label Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it possible to change a users avatar
2 participants