Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Fixed user not found error messsage added admin bio and new role capabilities view_other_admin and edit_other_admin

givanz3ed01fa52946
diff --git a/admin/controller/admin/auth-token.php b/admin/controller/admin/auth-token.php
index 485884c..44f2cdf 100644
--- a/admin/controller/admin/auth-token.php
+++ b/admin/controller/admin/auth-token.php
@@ -48,7 +48,7 @@ class AuthToken extends Listing {
$this->options['limit'] =1000;
if (! $this->options['admin_id']) {
- return $this->notFound(true, __('User not found!'));
+ return $this->notFound(__('User not found!'));
}
$this->view->user_url = url(['module' => 'admin/user', 'admin_id' => $this->options['admin_id']]);
diff --git a/admin/controller/admin/user.php b/admin/controller/admin/user.php
index dbce6f9..8c38571 100755
--- a/admin/controller/admin/user.php
+++ b/admin/controller/admin/user.php
@@ -41,8 +41,13 @@ class User extends UserBase {
$roles = $roles->getAll($options);
$sites = new SiteSQL();
+ if (! isset($this->view->user['site_access'])) {
+ //set default site access to current site for new user
+ $this->view->user['site_access'] = [$this->global['site_id']];
+ }
+
$this->view->admin_auth_token_url = \Vvveb\url(['module' => 'admin/auth-token', 'admin_id' => $this->request->get['admin_id'] ?? '']);
- $this->view->sitesList = $sites->getAll()['site'] ?? [];
- $this->view->roles = $roles ? $roles['role'] : [];
+ $this->view->sitesList = $sites->getAll()['site'] ?? [];
+ $this->view->roles = array_reverse($roles ? $roles['role'] : []);
}
}
diff --git a/admin/controller/admin/users.php b/admin/controller/admin/users.php
index 1ccea89..ccfa12b 100755
--- a/admin/controller/admin/users.php
+++ b/admin/controller/admin/users.php
@@ -23,9 +23,20 @@
namespace Vvveb\Controller\Admin;
use Vvveb\Controller\User\Users as UsersBase;
+use Vvveb\System\User\Admin;
class Users extends UsersBase {
protected $type = 'admin';
protected $module = 'admin/users';
+
+ function index($options = []) {
+ if (Admin::hasCapability('view_other_admin')) {
+ unset($options['admin_id']);
+ } else {
+ $options['admin_id'][] = $this->global['admin_id'];
+ }
+
+ parent::index($options);
+ }
}
diff --git a/admin/controller/user/user.php b/admin/controller/user/user.php
index 52256cf..9299576 100755
--- a/admin/controller/user/user.php
+++ b/admin/controller/user/user.php
@@ -25,11 +25,11 @@ namespace Vvveb\Controller\User;
use function Vvveb\__;
use Vvveb\Controller\Base;
use function Vvveb\model;
+use function Vvveb\sanitizeHTML;
use Vvveb\System\Core\View;
use Vvveb\System\Images;
+use Vvveb\System\Sites;
use Vvveb\System\User\Admin;
-use Vvveb\System\User\Auth;
-use Vvveb\System\User\User as UserLogin;
use Vvveb\System\User\User as UserSystem;
use Vvveb\System\Validator;
@@ -41,14 +41,26 @@ class User extends Base {
$user_id = (int)($this->request->get[$this->type . '_id'] ?? false);
+
if ($user_id) {
$options = [$this->type . '_id' => (int)$user_id];
+ if ($this->type == 'admin') {
+ if (Admin::hasCapability('view_other_admin')) {
+ } else {
+ if ($user_id != $this->global['admin_id']) {
+ $message = __('Permission denied!');
+ $view->errors[] = $message;
+ $this->notFound($message, 403, true);
+ }
+ }
+ }
+
$users = model($this->type);
$user = $users->get($options);
if (! $user) {
- return $this->notFound(true, __('User not found!'));
+ return $this->notFound(__('User not found!'));
}
if (isset($user['password'])) {
@@ -70,10 +82,27 @@ class User extends Base {
$view->user = $user;
}
+ $view->type = $this->type;
$admin_path = \Vvveb\adminPath();
$controllerPath = $admin_path . 'index.php?module=media/media';
$view->scanUrl = "$controllerPath&action=scan";
$view->uploadUrl = "$controllerPath&action=upload";
+ $view->themeCss = '';
+
+ $theme = Sites::getTheme($this->global['site_id']) ?? 'default';
+ if (file_exists(DIR_THEMES . "$theme/css/admin-post-editor.css")) {
+ $view->themeCss .= PUBLIC_PATH . "themes/$theme/css/admin-post-editor.css";
+ } else {
+ if (file_exists(DIR_THEMES . "$theme/css/style.css")) {
+ $view->themeCss .= PUBLIC_PATH . "themes/$theme/css/style.css";
+ }
+ }
+
+ foreach (['custom.css', 'fonts.css'] as $css) {
+ if (file_exists(DIR_THEMES . "$theme/css/$css")) {
+ $view->themeCss .= ',' . PUBLIC_PATH . "themes/$theme/css/$css";
+ }
+ }
if ($this->type == 'user') {
$userGroup = model('user_group');
@@ -88,7 +117,7 @@ class User extends Base {
if ($user_id) {
$view = View :: getInstance();
- $userInfo = UserLogin::get(['user_id' => $user_id]);
+ $userInfo = UserSystem::get(['user_id' => $user_id]);
if ($userInfo) {
\Vvveb\session(['user' => $userInfo]);
@@ -112,15 +141,26 @@ class User extends Base {
$user_id = (int)($this->request->get[$this->type . '_id'] ?? false);
$user = $this->request->post[$this->type] ?? [];
+ if ($this->type == 'admin') {
+ $editCapability = 'edit_other_admin';
+ if (Admin::hasCapability($editCapability)) {
+ } else {
+ if (! $user_id || $user_id != $this->global['admin_id']) {
+ $view->errors[] = __('Permission denied!');
+ return;
+ }
+ }
+ }
+
+
if (($errors = $validator->validate($user)) === true) {
- $users = model($this->type);
- $user = $this->request->post[$this->type] ?? [];
+ $users = model($this->type);
+ $user = $this->request->post[$this->type] ?? [];
//if no password provided don't change
if (empty($user['password'])) {
unset($user['password']);
} else {
- $user['password'] = Auth :: password($user['password']);
}
if (isset($user['site_access'])) {
@@ -134,9 +174,14 @@ class User extends Base {
}
$user['updated_at'] = date('Y-m-d H:i:s');
+ $user['bio'] = sanitizeHTML($user['bio']);
if ($user_id) {
- $result = $users->edit([$this->type . '_id' => $user_id, $this->type => $user]);
+ if ($this->type == 'admin') {
+ $result = Admin::update($user, [$this->type . '_id' => $user_id]);
+ } else {
+ $result = UserSystem::update($user, [$this->type . '_id' => $user_id]);
+ }
if ($result >= 0) {
$this->view->success[] = ucfirst($this->type) . __(' saved!');
diff --git a/admin/sql/mysqli/admin.sql b/admin/sql/mysqli/admin.sql
old mode 100755
new mode 100644
index f11373e..cf1d65a
--- a/admin/sql/mysqli/admin.sql
+++ b/admin/sql/mysqli/admin.sql
@@ -5,9 +5,10 @@
CREATE PROCEDURE getAll(
IN start INT,
IN limit INT,
- IN status INT,
+ IN status INT,
IN search CHAR,
IN email CHAR,
+ IN admin_id ARRAY,
IN phone_number CHAR,
-- return array of admin
@@ -20,24 +21,29 @@
SELECT * FROM admin WHERE 1 = 1
- @IF isset(:status) AND !empty(:status)
- THEN
- AND admin.status = :status
+ @IF isset(:status) AND !empty(:status)
+ THEN
+ AND admin.status = :status
END @IF
- @IF isset(:email) AND !empty(:email)
- THEN
- AND admin.email = :email
+ @IF isset(:email) AND !empty(:email)
+ THEN
+ AND admin.email = :email
END @IF
- @IF isset(:phone_number) AND !empty(:phone_number)
- THEN
- AND admin.phone_number = :phone_number
+ @IF isset(:phone_number) AND !empty(:phone_number)
+ THEN
+ AND admin.phone_number = :phone_number
+ END @IF
+
+ @IF isset(:admin_id) AND !empty(:admin_id) AND is_array(:admin_id)
+ THEN
+ AND admin.admin_id IN (:admin_id)
END @IF
- -- search
- @IF isset(:search) AND !empty(:search)
- THEN
+ -- search
+ @IF isset(:search) AND !empty(:search)
+ THEN
AND admin.username LIKE CONCAT('%',:search,'%') || admin.first_name LIKE CONCAT('%',:search,'%') || admin.last_name LIKE CONCAT('%',:search,'%')
END @IF
@@ -97,7 +103,7 @@
AND _.email = :email OR _.username = :username
END @IF
- @IF isset(:admin_id)
+ @IF isset(:admin_id) && :admin_id
THEN
AND _.admin_id = :admin_id
END @IF
@@ -167,26 +173,26 @@
WHERE
- @IF isset(:email)
+ @IF isset(:email)
THEN
email = :email
- END @IF
+ END @IF
- @IF isset(:admin_id)
+ @IF isset(:admin_id)
THEN
admin_id = :admin_id
- END @IF
+ END @IF
@IF isset(:username)
THEN
username = :username
- END @IF
+ END @IF
END
-- delete admin
PROCEDURE delete(
- IN admin_id ARRAY,
+ IN admin_id ARRAY,
OUT affected_rows
)
BEGIN
diff --git a/admin/sql/mysqli/digital_asset.sql b/admin/sql/mysqli/digital_asset.sql
old mode 100755
new mode 100644
index 3282fe1..7c3e4b0
--- a/admin/sql/mysqli/digital_asset.sql
+++ b/admin/sql/mysqli/digital_asset.sql
@@ -14,7 +14,7 @@
)
BEGIN
-- digital_asset
- SELECT UNIQUE digital_asset.digital_asset_id, digital_asset.*, digital_asset_content.name
+ SELECT DISTINCT digital_asset.digital_asset_id, digital_asset.*, digital_asset_content.name
-- user_id
@IF isset(:user_id)
THEN
diff --git a/admin/sql/pgsql/admin.sql b/admin/sql/pgsql/admin.sql
index a01b3e6..6348939 100755
--- a/admin/sql/pgsql/admin.sql
+++ b/admin/sql/pgsql/admin.sql
@@ -5,9 +5,10 @@
CREATE PROCEDURE getAll(
IN start INT,
IN limit INT,
- IN status INT,
+ IN status INT,
IN search CHAR,
IN email CHAR,
+ IN admin_id ARRAY,
IN phone_number CHAR,
-- return array of admin
@@ -20,24 +21,29 @@
SELECT * FROM admin WHERE 1 = 1
- @IF isset(:status) AND !empty(:status)
- THEN
- AND admin.status = :status
+ @IF isset(:status) AND !empty(:status)
+ THEN
+ AND admin.status = :status
END @IF
- @IF isset(:email) AND !empty(:email)
- THEN
- AND admin.email = :email
+ @IF isset(:email) AND !empty(:email)
+ THEN
+ AND admin.email = :email
END @IF
- @IF isset(:phone_number) AND !empty(:phone_number)
- THEN
- AND admin.phone_number = :phone_number
+ @IF isset(:phone_number) AND !empty(:phone_number)
+ THEN
+ AND admin.phone_number = :phone_number
+ END @IF
+
+ @IF isset(:admin_id) AND !empty(:admin_id) AND is_array(:admin_id)
+ THEN
+ AND admin.admin_id IN (:admin_id)
END @IF
- -- search
- @IF isset(:search) AND !empty(:search)
- THEN
+ -- search
+ @IF isset(:search) AND !empty(:search)
+ THEN
AND admin.username LIKE CONCAT('%',:search,'%') || admin.first_name LIKE CONCAT('%',:search,'%') || admin.last_name LIKE CONCAT('%',:search,'%')
END @IF
@@ -97,7 +103,7 @@
AND _.email = :email OR _.username = :username
END @IF
- @IF isset(:admin_id)
+ @IF isset(:admin_id) && :admin_id
THEN
AND _.admin_id = :admin_id
END @IF
@@ -186,7 +192,7 @@
-- delete admin
PROCEDURE delete(
- IN admin_id ARRAY,
+ IN admin_id ARRAY,
OUT affected_rows
)
BEGIN
diff --git a/admin/sql/sqlite/admin.sql b/admin/sql/sqlite/admin.sql
index 458f08a..32464f6 100755
--- a/admin/sql/sqlite/admin.sql
+++ b/admin/sql/sqlite/admin.sql
@@ -5,9 +5,10 @@
CREATE PROCEDURE getAll(
IN start INT,
IN limit INT,
- IN status INT,
+ IN status INT,
IN search CHAR,
IN email CHAR,
+ IN admin_id ARRAY,
IN phone_number CHAR,
-- return array of admin
@@ -20,24 +21,29 @@
SELECT * FROM admin WHERE 1 = 1
- @IF isset(:status) AND !empty(:status)
- THEN
- AND admin.status = :status
+ @IF isset(:status) AND !empty(:status)
+ THEN
+ AND admin.status = :status
END @IF
- @IF isset(:email) AND !empty(:email)
- THEN
- AND admin.email = :email
+ @IF isset(:email) AND !empty(:email)
+ THEN
+ AND admin.email = :email
END @IF
- @IF isset(:phone_number) AND !empty(:phone_number)
- THEN
- AND admin.phone_number = :phone_number
+ @IF isset(:phone_number) AND !empty(:phone_number)
+ THEN
+ AND admin.phone_number = :phone_number
+ END @IF
+
+ @IF isset(:admin_id) AND !empty(:admin_id) AND is_array(:admin_id)
+ THEN
+ AND admin.admin_id IN (:admin_id)
END @IF
- -- search
- @IF isset(:search) AND !empty(:search)
- THEN
+ -- search
+ @IF isset(:search) AND !empty(:search)
+ THEN
AND admin.username LIKE CONCAT('%',:search,'%') || admin.first_name LIKE CONCAT('%',:search,'%') || admin.last_name LIKE CONCAT('%',:search,'%')
END @IF
@@ -97,7 +103,7 @@
AND _.email = :email OR _.username = :username
END @IF
- @IF isset(:admin_id)
+ @IF isset(:admin_id) && :admin_id
THEN
AND _.admin_id = :admin_id
END @IF
@@ -186,7 +192,7 @@
-- delete admin
PROCEDURE delete(
- IN admin_id ARRAY,
+ IN admin_id ARRAY,
OUT affected_rows
)
BEGIN
diff --git a/admin/template/admin/user.tpl b/admin/template/admin/user.tpl
old mode 100755
new mode 100644
index 1fd7d17..37a30ea
--- a/admin/template/admin/user.tpl
+++ b/admin/template/admin/user.tpl
@@ -31,14 +31,14 @@ import(common.tpl)
?>
-[data-v-user] select[data-v-user-*] option|addNewAttribute = <?php if (isset($this->user) && $this->user['status'] == '@@__value__@@') echo 'selected';?>
+[data-v-user] select[data-v-user-*] option|addNewAttribute = <?php if (isset($this->user['status']) && $this->user['status'] == '@@__value__@@') echo 'selected';?>
[data-v-role-list] [data-v-role]|before = <?php
foreach ($this->roles as $i => $role) { ?>
[data-v-role-list] [data-v-role] = $role['display_name']
[data-v-role-list] [data-v-role]|value = $role['role_id']
- [data-v-role-list] [data-v-role]|addNewAttribute = <?php if (isset($this->user) && ($role['role_id'] == $this->user['role_id'])) echo 'selected';?>
+ [data-v-role-list] [data-v-role]|addNewAttribute = <?php if (isset($this->user['role_id']) && ($role['role_id'] == $this->user['role_id'])) echo 'selected';?>
[data-v-role-list] [data-v-role]|after = <?php
}
diff --git a/admin/template/user/user.tpl b/admin/template/user/user.tpl
old mode 100755
new mode 100644
index 39b132a..29464c5
--- a/admin/template/user/user.tpl
+++ b/admin/template/user/user.tpl
@@ -1,5 +1,13 @@
import(crud.tpl, {"type":"user"})
+[data-v-user] input[data-v-user-*]|value =
+<?php
+ if (isset($_POST['user']['@@__data-v-user-(*)__@@']))
+ echo htmlspecialchars($_POST['user']['@@__data-v-user-(*)__@@']);
+ else if (isset($this->user['@@__data-v-user-(*)__@@']))
+ echo htmlspecialchars($this->user['@@__data-v-user-(*)__@@']);
+?>
+
[data-v-user] select[data-v-user-*] option|addNewAttribute = <?php if (isset($this->user) && $this->user['status'] == '@@__value__@@') echo 'selected';?>
/* Avatar */
diff --git a/admin/template/user/users.tpl b/admin/template/user/users.tpl
old mode 100755
new mode 100644
index b975257..3cbef34
--- a/admin/template/user/users.tpl
+++ b/admin/template/user/users.tpl
@@ -12,11 +12,12 @@ if(isset($this->users) && is_array($this->users)) {
foreach ($this->users as $index => $user) {
$url = Vvveb\url(['module' => $module, $id => $user[$id]]);
$status = $user['status_text'];
- $status_class = $user['status'] == 1 ? 'bg-success' :($user['status'] == 0 ? 'bg-body-secondary text-muted' : $user['status']);
+ $status_class = ($user['status'] == 3 ? 'bg-danger' : ($user['status'] == 1 ? 'bg-success' :($user['status'] == 0 ? 'bg-body-secondary text-muted' : $user['status'])));
?>
@user [data-v-*]|innerText = $user['@@__data-v-(*)__@@']
@user input[data-v-*]|value = $user['@@__data-v-(*)__@@']
+ @user button[data-v-*]|value = $user['@@__data-v-(*)__@@']
@user img[data-v-*]|src = $user['@@__data-v-(*)__@@']
@user [data-v-url]|href = $url
@user a[data-v-*]|href = $user['@@__data-v-(*)__@@']
diff --git a/app/component/admin.php b/app/component/admin.php
old mode 100644
new mode 100755
index c0e67e5..a2a1cec
--- a/app/component/admin.php
+++ b/app/component/admin.php
@@ -63,6 +63,7 @@ class Admin extends ComponentBase {
}
}
+ $results['website'] = $results['website'] ?? $results['url'];
$results['url'] = url('content/user/index', ['username' => $results['username']]);
} else {
$results = [];
diff --git a/app/template/components/admin.tpl b/app/template/components/admin.tpl
index 8ad9ac1..ebfd7ee 100644
--- a/app/template/components/admin.tpl
+++ b/app/template/components/admin.tpl
@@ -5,6 +5,7 @@
//$admin = \Vvveb\session('admin');
?>
+[data-v-component-admin] [data-v-admin-bio] = <?php echo $admin['bio'] ?? '';?>
[data-v-component-admin] [data-v-admin-*]|innerText = $admin['@@__data-v-admin-(*)__@@']
[data-v-component-admin] a[data-v-admin-*]|href = $admin['@@__data-v-admin-(*)__@@']
[data-v-component-admin] img[data-v-admin-*]|src = <?php
diff --git a/app/template/components/admins.tpl b/app/template/components/admins.tpl
new file mode 100644
index 0000000..9ebc2d9
--- /dev/null
+++ b/app/template/components/admins.tpl
@@ -0,0 +1,43 @@
+@admins = [data-v-component-admins]
+@admin = [data-v-component-admins] [data-v-admin]
+
+@admin|deleteAllButFirstChild
+
+@admins|prepend = <?php
+if (isset($_admins_idx)) $_admins_idx++; else $_admins_idx = 0;
+$previous_component = isset($current_component)?$current_component:null;
+$admins = $current_component = $this->_component['admins'][$_admins_idx] ?? [];
+
+$count = $admins['count'] ?? 0;
+$limit = isset($admins['limit']) ? $admins['limit'] : 5;
+?>
+
+
+@admin|before = <?php
+$vvveb_is_page_edit = Vvveb\isEditor();
+$_admins = $admins['admin'] ?? [];
+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['admin_id' => 1, 'username' => '']] : false;
+$_admins = empty($_admins) ? $_default : $_admins;
+
+if($_admins && is_array($_admins)) {
+ foreach ($_admins as $index => $admin) {?>
+
+ @admin|data-admin_id = $admin['admin_id']
+
+ @admin|addClass = <?php if (!$vvveb_is_page_edit) echo 'level-' . ($admin['level'] ?? 0);?>
+
+ @admin|id = <?php if (!$vvveb_is_page_edit) echo 'admin-' . $admin['admin_id'];?>
+
+ @admin [data-v-admin-content] = $admin['content']
+
+ @admin img[data-v-admin-*]|src = $admin['@@__data-v-admin-(*)__@@']
+ //@admin img[data-v-admin-*]|width = <?php echo (int)($admin['size'] ?? 60);?>
+
+ @admin [data-v-admin-*]|innerText = $admin['@@__data-v-admin-(*)__@@']
+
+ @admin a[data-v-admin-*]|href = $admin['@@__data-v-admin-(*)__@@']
+
+ @admin|after = <?php
+ }
+}
+?>
\ No newline at end of file
diff --git a/system/data/capabilities.php b/system/data/capabilities.php
old mode 100644
new mode 100755
index c7edb5a..7c3200f
--- a/system/data/capabilities.php
+++ b/system/data/capabilities.php
@@ -29,4 +29,6 @@ return [
'edit_other_products' => __('Edit other users products'),
'view_other_sites' => __('View other users sites'),
'edit_other_sites' => __('Edit other users sites'),
+ 'view_other_admin' => __('View other admin users'),
+ 'edit_other_admin' => __('Edit other admin users'),
];