Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Administration functionalities #1784

Merged
merged 1 commit into from
Feb 6, 2017

Conversation

morteza-araby
Copy link
Contributor

1- Get Request to get list of users for administrator
2- Post request to reset password for users
3 - Get Request to get a paginated users With start and limit.
4 - Search users from database and return an array of found users or empty

@matrixbot
Copy link
Member

Can one of the admins verify this patch?

2 similar comments
@matrixbot
Copy link
Member

Can one of the admins verify this patch?

@matrixbot
Copy link
Member

Can one of the admins verify this patch?

@erikjohnston
Copy link
Member

@matrixbot ok to test

@erikjohnston
Copy link
Member

There's a bunch of PEP8 violations:

synapse/handlers/admin.py:22:1: F401 'operator.attrgetter' imported but unused
synapse/rest/client/v1/admin.py:40:9: F841 local variable 'auth_user' is assigned to but never used
synapse/rest/client/v1/admin.py:57:1: E302 expected 2 blank lines, found 1
synapse/rest/client/v1/admin.py:159:1: E302 expected 2 blank lines, found 1
synapse/rest/client/v1/admin.py:190:1: E302 expected 2 blank lines, found 1
synapse/rest/client/v1/admin.py:204:9: F841 local variable 'auth_user' is assigned to but never used
synapse/rest/client/v1/admin.py:253:1: E302 expected 2 blank lines, found 1
synapse/rest/client/v1/admin.py:290:1: E302 expected 2 blank lines, found 1
synapse/storage/_base.py:931:37: E128 continuation line under-indented for visual indent
synapse/storage/_base.py:951:91: E501 line too long (92 > 90 characters)
synapse/storage/_base.py:953:91: E501 line too long (93 > 90 characters)
synapse/storage/_base.py:973:91: E501 line too long (92 > 90 characters)
synapse/storage/_base.py:1039:1: E303 too many blank lines (3)

You should be able to test locally by installing flake8 and then running flake8 synapse/

Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

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

This broadly looks good. If you can just add some docstring to:

  • the functions in the handler and storage
  • the classes in the rest layer explaining what they do

raise SynapseError(400, "Missing 'limit' arg")
if not start:
raise SynapseError(400, "Missing 'start' arg")
logger.info("limit: %s, start: %s", limit, start)
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be debug level logging.

raise SynapseError(400, "Missing 'limit' arg")
if not start:
raise SynapseError(400, "Missing 'start' arg")
logger.info("limit: %s, start: %s", limit, start)
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be debug level logging.

if not term:
raise SynapseError(400, "Missing 'term' arg")

logger.info("term: %s ", term)
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be debug level logging.

@@ -284,6 +284,48 @@ def get_user_ip_and_agents(self, user):
desc="get_user_ip_and_agents",
)

def get_users(self, user):
Copy link
Member

Choose a reason for hiding this comment

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

Why does this take a user param?

def get_users_paginate(self, user, start, limit):
ret = yield self.store.get_users_paginate(user, start, limit)

defer.returnValue(ret)
Copy link
Member

Choose a reason for hiding this comment

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

These functions can simply be rewritten as:

def get_users_paginate(self, user, start, limit):
    return self.store.get_users_paginate(user, start, limit)

url = 'http://localhost:8008/_matrix/client/api/v1/register'
post_data = {'user': 'admin',
'password': 'admin123',
'type': 'm.login.password'}
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit hesitant to add example scripts like this, as they can't directly be run. I believe the register_new_user script actually has an option to specify the new user is an admin or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,
Made a new commit.
1- Fix all error from flake8
2- add docstring to all the new methods
3 - Used _simple_select_list_paginate as private method which is more generic to use for other list search as well and used get_user_list_paginate for calling from rest api

@erikjohnston
Copy link
Member

(The sytest dendron failure is probably spurious, ignore it)

@morteza-araby
Copy link
Contributor Author

morteza-araby commented Jan 21, 2017 via email

administrators can now:
 - Set displayname of users
 - Update user avatars
 - Search for users by user_id
 - Browse all users in a paginated API
 - Reset user passwords
 - Deactivate users

Helpers for doing paginated queries has also been added to storage

Signed-off-by: Morteza Araby <morteza.araby@ericsson.com>
@erikjohnston erikjohnston merged commit af6da6d into matrix-org:develop Feb 6, 2017
erikjohnston added a commit that referenced this pull request Mar 13, 2017
Changes in synapse v0.19.3-rc1 (2017-03-08)
===========================================

Features:

* Add some administration functionalities. Thanks to morteza-araby! (PR #1784)

Changes:

* Reduce database table sizes (PR #1873, #1916, #1923, #1963)
* Update contrib/ to not use syutil. Thanks to andrewshadura! (PR #1907)
* Don't fetch current state when sending an event in common case (PR #1955)

Bug fixes:

* Fix synapse_port_db failure. Thanks to Pneumaticat! (PR #1904)
* Fix caching to not cache error responses (PR #1913)
* Fix APIs to make kick & ban reasons work (PR #1917)
* Fix bugs in the /keys/changes api (PR #1921)
* Fix bug where users couldn't forget rooms they were banned from (PR #1922)
* Fix issue with long language values in pushers API (PR #1925)
* Fix a race in transaction queue (PR #1930)
* Fix dynamic thumbnailing to preserve aspect ratio. Thanks to jkolo! (PR
  #1945)
* Fix device list update to not constantly resync (PR #1964)
* Fix potential for huge memory usage when getting device that have
  changed (PR #1969)
@richvdh
Copy link
Member

richvdh commented Mar 22, 2017

It'd be nice if someone could write something in https://github.com/matrix-org/synapse/tree/master/docs/admin_api about this.

@jcgruenhage
Copy link
Contributor

Also, it would be great if the swagger ui supported this.

@richvdh
Copy link
Member

richvdh commented Mar 22, 2017

The swagger spec is limited to the client-server API. These APIs are synapse-specific.

Of course, you could give them a swagger UI, but it wouldn't be appropriate to include them in the current one.

@jcgruenhage
Copy link
Contributor

It would probably be more appropriate to write a little synapse admin client instead
(Or maybe even a web interface for those :D)

@@ -25,6 +26,34 @@
logger = logging.getLogger(__name__)


class UsersRestServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/admin/users/(?P<user_id>[^/]*)")
Copy link
Member

Choose a reason for hiding this comment

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

is my understanding correct? this takes a user_id, and then ignores it? @morteza-araby

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, I must have missed that. The UsersRest Api, has not been used at my client side implementation and I think that's why I've missed all of your comments here. Probably should have wrote some test cases.

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 now tracked as #2522

# raise AuthError(403, "You are not a server admin")

if not self.hs.is_mine(target_user):
raise SynapseError(400, "Can only users a local user")
Copy link
Member

Choose a reason for hiding this comment

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

this error makes no sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right.

if not new_password:
raise SynapseError(400, "Missing 'new_password' arg")

logger.info("new_password: %r", new_password)
Copy link
Member

Choose a reason for hiding this comment

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

we really shouldn't log passwords at info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be removed.

Copy link
Member

Choose a reason for hiding this comment

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

yes it should...

Copy link
Member

Choose a reason for hiding this comment

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

this finally got fixed by #4965

richvdh added a commit that referenced this pull request Apr 20, 2017
I haven't (yet) documented all of the user-list APIs introduced in
#1784 because the API shape seems
very odd, given the functionality.
richvdh added a commit that referenced this pull request Apr 21, 2017
I haven't (yet) documented all of the user-list APIs introduced in
#1784 because the API shape seems
very odd, given the functionality.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants