Skip to content

Commit c1d5fff

Browse files
committed
Merge branch '4.9' into 5.0.0
# Conflicts: # .github/workflows/phpunit.yml # README.md # composer.json
2 parents 8e81d5c + 1c73516 commit c1d5fff

File tree

10 files changed

+97
-68
lines changed

10 files changed

+97
-68
lines changed

.github/workflows/phpunit.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ jobs:
2222
- "7.4"
2323

2424
steps:
25-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
2626
- run: composer install
2727
- run: ./vendor/bin/phpunit --stderr
2828

2929
Documentation:
30-
runs-on: 'ubuntu-latest'
31-
needs: Build
3230
if: github.ref == 'refs/heads/master'
33-
env:
34-
DOC_GITHUB_TOKEN: '${{ secrets.DOC_TOKEN }}'
35-
steps:
36-
- uses: actions/checkout@v3
37-
- run: curl https://opensource.byjg.com/add-doc.sh | bash /dev/stdin php authuser
31+
needs: Build
32+
uses: byjg/byjg.github.io/.github/workflows/add-doc.yaml@master
33+
with:
34+
folder: php
35+
project: ${{ github.event.repository.name }}
36+
secrets: inherit
37+

.vscode/launch.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Auth User PHP
22

3-
[![Build Status](https://github.com/byjg/authuser/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/authuser/actions/workflows/phpunit.yml)
3+
[![Build Status](https://github.com/byjg/php-authuser/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-authuser/actions/workflows/phpunit.yml)
44
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
5-
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/authuser/)
6-
[![GitHub license](https://img.shields.io/github/license/byjg/authuser.svg)](https://opensource.byjg.com/opensource/licensing.html)
7-
[![GitHub release](https://img.shields.io/github/release/byjg/authuser.svg)](https://github.com/byjg/authuser/releases/)
5+
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/php-authuser/)
6+
[![GitHub license](https://img.shields.io/github/license/byjg/php-authuser.svg)](https://opensource.byjg.com/opensource/licensing.html)
7+
[![GitHub release](https://img.shields.io/github/release/byjg/php-authuser.svg)](https://github.com/byjg/php-authuser/releases/)
88

99
A simple and customizable class for enable user authentication inside your application. It is available on XML files, Relational Databases and Moodle.
1010

@@ -316,16 +316,26 @@ $users = new ByJG\Authenticate\UsersDBDataset(
316316
Just type:
317317

318318
```bash
319-
composer require "byjg/authuser=5.0.*"
319+
composer require "byjg/authuser"
320320
```
321321

322322
## Running Tests
323323

324324
Because this project uses PHP Session you need to run the unit test the following manner:
325325

326326
```bash
327-
phpunit --stderr
327+
./vendor/bin/phpunit --stderr
328328
```
329329

330+
## Dependencies
331+
332+
```mermaid
333+
flowchart TD
334+
byjg/authuser --> byjg/micro-orm
335+
byjg/authuser --> byjg/cache-engine
336+
byjg/authuser --> byjg/jwt-wrapper
337+
```
338+
339+
330340
----
331341
[Open source ByJG](http://opensource.byjg.com)

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"prefer-stable": true,
1111
"require": {
1212
"php": ">=7.4",
13-
"byjg/micro-orm": "5.0.0.x-dev",
14-
"byjg/cache-engine": "5.0.0.x-dev",
15-
"byjg/jwt-wrapper": "5.0.0.x-dev"
13+
"byjg/micro-orm": "4.9.*",
14+
"byjg/cache-engine": "4.9.*",
15+
"byjg/jwt-wrapper": "4.9.*"
1616
},
1717
"require-dev": {
1818
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"

src/Interfaces/UsersInterface.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getUser($filter);
4949
/**
5050
* Enter description here...
5151
*
52-
* @param int $userid
52+
* @param int|string $userid
5353
* @return Row
5454
*/
5555
public function getById($userid);
@@ -99,7 +99,7 @@ public function isAdmin($userId);
9999

100100
/**
101101
* @desc Check if the user have rights to edit specific site.
102-
* @param int $userId
102+
* @param int|string $userId
103103
* @param string $propertyName
104104
* @param string $value
105105
* @return True if have rights; false, otherwisebool
@@ -108,23 +108,31 @@ public function hasProperty($userId, $propertyName, $value = null);
108108

109109
/**
110110
* @desc Return all sites from a specific user
111-
* @param int $userId
111+
* @param int|string $userId
112112
* @param string $propertyName
113113
* @return string[] String vector with all sites
114114
*/
115115
public function getProperty($userId, $propertyName);
116116

117117
/**
118118
*
119-
* @param int $userId
119+
* @param int|string $userId
120120
* @param string $propertyName
121121
* @param string $value
122122
*/
123123
public function addProperty($userId, $propertyName, $value);
124124

125125
/**
126126
*
127-
* @param int $userId
127+
* @param int|string $userId
128+
* @param string $propertyName
129+
* @param string $value
130+
*/
131+
public function setProperty($userId, $propertyName, $value);
132+
133+
/**
134+
*
135+
* @param int|string $userId
128136
* @param string $propertyName
129137
* @param string $value
130138
*/

src/UsersAnyDataset.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function getUsersByPropertySet($propertiesArray)
162162
}
163163

164164
/**
165-
* @param int $userId
165+
* @param int|string $userId
166166
* @param string $propertyName
167167
* @param string $value
168168
* @return boolean
@@ -187,8 +187,19 @@ public function addProperty($userId, $propertyName, $value)
187187
return false;
188188
}
189189

190+
public function setProperty($userId, $propertyName, $value)
191+
{
192+
$user = $this->getById($userId);
193+
if ($user !== null) {
194+
$user->set($propertyName, $value);
195+
$this->save($user);
196+
return true;
197+
}
198+
return false;
199+
}
200+
190201
/**
191-
* @param int $userId
202+
* @param int|string $userId
192203
* @param string $propertyName
193204
* @param string $value
194205
* @return boolean

src/UsersBase.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,16 @@ public function hasProperty($userId, $propertyName, $value = null)
226226
}
227227

228228
$values = $user->get($propertyName);
229-
return ($values !== null ? in_array($value, (array)$values) : false);
229+
230+
if ($values === null) {
231+
return false;
232+
}
233+
234+
if ($value === null) {
235+
return true;
236+
}
237+
238+
return in_array($value, (array)$values);
230239
}
231240

232241
/**
@@ -261,7 +270,7 @@ abstract public function getUsersByPropertySet($propertiesArray);
261270

262271
/**
263272
*
264-
* @param int $userId
273+
* @param int|string $userId
265274
* @param string $propertyName
266275
* @param string $value
267276
*/
@@ -271,7 +280,7 @@ abstract public function addProperty($userId, $propertyName, $value);
271280
* Remove a specific site from user
272281
* Return True or false
273282
*
274-
* @param int $userId User login
283+
* @param int|string $userId User login
275284
* @param string $propertyName Property name
276285
* @param string $value Property value with a site
277286
* @return bool

src/UsersDBDataset.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public function getUsersByProperty($propertyName, $value)
249249
public function getUsersByPropertySet($propertiesArray)
250250
{
251251
$query = Query::getInstance()
252+
->field("u.*")
252253
->table($this->getUserDefinition()->table(), "u");
253254

254255
$count = 0;
@@ -263,7 +264,7 @@ public function getUsersByPropertySet($propertiesArray)
263264
}
264265

265266
/**
266-
* @param int $userId
267+
* @param int|string $userId
267268
* @param string $propertyName
268269
* @param string $value
269270
* @return bool
@@ -289,11 +290,30 @@ public function addProperty($userId, $propertyName, $value)
289290
return true;
290291
}
291292

293+
public function setProperty($userId, $propertyName, $value)
294+
{
295+
$query = Query::getInstance()
296+
->table($this->getUserPropertiesDefinition()->table())
297+
->where("{$this->getUserPropertiesDefinition()->getUserid()} = :id", ["id" => $userId])
298+
->where("{$this->getUserPropertiesDefinition()->getName()} = :name", ["name" => $propertyName]);
299+
300+
$userProperty = $this->propertiesRepository->getByQuery($query);
301+
if (empty($userProperty)) {
302+
$userProperty = new UserPropertiesModel($propertyName, $value);
303+
$userProperty->setUserid($userId);
304+
} else {
305+
$userProperty = $userProperty[0];
306+
$userProperty->setValue($value);
307+
}
308+
309+
$this->propertiesRepository->save($userProperty);
310+
}
311+
292312
/**
293313
* Remove a specific site from user
294314
* Return True or false
295315
*
296-
* @param int $userId User Id
316+
* @param int|string $userId User Id
297317
* @param string $propertyName Property name
298318
* @param string $value Property value with a site
299319
* @return bool

src/UsersMoodleDataset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function removeByLoginField($login)
181181
/**
182182
* Remove the user based on his user id.
183183
*
184-
* @param int $userId
184+
* @param int|string $userId
185185
* @return void
186186
* @throws \ByJG\Authenticate\Exception\NotImplementedException
187187
*/

tests/UsersAnyDatasetByUsernameTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,13 @@ public function testGetByUserProperty()
343343
$this->assertEquals($this->prefix . '2', $user[0]->getUserid());
344344

345345
}
346+
347+
public function testSetProperty()
348+
{
349+
$this->assertFalse($this->object->hasProperty($this->prefix . '1', 'propertySet'));
350+
$this->object->setProperty($this->prefix . '1', 'propertySet', 'somevalue');
351+
$this->assertTrue($this->object->hasProperty($this->prefix . '1', 'propertySet'));
352+
$this->assertTrue($this->object->hasProperty($this->prefix . '1', 'propertySet', 'somevalue'));
353+
$this->assertEquals('somevalue', $this->object->getProperty($this->prefix . '1', 'propertySet'));
354+
}
346355
}

0 commit comments

Comments
 (0)