From e8b6d7c946da5fb2ce5397bccfd332de8ca1f9dd Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 19 Oct 2010 20:54:53 -0700 Subject: Add support for an anonymous OAuth consumer. Note: this requires a small DB tweak. Oauth_application_user needs to have the primary compound key: (profile_id, application_id, token). http://status.net/open-source/issues/2761 This should also make it possible to have multiple access tokens per application. http://status.net/open-source/issues/2788 --- classes/Profile.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'classes/Profile.php') diff --git a/classes/Profile.php b/classes/Profile.php index 12ce5d9b6..a32051d07 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -401,10 +401,10 @@ class Profile extends Memcached_DataObject return $profile; } - function getApplications($offset = 0, $limit = null) + function getConnectedApps($offset = 0, $limit = null) { $qry = - 'SELECT a.* ' . + 'SELECT u.* ' . 'FROM oauth_application_user u, oauth_application a ' . 'WHERE u.profile_id = %d ' . 'AND a.id = u.application_id ' . @@ -419,11 +419,11 @@ class Profile extends Memcached_DataObject } } - $application = new Oauth_application(); + $apps = new Oauth_application_user(); - $cnt = $application->query(sprintf($qry, $this->id)); + $cnt = $apps->query(sprintf($qry, $this->id)); - return $application; + return $apps; } function subscriptionCount() -- cgit v1.2.3-54-g00ecf From 1d85bfece1ac3d6de3b4c350cbb617982e9d8638 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 22 Oct 2010 10:31:50 -0400 Subject: New events when granting and revoking roles Four new events for when roles are granted or revoked. --- EVENTS.txt | 16 +++++++++++++++ classes/Profile.php | 57 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 49 insertions(+), 24 deletions(-) (limited to 'classes/Profile.php') diff --git a/EVENTS.txt b/EVENTS.txt index e5cafa857..8e730945a 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1142,3 +1142,19 @@ StartShowNoticeForm: before showing the notice form (before
) EndShowNoticeForm: after showing the notice form (after ) - $action: action being executed + +StartGrantRole: when a role is being assigned +- $profile: profile that will have the role +- $role: string name of the role + +EndGrantRole: when a role has been successfully assigned +- $profile: profile that will have the role +- $role: string name of the role + +StartRevokeRole: when a role is being revoked +- $profile: profile that will lose the role +- $role: string name of the role + +EndRevokeRole: when a role has been revoked +- $profile: profile that lost the role +- $role: string name of the role diff --git a/classes/Profile.php b/classes/Profile.php index a32051d07..cb5ca54b0 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -758,43 +758,52 @@ class Profile extends Memcached_DataObject function grantRole($name) { - $role = new Profile_role(); + if (Event::handle('StartGrantRole', array($this, $name))) { - $role->profile_id = $this->id; - $role->role = $name; - $role->created = common_sql_now(); + $role = new Profile_role(); - $result = $role->insert(); + $role->profile_id = $this->id; + $role->role = $name; + $role->created = common_sql_now(); - if (!$result) { - common_log_db_error($role, 'INSERT', __FILE__); - return false; + $result = $role->insert(); + + if (!$result) { + throw new Exception("Can't save role '$name' for profile '{$this->id}'"); + } + + Event::handle('EndGrantRole', array($this, $name)); } - return true; + return $result; } function revokeRole($name) { - $role = Profile_role::pkeyGet(array('profile_id' => $this->id, - 'role' => $name)); + if (Event::handle('StartRevokeRole', array($this, $name))) { - if (empty($role)) { - // TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist. - // TRANS: %1$s is the role name, %2$s is the user ID (number). - throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),$name, $this->id)); - } + $role = Profile_role::pkeyGet(array('profile_id' => $this->id, + 'role' => $name)); - $result = $role->delete(); + if (empty($role)) { + // TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist. + // TRANS: %1$s is the role name, %2$s is the user ID (number). + throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),$name, $this->id)); + } - if (!$result) { - common_log_db_error($role, 'DELETE', __FILE__); - // TRANS: Exception thrown when trying to revoke a role for a user with a failing database query. - // TRANS: %1$s is the role name, %2$s is the user ID (number). - throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id)); - } + $result = $role->delete(); - return true; + if (!$result) { + common_log_db_error($role, 'DELETE', __FILE__); + // TRANS: Exception thrown when trying to revoke a role for a user with a failing database query. + // TRANS: %1$s is the role name, %2$s is the user ID (number). + throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id)); + } + + Event::handle('EndRevokeRole', array($this, $name)); + + return true; + } } function isSandboxed() -- cgit v1.2.3-54-g00ecf From 968f9b0513f1a2329ad3d9815303b32f94487764 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 25 Oct 2010 11:08:53 -0400 Subject: change max_id from < to <= --- classes/Profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes/Profile.php') diff --git a/classes/Profile.php b/classes/Profile.php index cb5ca54b0..a359a02d9 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -199,7 +199,7 @@ class Profile extends Memcached_DataObject } if ($max_id != 0) { - $query .= " and id < $max_id"; + $query .= " and id <= $max_id"; } $query .= ' order by id DESC'; -- cgit v1.2.3-54-g00ecf From aef88c7ceeb219c12d4ebce65b6f1fbccbc1458a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 25 Oct 2010 11:18:49 -0400 Subject: max_id is inclusive --- classes/Notice_tag.php | 2 +- classes/Profile.php | 2 +- classes/Reply.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'classes/Profile.php') diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php index a5d0716a7..6eada7022 100644 --- a/classes/Notice_tag.php +++ b/classes/Notice_tag.php @@ -60,7 +60,7 @@ class Notice_tag extends Memcached_DataObject } if ($max_id != 0) { - $nt->whereAdd('notice_id < ' . $max_id); + $nt->whereAdd('notice_id <= ' . $max_id); } $nt->orderBy('notice_id DESC'); diff --git a/classes/Profile.php b/classes/Profile.php index a359a02d9..37d2c571f 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -240,7 +240,7 @@ class Profile extends Memcached_DataObject } if ($max_id != 0) { - $query .= " and id < $max_id"; + $query .= " and id <= $max_id"; } $query .= ' order by id DESC'; diff --git a/classes/Reply.php b/classes/Reply.php index dc6296bda..da8a4f685 100644 --- a/classes/Reply.php +++ b/classes/Reply.php @@ -55,7 +55,7 @@ class Reply extends Memcached_DataObject } if ($max_id != 0) { - $reply->whereAdd('notice_id < ' . $max_id); + $reply->whereAdd('notice_id <= ' . $max_id); } $reply->orderBy('notice_id DESC'); -- cgit v1.2.3-54-g00ecf