Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Add basic implementation for the tags endpoint. #105
Conversation
This was referenced Oct 12, 2016
farodin91
changed the title from
[WIP] Add basic implementation for the tags endpoint.
to
Add basic implementation for the tags endpoint.
Oct 15, 2016
|
@jimmycuadra Review? |
|
I need to add an event |
|
This could done by different PR. It need to fix ruma/ruma-events#4, before this issue could resolve correct. |
farodin91
closed this
Oct 15, 2016
farodin91
reopened this
Oct 15, 2016
farodin91
added
status/needs review
and removed
status/work in progress
labels
Oct 16, 2016
| + | ||
| + // Check if the given user_id corresponds to the authenticated user. | ||
| + if user_id != user.id { | ||
| + Err(ApiError::unauthorized(None))?; |
mujx
Oct 17, 2016
Member
Could you add some useful error message instead of None? You can use this for this particular error, in order to be consistent.
| + room_id: RoomId, | ||
| + tag: String, | ||
| + content: Value) | ||
| + -> Result<(), ApiError> { |
mujx
Oct 17, 2016
Member
Until we use something like rustfmt it would be better to stick with the current style.
| + let user = request.extensions.get::<User>() | ||
| + .expect("AccessTokenAuth should ensure a user").clone(); | ||
| + let params = request.extensions.get::<Router>().expect("Params object is missing").clone(); | ||
| + let tag = match params.find("tag") { |
| + | ||
| + let mut content = String::new(); | ||
| + if let Err(_) = request.body.read_to_string(&mut content) { | ||
| + Err(ApiError::not_found(None))?; |
mujx
Oct 17, 2016
Member
You missed this one. Although synapse parses it as json, so you can skip this check and just add the JsonRequest middleware.
farodin91
Oct 17, 2016
Member
Resolved!
I think the json middleware could be refactored in the future.
| +use tags::RoomTag; | ||
| +use user::User; | ||
| + | ||
| +pub type MapTags = BTreeMap<String, Value>; |
farodin91
added
the
status/blocked
label
Dec 2, 2016
|
Waiting for #114 |
farodin91
added
status/work in progress
status/needs review
and removed
status/needs review
status/blocked
status/work in progress
labels
Dec 2, 2016
|
@jimmycuadra Could you start reviewing? Thanks |
| + fn handle(&self, request: &mut Request) -> IronResult<Response> { | ||
| + let user_id = request.extensions.get::<UserIdParam>() | ||
| + .expect("UserIdParam should ensure a UserId").clone(); | ||
| + let room_id = request.extensions.get::<RoomIdParam>() |
mujx
Dec 8, 2016
Member
You need to check that the room and user the exist before adding a tag. Also add the relevant tests. We don't have foreign keys so there will be no error.
| + #[test] | ||
| + fn basic_create_tag() { | ||
| + let test = Test::new(); | ||
| + let access_token = test.create_access_token(); // @carl:ruma.test |
mujx
Dec 8, 2016
Member
You can remove the comment by using the create_access_token_with_username("carl")
| + let room_id = test.create_public_room(&access_token); | ||
| + let put_tag_path = format!( | ||
| + "/_matrix/client/r0/user/{}/rooms/{}/tags/{}?access_token={}", | ||
| + "@carls:ruma.test", |
mujx
Dec 8, 2016
Member
Create another access token e.g alice. The user is not registered, so the action is not forbidden but the user id was not found.
| + } | ||
| + | ||
| + #[test] | ||
| + fn delete_tag_forbidden() { |
| + } | ||
| + | ||
| + #[test] | ||
| + fn update_tag() { |
mujx
Dec 8, 2016
Member
Sorry, my bad. Rename the helper function to put_tag so there is no confusion.
| + .filter(room_tags::user_id.eq(user_id)) | ||
| + .get_results(connection) | ||
| + .map_err(|err| match err { | ||
| + DieselError::NotFound => ApiError::not_found(None), |
| + map.insert(tag.tag, info); | ||
| + } | ||
| + | ||
| + let tags = TagEventContent { tags: map }; |
mujx
Dec 8, 2016
Member
Better use a custom TagsResponse in the api handler and here just return the hashmap.
| + user_id: UserId, | ||
| + room_id: RoomId, | ||
| + tag: String, | ||
| + content: Value, |
| + delete(tag) | ||
| + .execute(connection) | ||
| + .map_err(|err| match err { | ||
| + DieselError::NotFound => ApiError::not_found(None), |
jimmycuadra
merged commit fba8be9
into
ruma:master
Dec 21, 2016
1 check passed
|
Fantastic work. :D |
farodin91 commentedOct 12, 2016
No description provided.