mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 22:41:27 +00:00
Merge pull request #2798 from pixelfed/staging
Auto Following support for admins
This commit is contained in:
commit
8dc6d17bfd
5 changed files with 119 additions and 60 deletions
|
@ -3,6 +3,7 @@
|
|||
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.11.0...dev)
|
||||
### Added
|
||||
- WebP Support ([069a0e4a](https://github.com/pixelfed/pixelfed/commit/069a0e4a))
|
||||
- Auto Following support for admins ([68aa2540](https://github.com/pixelfed/pixelfed/commit/68aa2540))
|
||||
|
||||
### Updated
|
||||
- Updated PrettyNumber, fix deprecated warning. ([20ec870b](https://github.com/pixelfed/pixelfed/commit/20ec870b))
|
||||
|
|
|
@ -135,7 +135,8 @@ trait AdminSettingsController
|
|||
'enforce_account_limit' => 'pixelfed.enforce_account_limit',
|
||||
'show_custom_css' => 'uikit.show_custom.css',
|
||||
'show_custom_js' => 'uikit.show_custom.js',
|
||||
'cloud_storage' => 'pixelfed.cloud_storage'
|
||||
'cloud_storage' => 'pixelfed.cloud_storage',
|
||||
'account_autofollow' => 'account.autofollow'
|
||||
];
|
||||
|
||||
foreach ($bools as $key => $value) {
|
||||
|
@ -171,6 +172,21 @@ trait AdminSettingsController
|
|||
}
|
||||
}
|
||||
|
||||
if($request->filled('account_autofollow_usernames')) {
|
||||
$usernames = explode(',', $request->input('account_autofollow_usernames'));
|
||||
$names = [];
|
||||
|
||||
foreach($usernames as $n) {
|
||||
$p = Profile::whereUsername($n)->first();
|
||||
if(!$p) {
|
||||
continue;
|
||||
}
|
||||
array_push($names, $p->username);
|
||||
}
|
||||
|
||||
ConfigCacheService::put('account.autofollow_usernames', implode(',', $names));
|
||||
}
|
||||
|
||||
Cache::forget(Config::CACHE_KEY);
|
||||
|
||||
return redirect('/i/admin/settings')->with('status', 'Successfully updated settings!');
|
||||
|
|
|
@ -3,63 +3,88 @@
|
|||
namespace App\Observers;
|
||||
|
||||
use App\Jobs\AvatarPipeline\CreateAvatar;
|
||||
use App\Follower;
|
||||
use App\Profile;
|
||||
use App\User;
|
||||
use App\UserSetting;
|
||||
use App\Jobs\FollowPipeline\FollowPipeline;
|
||||
use DB;
|
||||
|
||||
class UserObserver
|
||||
{
|
||||
/**
|
||||
* Listen to the User created event.
|
||||
*
|
||||
* @param \App\User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saved(User $user)
|
||||
{
|
||||
if($user->status == 'deleted') {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Listen to the User created event.
|
||||
*
|
||||
* @param \App\User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saved(User $user)
|
||||
{
|
||||
if($user->status == 'deleted') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($user->profile)) {
|
||||
$profile = DB::transaction(function() use($user) {
|
||||
$profile = new Profile();
|
||||
$profile->user_id = $user->id;
|
||||
$profile->username = $user->username;
|
||||
$profile->name = $user->name;
|
||||
$pkiConfig = [
|
||||
'digest_alg' => 'sha512',
|
||||
'private_key_bits' => 2048,
|
||||
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
||||
];
|
||||
$pki = openssl_pkey_new($pkiConfig);
|
||||
openssl_pkey_export($pki, $pki_private);
|
||||
$pki_public = openssl_pkey_get_details($pki);
|
||||
$pki_public = $pki_public['key'];
|
||||
if (empty($user->profile)) {
|
||||
$profile = DB::transaction(function() use($user) {
|
||||
$profile = new Profile();
|
||||
$profile->user_id = $user->id;
|
||||
$profile->username = $user->username;
|
||||
$profile->name = $user->name;
|
||||
$pkiConfig = [
|
||||
'digest_alg' => 'sha512',
|
||||
'private_key_bits' => 2048,
|
||||
'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
||||
];
|
||||
$pki = openssl_pkey_new($pkiConfig);
|
||||
openssl_pkey_export($pki, $pki_private);
|
||||
$pki_public = openssl_pkey_get_details($pki);
|
||||
$pki_public = $pki_public['key'];
|
||||
|
||||
$profile->private_key = $pki_private;
|
||||
$profile->public_key = $pki_public;
|
||||
$profile->save();
|
||||
return $profile;
|
||||
});
|
||||
DB::transaction(function() use($user, $profile) {
|
||||
$user = User::findOrFail($user->id);
|
||||
$user->profile_id = $profile->id;
|
||||
$user->save();
|
||||
$profile->private_key = $pki_private;
|
||||
$profile->public_key = $pki_public;
|
||||
$profile->save();
|
||||
return $profile;
|
||||
});
|
||||
|
||||
CreateAvatar::dispatch($profile);
|
||||
});
|
||||
DB::transaction(function() use($user, $profile) {
|
||||
$user = User::findOrFail($user->id);
|
||||
$user->profile_id = $profile->id;
|
||||
$user->save();
|
||||
|
||||
}
|
||||
CreateAvatar::dispatch($profile);
|
||||
});
|
||||
|
||||
if (empty($user->settings)) {
|
||||
DB::transaction(function() use($user) {
|
||||
UserSetting::firstOrCreate([
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
if(config_cache('account.autofollow') == true) {
|
||||
$names = config_cache('account.autofollow_usernames');
|
||||
$names = explode(',', $names);
|
||||
|
||||
if(!$names || !last($names)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$profiles = Profile::whereIn('username', $names)->get();
|
||||
|
||||
if($profiles) {
|
||||
foreach($profiles as $p) {
|
||||
$follower = new Follower;
|
||||
$follower->profile_id = $profile->id;
|
||||
$follower->following_id = $p->id;
|
||||
$follower->save();
|
||||
|
||||
FollowPipeline::dispatch($follower);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($user->settings)) {
|
||||
DB::transaction(function() use($user) {
|
||||
UserSetting::firstOrCreate([
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,10 @@ class ConfigCacheService
|
|||
'uikit.show_custom.js',
|
||||
'about.title',
|
||||
|
||||
'pixelfed.cloud_storage'
|
||||
'pixelfed.cloud_storage',
|
||||
|
||||
'account.autofollow',
|
||||
'account.autofollow_usernames'
|
||||
];
|
||||
|
||||
if(!config('instance.enable_cc')) {
|
||||
|
|
|
@ -184,19 +184,33 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="ml-n4 mr-n2 p-3 border-top border-bottom">
|
||||
<div class="custom-control custom-checkbox my-2">
|
||||
<input type="checkbox" name="enforce_account_limit" class="custom-control-input" id="userEnforceLimit" {{config_cache('pixelfed.enforce_account_limit') ? 'checked' : ''}}>
|
||||
<label class="custom-control-label font-weight-bold" for="userEnforceLimit">Enable account storage limit</label>
|
||||
<p class="help-text small text-muted">Set a storage limit per user account.</p>
|
||||
</div>
|
||||
<label class="font-weight-bold text-muted">Account Limit</label>
|
||||
<input class="form-control" name="account_limit" placeholder="Pixelfed" value="{{config_cache('pixelfed.max_account_size')}}">
|
||||
<p class="help-text small text-muted mt-3 mb-0">Account limit size in KB.</p>
|
||||
<p class="help-text small text-muted mb-0">{{config_cache('pixelfed.max_account_size')}} KB = {{floor(config_cache('pixelfed.max_account_size') / 1024)}} MB</p>
|
||||
<div class="ml-n4 mr-n2 p-3 border-top">
|
||||
<div class="custom-control custom-checkbox my-2">
|
||||
<input type="checkbox" name="enforce_account_limit" class="custom-control-input" id="userEnforceLimit" {{config_cache('pixelfed.enforce_account_limit') ? 'checked' : ''}}>
|
||||
<label class="custom-control-label font-weight-bold" for="userEnforceLimit">Enable account storage limit</label>
|
||||
<p class="help-text small text-muted">Set a storage limit per user account.</p>
|
||||
</div>
|
||||
<label class="font-weight-bold text-muted">Account Limit</label>
|
||||
<input class="form-control" name="account_limit" placeholder="Pixelfed" value="{{config_cache('pixelfed.max_account_size')}}">
|
||||
<p class="help-text small text-muted mt-3 mb-0">Account limit size in KB.</p>
|
||||
<p class="help-text small text-muted mb-0">{{config_cache('pixelfed.max_account_size')}} KB = {{floor(config_cache('pixelfed.max_account_size') / 1024)}} MB</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="ml-n4 mr-n2 p-3 border-top">
|
||||
<div class="custom-control custom-checkbox my-2">
|
||||
<input type="checkbox" name="account_autofollow" class="custom-control-input" id="userAccountAutofollow" {{config_cache('account.autofollow') ? 'checked' : ''}}>
|
||||
<label class="custom-control-label font-weight-bold" for="userAccountAutofollow">Auto Follow Accounts</label>
|
||||
<p class="help-text small text-muted">Enable auto follow accounts, new accounts will follow accounts you set.</p>
|
||||
</div>
|
||||
<label class="font-weight-bold text-muted">Accounts</label>
|
||||
<textarea class="form-control" name="account_autofollow_usernames" placeholder="Add account usernames to follow separated by commas">{{config_cache('account.autofollow_usernames')}}</textarea>
|
||||
<p class="help-text small text-muted mt-3 mb-0">Add account usernames to follow separated by commas.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane" id="media" role="tabpanel" aria-labelledby="media-tab">
|
||||
|
|
Loading…
Reference in a new issue