Moved shareLocation preference check to Profile class

This commit is contained in:
Mikael Nordfeldth 2013-10-06 13:38:09 +02:00
parent cc34bb48c7
commit 78f9629bf3
9 changed files with 42 additions and 44 deletions

View File

@ -158,7 +158,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare(array $args=array())
{ {
parent::prepare($args); parent::prepare($args);
@ -181,9 +181,9 @@ class ApiStatusesUpdateAction extends ApiAuthAction
* *
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') { if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError( $this->clientError(
@ -222,7 +222,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
return; return;
} }
if (empty($this->auth_user)) { if (is_null($this->scoped)) {
// TRANS: Client error displayed when updating a status for a non-existing user. // TRANS: Client error displayed when updating a status for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404, $this->format);
return; return;
@ -269,7 +269,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
$upload = null; $upload = null;
try { try {
$upload = MediaFile::fromUpload('media', $this->auth_user->getProfile()); $upload = MediaFile::fromUpload('media', $this->scoped);
} catch (Exception $e) { } catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode(), $this->format); $this->clientError($e->getMessage(), $e->getCode(), $this->format);
return; return;
@ -306,20 +306,20 @@ class ApiStatusesUpdateAction extends ApiAuthAction
$options = array('reply_to' => $reply_to); $options = array('reply_to' => $reply_to);
if ($this->auth_user->shareLocation()) { if ($this->scoped->shareLocation()) {
$locOptions = Notice::locationOptions($this->lat, $locOptions = Notice::locationOptions($this->lat,
$this->lon, $this->lon,
null, null,
null, null,
$this->auth_user->getProfile()); $this->scoped);
$options = array_merge($options, $locOptions); $options = array_merge($options, $locOptions);
} }
try { try {
$this->notice = Notice::saveNew( $this->notice = Notice::saveNew(
$this->auth_user->id, $this->scoped->id,
$content, $content,
$this->source, $this->source,
$options $options

View File

@ -134,7 +134,7 @@ class NewnoticeAction extends FormAction
} }
} }
if ($user->shareLocation()) { if ($this->scoped->shareLocation()) {
// use browser data if checked; otherwise profile data // use browser data if checked; otherwise profile data
if ($this->arg('notice_data-geo')) { if ($this->arg('notice_data-geo')) {
$locOptions = Notice::locationOptions($this->trimmed('lat'), $locOptions = Notice::locationOptions($this->trimmed('lat'),

View File

@ -150,7 +150,7 @@ class ProfilesettingsAction extends SettingsAction
// TRANS: Checkbox label in form for profile settings. // TRANS: Checkbox label in form for profile settings.
$this->checkbox('sharelocation', _('Share my current location when posting notices'), $this->checkbox('sharelocation', _('Share my current location when posting notices'),
($this->arg('sharelocation')) ? ($this->arg('sharelocation')) ?
$this->arg('sharelocation') : $user->shareLocation()); $this->arg('sharelocation') : $this->scoped->shareLocation());
$this->elementEnd('li'); $this->elementEnd('li');
} }
Event::handle('EndProfileFormData', array($this)); Event::handle('EndProfileFormData', array($this));

View File

@ -955,7 +955,7 @@ class Profile extends Managed_DataObject
// XXX: identical to Notice::getLocation. // XXX: identical to Notice::getLocation.
function getLocation() public function getLocation()
{ {
$location = null; $location = null;
@ -978,6 +978,29 @@ class Profile extends Managed_DataObject
return $location; return $location;
} }
public function shareLocation()
{
$cfg = common_config('location', 'share');
if ($cfg == 'always') {
return true;
} else if ($cfg == 'never') {
return false;
} else { // user
$share = common_config('location', 'sharedefault');
// Check if user has a personal setting for this
$prefs = User_location_prefs::getKV('user_id', $this->id);
if (!empty($prefs)) {
$share = $prefs->share_location;
$prefs->free();
}
return $share;
}
}
function hasRole($name) function hasRole($name)
{ {
$has_role = false; $has_role = false;

View File

@ -861,29 +861,6 @@ class User extends Managed_DataObject
throw new Exception(_('Not implemented since inbox change.')); throw new Exception(_('Not implemented since inbox change.'));
} }
function shareLocation()
{
$cfg = common_config('location', 'share');
if ($cfg == 'always') {
return true;
} else if ($cfg == 'never') {
return false;
} else { // user
$share = common_config('location', 'sharedefault');
// Check if user has a personal setting for this
$prefs = User_location_prefs::getKV('user_id', $this->id);
if (!empty($prefs)) {
$share = $prefs->share_location;
$prefs->free();
}
return $share;
}
}
public static function siteOwner() public static function siteOwner()
{ {
$owner = self::cacheGet('user:site_owner'); $owner = self::cacheGet('user:site_owner');

View File

@ -140,7 +140,7 @@ class ApiAction extends Action
* *
* @return boolean false if user doesn't exist * @return boolean false if user doesn't exist
*/ */
function prepare($args) protected function prepare(array $args=array())
{ {
StatusNet::setApi(true); // reduce exception reports to aid in debugging StatusNet::setApi(true); // reduce exception reports to aid in debugging
parent::prepare($args); parent::prepare($args);
@ -172,10 +172,10 @@ class ApiAction extends Action
* *
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
parent::handle($args); parent::handle();
} }
/** /**

View File

@ -53,9 +53,7 @@
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/** /**
* Actions extending this class will require auth * Actions extending this class will require auth
@ -80,7 +78,7 @@ class ApiAuthAction extends ApiAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare(array $args=array())
{ {
parent::prepare($args); parent::prepare($args);

View File

@ -246,7 +246,7 @@ class NoticeForm extends Form
$toWidget->show(); $toWidget->show();
$this->out->elementEnd('div'); $this->out->elementEnd('div');
if ($this->user->shareLocation()) { if ($this->profile->shareLocation()) {
$this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat'); $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
$this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon'); $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
$this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id'); $this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id');

View File

@ -206,7 +206,7 @@ class ReplyForm extends NoticeForm
} }
$this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto'); $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
if ($this->user->shareLocation()) { if ($this->profile->shareLocation()) {
$this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat'); $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
$this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon'); $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
$this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id'); $this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id');