Skip to content

Commit f53b581

Browse files
committed
Fixes #478, #520
1 parent de29e09 commit f53b581

7 files changed

Lines changed: 62 additions & 46 deletions

File tree

public/index.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,10 @@
133133
return $controller->pageUsers($primary_group);
134134
});
135135

136-
// User info form (update/view)
136+
// User info form (update)
137137
$app->get('/forms/users/u/:user_id/?', function ($user_id) use ($app) {
138138
$controller = new UF\UserController($app);
139-
$get = $app->request->get();
140-
if (isset($get['mode']) && $get['mode'] == "update")
141-
return $controller->formUserEdit($user_id);
142-
else
143-
return $controller->formUserView($user_id);
139+
return $controller->formUserEdit($user_id);
144140
});
145141

146142
// User edit password form
@@ -194,14 +190,10 @@
194190
return $controller->pageGroupAuthorization($group_id);
195191
})->name('uri_authorization');
196192

197-
// Group info form (update/view)
193+
// Group info form (update)
198194
$app->get('/forms/groups/g/:group_id/?', function ($group_id) use ($app) {
199195
$controller = new UF\GroupController($app);
200-
$get = $app->request->get();
201-
if (isset($get['mode']) && $get['mode'] == "update")
202-
return $controller->formGroupEdit($group_id);
203-
else
204-
return $controller->formGroupView($group_id);
196+
return $controller->formGroupEdit($group_id);
205197
});
206198

207199
// Group creation form

public/js/widget-auth.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,14 @@ function authForm(box_id, options) {
4646
$('#' + box_id).remove();
4747
}
4848

49-
// If we are updating an existing auth rule
50-
if (options['auth_id']) {
51-
var data = {
52-
box_id: box_id,
53-
mode: "update"
54-
};
49+
var data = {
50+
box_id: box_id
51+
};
5552

53+
// Creating vs updating an existing auth rule
54+
if (options['auth_id']) {
5655
var url = site['uri']['public'] + "/forms/groups/auth/a/" + options['auth_id'];
5756
} else {
58-
var data = {
59-
box_id: box_id
60-
};
61-
6257
var url = site['uri']['public'] + "/forms/groups/g/" + options['owner_id'] + "/auth";
6358
}
6459

public/js/widget-groups.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ function groupForm(box_id, group_id) {
5353
if (group_id) {
5454
data = {
5555
box_id: box_id,
56-
render: 'modal',
57-
mode: "update"
56+
render: 'modal'
5857
};
5958

6059
url = site['uri']['public'] + "/forms/groups/g/" + group_id;

public/js/widget-users.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ function userForm(box_id, user_id) {
184184
if (user_id) {
185185
data = {
186186
box_id: box_id,
187-
render: 'modal',
188-
mode: "update"
187+
render: 'modal'
189188
};
190189

191190
url = site['uri']['public'] + "/forms/users/u/" + user_id;
@@ -314,7 +313,11 @@ function userPasswordForm(box_id, user_id) {
314313
});
315314
}
316315

317-
// Display user info in a panel
316+
/**
317+
* Display user info in a panel
318+
*
319+
* @deprecated
320+
*/
318321
function userDisplay(box_id, user_id) {
319322
user_id = typeof user_id !== 'undefined' ? user_id : "";
320323

@@ -325,8 +328,7 @@ function userDisplay(box_id, user_id) {
325328

326329
var data = {
327330
box_id: box_id,
328-
render: 'modal',
329-
mode: 'view'
331+
render: 'modal'
330332
};
331333

332334
// Generate the form

userfrosting/controllers/GroupController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,13 @@ public function updateGroup($group_id){
338338

339339
// Check authorization for submitted fields, if the value has been changed
340340
foreach ($post as $name => $value) {
341-
if (isset($group->$name) && $post[$name] != $group->$name){
341+
if ($group->attributeExists($name) && $post[$name] != $group->$name){
342342
// Check authorization
343343
if (!$this->_app->user->checkAccess('update_group_setting', ['group' => $group, 'property' => $name])){
344344
$ms->addMessageTranslated("danger", "ACCESS_DENIED");
345345
$this->_app->halt(403);
346346
}
347-
} else if (!isset($group->$name)) {
347+
} else if (!$group->attributeExists($name)) {
348348
$ms->addMessageTranslated("danger", "NO_DATA");
349349
$this->_app->halt(400);
350350
}

userfrosting/controllers/UserController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,13 @@ public function updateUser($user_id){
576576

577577
// Check authorization for submitted fields, if the value has been changed
578578
foreach ($post as $name => $value) {
579-
if ($name == "groups" || (isset($target_user->$name) && $post[$name] != $target_user->$name)){
579+
if ($name == "groups" || ($target_user->attributeExists($name) && $post[$name] != $target_user->$name)){
580580
// Check authorization
581581
if (!$this->_app->user->checkAccess('update_account_setting', ['user' => $target_user, 'property' => $name])){
582582
$ms->addMessageTranslated("danger", "ACCESS_DENIED");
583583
$this->_app->halt(403);
584584
}
585-
} else if (!isset($target_user->$name)) {
585+
} else if (!$target_user->attributeExists($name)) {
586586
$ms->addMessageTranslated("danger", "NO_DATA");
587587
$this->_app->halt(400);
588588
}

userfrosting/models/database/UFModel.php

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* @package UserFrosting
1515
* @author Alex Weissman
1616
*/
17-
abstract class UFModel extends Model {
17+
abstract class UFModel extends Model
18+
{
1819

1920
/**
2021
* @var Slim The Slim app, containing configuration info
@@ -35,7 +36,8 @@ abstract class UFModel extends Model {
3536
* Create a new object, initializing the table name and whitelisted columns.
3637
*
3738
*/
38-
public function __construct($properties = []) {
39+
public function __construct($properties = [])
40+
{
3941
$table_schema = Database::getSchemaTable(static::$_table_id);
4042
$this->table = $table_schema->name;
4143
$this->fillable = $table_schema->columns;
@@ -45,19 +47,32 @@ public function __construct($properties = []) {
4547
}
4648

4749
/**
48-
* For raw array fetching. Must be static, otherwise PHP gets confused about where to find the table_id.
49-
*/
50-
public static function queryBuilder(){
51-
// Set query builder to fetch result sets as associative arrays (instead of creating stdClass objects)
52-
Capsule::connection()->setFetchMode(\PDO::FETCH_ASSOC);
53-
$table = Database::getSchemaTable(static::$_table_id)->name;
54-
return Capsule::table($table);
50+
* Determine if an attribute exists on the model - even if it is null.
51+
*
52+
* @param string $key
53+
* @return bool
54+
*/
55+
public function attributeExists($key)
56+
{
57+
return array_key_exists($key, $this->attributes);
58+
}
59+
60+
/**
61+
* Determine if an relation exists on the model - even if it is null.
62+
*
63+
* @param string $key
64+
* @return bool
65+
*/
66+
public function relationExists($key)
67+
{
68+
return array_key_exists($key, $this->relations);
5569
}
5670

5771
/**
5872
* For excluding certain columns in a query.
5973
*/
60-
public function scopeExclude($query, $value = []) {
74+
public function scopeExclude($query, $value = [])
75+
{
6176
$columns = array_merge(['id'], Database::getSchemaTable(static::$_table_id)->columns);
6277
return $query->select( array_diff( $columns,(array) $value) );
6378
}
@@ -68,7 +83,8 @@ public function scopeExclude($query, $value = []) {
6883
* Calls save(), then returns the id of the new record in the database.
6984
* @return int the id of this object.
7085
*/
71-
public function store(){
86+
public function store()
87+
{
7288
$this->save();
7389

7490
// Store function should always return the id of the object
@@ -80,7 +96,19 @@ public function store(){
8096
*
8197
* @return array
8298
*/
83-
public function export(){
99+
public function export()
100+
{
84101
return $this->toArray();
85-
}
102+
}
103+
104+
/**
105+
* For raw array fetching. Must be static, otherwise PHP gets confused about where to find the table_id.
106+
*/
107+
public static function queryBuilder()
108+
{
109+
// Set query builder to fetch result sets as associative arrays (instead of creating stdClass objects)
110+
Capsule::connection()->setFetchMode(\PDO::FETCH_ASSOC);
111+
$table = Database::getSchemaTable(static::$_table_id)->name;
112+
return Capsule::table($table);
113+
}
86114
}

0 commit comments

Comments
 (0)