Skip to content

Commit d2b097d

Browse files
authored
Merge pull request #2071 from opensource-workshop/OW-2399
[グループ管理] 初期参加グループフラグ追加
2 parents b69cca4 + f4c599c commit d2b097d

File tree

8 files changed

+164
-73
lines changed

8 files changed

+164
-73
lines changed

app/Http/Controllers/Auth/RegistersUsers.php

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,38 @@
22

33
namespace App\Http\Controllers\Auth;
44

5-
use Illuminate\Http\Request;
6-
use Illuminate\Support\Facades\Auth;
7-
use Illuminate\Auth\Events\Registered;
8-
use Illuminate\Foundation\Auth\RedirectsUsers;
9-
use Illuminate\Support\Facades\Validator;
10-
11-
use App\User;
5+
use App\Enums\UserRegisterNoticeEmbeddedTag;
6+
use App\Enums\UserStatus;
7+
use App\Models\Common\Group;
8+
use App\Models\Common\GroupUser;
129
use App\Models\Core\Configs;
10+
use App\Models\Core\Section;
1311
use App\Models\Core\UsersColumnsSet;
1412
use App\Models\Core\UsersRoles;
13+
use App\Models\Core\UserSection;
14+
use App\Plugins\Manage\UserManage\UsersTool;
15+
use App\Providers\RouteServiceProvider;
16+
use App\Rules\CustomValiTokenExists;
1517
use App\Traits\ConnectCommonTrait;
1618
use App\Traits\ConnectMailTrait;
17-
18-
use Carbon\Carbon;
19-
20-
use App\Plugins\Manage\UserManage\UsersTool;
19+
use App\User;
2120
use App\Utilities\Token\TokenUtils;
22-
use App\Rules\CustomValiTokenExists;
23-
use App\Providers\RouteServiceProvider;
24-
25-
use App\Enums\UserRegisterNoticeEmbeddedTag;
26-
use App\Enums\UserStatus;
27-
use App\Models\Core\Section;
28-
use App\Models\Core\UserSection;
21+
use Carbon\Carbon;
22+
use Illuminate\Auth\Events\Registered;
23+
use Illuminate\Foundation\Auth\RedirectsUsers;
24+
use Illuminate\Http\Request;
25+
use Illuminate\Support\Facades\Auth;
26+
use Illuminate\Support\Facades\Validator;
2927

28+
/**
29+
* ユーザ登録の共通処理
30+
*
31+
* @author 永原 篤 <[email protected]>
32+
* @author 牟田口 満 <[email protected]>
33+
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
34+
* @category Auth
35+
* @package CommonTrait
36+
*/
3037
trait RegistersUsers
3138
{
3239
use RedirectsUsers;
@@ -225,6 +232,20 @@ public function register(Request $request)
225232
}
226233
}
227234

235+
// ユーザー自動登録(未ログイン、ユーザ管理者以外)
236+
if (!Auth::user() || !$this->isCan('admin_user')) {
237+
// 初期参加グループ
238+
$groups = Group::where('initial_group_flag', 1)->get();
239+
foreach ($groups as $group) {
240+
// グループ参加
241+
GroupUser::create([
242+
'group_id' => $group->id,
243+
'user_id' => $user->id,
244+
'group_role' => 'general',
245+
]);
246+
}
247+
}
248+
228249
// ユーザー自動登録(未ログイン、ユーザ管理者以外)
229250
if (!Auth::user() || !$this->isCan('admin_user')) {
230251
// 登録者に仮登録メールを送信する

app/Models/Common/Group.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
namespace App\Models\Common;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
use Illuminate\Database\Eloquent\SoftDeletes;
7-
85
use App\Models\Common\GroupUser;
96
use App\UserableNohistory;
107
use Illuminate\Database\Eloquent\Factories\HasFactory;
8+
use Illuminate\Database\Eloquent\Model;
9+
use Illuminate\Database\Eloquent\SoftDeletes;
1110

11+
/**
12+
* グループ
13+
*
14+
* @author 永原 篤 <[email protected]>
15+
* @author 牟田口 満 <[email protected]>
16+
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
17+
* @category グループ管理
18+
* @package Model
19+
*/
1220
class Group extends Model
1321
{
1422
// 論理削除
@@ -21,7 +29,7 @@ class Group extends Model
2129
/**
2230
* create()やupdate()で入力を受け付ける ホワイトリスト
2331
*/
24-
protected $fillable = ['name', 'display_sequence'];
32+
protected $fillable = ['name', 'initial_group_flag', 'display_sequence'];
2533

2634
/**
2735
* 日付型の場合、$dates にカラムを指定しておく。

app/Plugins/Manage/GroupManage/GroupManage.php

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@
22

33
namespace App\Plugins\Manage\GroupManage;
44

5-
use Illuminate\Http\Request;
6-
use Illuminate\Support\Facades\Auth;
7-
use Illuminate\Support\Facades\DB;
8-
use Illuminate\Support\Facades\Log;
9-
use Illuminate\Support\Facades\Validator;
10-
use Illuminate\Validation\Rule;
11-
125
use App\Enums\UserStatus;
13-
146
use App\Models\Common\Group;
157
use App\Models\Common\GroupUser;
16-
178
use App\Plugins\Manage\ManagePluginBase;
189
use App\User;
1910
use App\Utilities\String\StringUtils;
11+
use Illuminate\Support\Facades\DB;
12+
use Illuminate\Support\Facades\Validator;
2013

2114
/**
2215
* グループ管理クラス
2316
*
2417
* @author 永原 篤 <[email protected]>
18+
* @author 牟田口 満 <[email protected]>
2519
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
2620
* @category グループ管理
2721
* @package Controller
@@ -37,16 +31,16 @@ class GroupManage extends ManagePluginBase
3731
public function declareRole()
3832
{
3933
// 権限チェックテーブル
40-
$role_ckeck_table = array();
41-
$role_ckeck_table["index"] = array('admin_user');
42-
$role_ckeck_table["edit"] = array('admin_user');
43-
$role_ckeck_table["update"] = array('admin_user');
44-
$role_ckeck_table["delete"] = array('admin_user');
45-
$role_ckeck_table["removeUser"] = array('admin_user');
46-
$role_ckeck_table["joinUser"] = array('admin_user');
47-
$role_ckeck_table["notJoinedUsers"] = array('admin_user');
48-
// $role_ckeck_table["list"] = array('admin_user');
49-
return $role_ckeck_table;
34+
$role_check_table = array();
35+
$role_check_table["index"] = array('admin_user');
36+
$role_check_table["edit"] = array('admin_user');
37+
$role_check_table["update"] = array('admin_user');
38+
$role_check_table["delete"] = array('admin_user');
39+
$role_check_table["removeUser"] = array('admin_user');
40+
$role_check_table["joinUser"] = array('admin_user');
41+
$role_check_table["notJoinedUsers"] = array('admin_user');
42+
// $role_check_table["list"] = array('admin_user');
43+
return $role_check_table;
5044
}
5145

5246
/**
@@ -96,7 +90,7 @@ public function index($request, $id)
9690
}
9791

9892
/**
99-
* グループ登録・変更画面表示
93+
* グループ登録・変更画面表示
10094
*
10195
* @method_title グループ登録
10296
* @method_desc グループ名の変更及び、参加ユーザを一覧で確認できます。
@@ -105,13 +99,7 @@ public function index($request, $id)
10599
public function edit($request, $id = null)
106100
{
107101
// グループデータの取得
108-
if (empty($id)) {
109-
// グループデータの空枠
110-
$group = new Group();
111-
} else {
112-
// グループデータの呼び出し
113-
$group = Group::find($id);
114-
}
102+
$group = Group::findOrNew($id);
115103

116104
// グループのユーザデータの取得
117105
$group_users = $this->getGroupUsers($id);
@@ -126,13 +114,13 @@ public function edit($request, $id = null)
126114
}
127115

128116
/**
129-
* グループ登録・変更処理
117+
* グループ登録・変更処理
130118
*/
131119
public function update($request, $id = null)
132120
{
133121
// 項目のエラーチェック
134122
$validator = Validator::make($request->all(), [
135-
'name' => 'required|string|max:255',
123+
'name' => 'required|string|max:191',
136124
'display_sequence' => ['nullable', 'numeric'],
137125
]);
138126
$validator->setAttributeNames([
@@ -147,9 +135,8 @@ public function update($request, $id = null)
147135

148136
// エラーがあった場合は入力画面に戻る。
149137
if ($validator->fails()) {
150-
return redirect('manage/group/edit/')
151-
->withErrors($validator)
152-
->withInput();
138+
$url = $id ? "manage/group/edit/$id" : 'manage/group/edit/';
139+
return redirect($url)->withErrors($validator)->withInput();
153140
}
154141

155142
// 表示順が空なら、自分を省いた最後の番号+1 をセット
@@ -160,12 +147,19 @@ public function update($request, $id = null)
160147
['id' => $id],
161148
[
162149
'name' => $request->name,
150+
'initial_group_flag' => $request->initial_group_flag ? 1 : 0,
163151
'display_sequence' => $display_sequence,
164152
]
165153
);
166154

155+
if ($id) {
156+
$flash_message = 'グループを変更しました。';
157+
} else {
158+
$flash_message = 'グループを登録しました。';
159+
}
160+
167161
// 登録・更新後は一覧画面へ
168-
return redirect('manage/group');
162+
return redirect('manage/group')->with('flash_message', $flash_message);
169163
}
170164

171165
/**
@@ -184,22 +178,23 @@ private function getSaveDisplaySequence($display_sequence, $id)
184178
}
185179

186180
/**
187-
* グループ削除処理
181+
* グループ削除処理
188182
*/
189183
public function delete($request, $id)
190184
{
191185
// カテゴリ削除
192186
Group::find($id)->delete();
193187

194188
// 削除後は一覧画面へ
195-
return redirect('manage/group');
189+
return redirect('manage/group')->with('flash_message', 'グループを削除しました。');
196190
}
197191

198192
/**
199-
* グループ内ユーザー表示
193+
* グループ内ユーザー表示
200194
*
201195
* @return view
202196
*/
197+
/*
203198
public function list($request, $id)
204199
{
205200
// グループデータの取得
@@ -211,6 +206,7 @@ public function list($request, $id)
211206
"group_users" => $group_users,
212207
]);
213208
}
209+
*/
214210

215211
/**
216212
* グループユーザー削除
@@ -220,7 +216,7 @@ public function removeUser($request, $id)
220216
// グループユーザーから削除
221217
GroupUser::where('group_id', $id)->where('user_id', $request->user_id)->delete();
222218

223-
return redirect('manage/group/edit/' . $id);
219+
return redirect("manage/group/edit/$id")->with('flash_message', 'グループから抜けました。');
224220
}
225221

226222
/**
@@ -238,7 +234,7 @@ public function joinUser($request, $id)
238234
]
239235
);
240236

241-
return redirect('manage/group/edit/' . $id);
237+
return redirect("manage/group/edit/$id")->with('flash_message', 'グループに参加しました。');
242238
}
243239

244240
/**

app/Plugins/Manage/UserManage/UserManage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,16 @@ public function groups($request, $id)
12481248
->get();
12491249
// ->paginate(10);
12501250

1251+
// register_redirectTo あり(ユーザ新規登録>グループ参加)の場合
1252+
if (session('register_redirectTo')) {
1253+
foreach ($group_users as &$group_user) {
1254+
// 初期参加グループなら、参加で初期表示
1255+
if ($group_user->initial_group_flag) {
1256+
$group_user->group_role = 'general';
1257+
}
1258+
}
1259+
}
1260+
12511261
// 画面呼び出し
12521262
return view('plugins.manage.user.groups', [
12531263
"function" => __FUNCTION__,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddInitialGroupFlagFromGroups extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('groups', function (Blueprint $table) {
17+
$table->integer('initial_group_flag')->default(0)->comment('初期参加グループフラグ')->after('name');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('groups', function (Blueprint $table) {
29+
$table->dropColumn('initial_group_flag');
30+
});
31+
}
32+
}

0 commit comments

Comments
 (0)