/** * Seed the project teams table. */ protected function seedOwners() { $defaultOwners = [['name' => 'Baidu', 'path' => 'Baidu', 'user_id' => 1, 'description' => 'www.baidu.com', 'type' => 'Group'], ['name' => 'Alibaba', 'path' => 'Alibaba', 'user_id' => 1, 'description' => 'www.alibaba.com', 'type' => 'Group'], ['name' => 'Tencent', 'path' => 'Tencent', 'user_id' => 1, 'description' => 'www.qq.com', 'type' => 'Group'], ['name' => 'demo', 'path' => 'demo', 'user_id' => 1, 'description' => 'user', 'type' => 'User'], ['name' => 'jack', 'path' => 'jack', 'user_id' => 2, 'description' => 'user', 'type' => 'User'], ['name' => 'larry', 'path' => 'larry', 'user_id' => 3, 'description' => 'user', 'type' => 'User']]; foreach ($defaultOwners as $owner) { Owner::create($owner); } }
/** * Shows the owner view. * * @return \Illuminate\View\View */ public function showAction($path) { $owner = Owner::findByPath($path); if ($owner->type == 'User') { $user = User::find($owner->user_id); return $this->showUser($user); } else { return $this->showGroup($owner); } }
/** * Updates a project namespace. * * @param \Gitamin\Models\Owner $namespace * * @return \Illuminate\Http\RedirectResponse */ public function updateAction($path) { $groupData = Request::get('group'); $group = Owner::where('path', '=', $path)->first(); try { $groupData['owner'] = $group; $groupData['user_id'] = Auth::user()->id; $group = $this->dispatchFromArray(UpdateOwnerCommand::class, $groupData); } catch (ValidationException $e) { return Redirect::route('groups.group_edit', ['owner' => $group->path])->withInput(Request::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('groups.group_edit', ['owner' => $group->path])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('gitamin.groups.edit.success'))); }
/** * Overrides the models boot method. */ public static function boot() { parent::boot(); self::creating(function ($user) { $ownerExists = Owner::where('path', '=', $user->username)->exists(); $userExists = User::where('username', '=', $user->username)->orWhere('email', '=', $user->email)->exists(); if ($ownerExists === true || $userExists === true) { throw new UserAlreadyTakenException('Username or email has already been taken.'); } if (!$user->api_key) { $user->api_key = self::generateApiKey(); } }); }
/** * Register model bindings. * * @return void */ protected function registerBindings() { $this->app->router->model('owner', Owner::class, function ($slug) { return Owner::where('slug', $slug)->firstOrFail(); }); $this->app->router->bind('project', function ($slug, $route) { $owner = $route->getParameter('owner'); return Project::where(['owner_id' => $owner->id, 'slug' => $slug])->firstOrFail(); }); $this->app->router->bind('issue', function ($iid, $route) { $project = $route->getParameter('project'); return Issue::where(['project_id' => $project->id, 'iid' => $iid])->firstOrFail(); }); }
/** * Index page view composer. * * @param \Illuminate\Contracts\View\View $view */ public function compose(View $view) { // Default data $withData = ['systemStatus' => 'info', 'systemMessage' => trans('gitamin.service.bad'), 'favicon' => 'favicon-high-alert']; if (Project::notVisibilityLevel(1)->count() === 0) { // If all our projects are ok, do we have any non-fixed issues? $issues = Issue::orderBy('created_at', 'desc')->get(); $issueCount = $issues->count(); if ($issueCount === 0 || $issueCount >= 1 && (int) $issues->first()->visibility_level === 4) { $withData = ['systemStatus' => 'success', 'systemMessage' => trans('gitamin.service.good'), 'favicon' => 'favicon']; } } else { if (Project::whereIn('visibility_level', [2, 3])->count() > 0) { $withData['favicon'] = 'favicon-medium-alert'; } } // Project & Project Team lists. $usedProjectTeams = Project::where('owner_id', '>', 0)->groupBy('owner_id')->lists('owner_id'); $projectTeams = Owner::whereIn('id', $usedProjectTeams)->get(); $unteamedProjects = Project::where('owner_id', 0)->orderBy('created_at')->get(); $view->with($withData)->withProjectTeams($projectTeams)->withUnteamedProjects($unteamedProjects); }
/** * Handle the add project owner command. * * @param \Gitamin\Commands\Owner\AddOwnerCommand $command * * @return \Gitamin\Models\Owner */ public function handle(AddOwnerCommand $command) { $group = Owner::create(['name' => $command->name, 'path' => $command->path, 'user_id' => $command->user_id, 'description' => $command->description, 'type' => $command->type]); event(new OwnerWasAddedEvent($group)); return $group; }
/** * Show the form or adding a new resource. * * return \Illuminate\Http\Response */ public function newAction() { return View::make('projects.new')->withPageTitle(trans('dashboard.projects.new.title') . ' - ' . trans('dashboard.dashboard'))->withGroupId('')->withOwners(Owner::where('user_id', '=', Auth::user()->id)->get()); }
/** * Find by owner_path & project_path, or throw an exception. * * @param string $owner_path * @param string $project_path * @param string[] $columns * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return \Gitamin\Models\User */ public static function findByPath($owner_path, $project_path, $columns = ['*']) { $project = Owner::findByPath($owner_path)->project($project_path, $columns); /* Another way $project = static::leftJoin('owners', function ($join) { $join->on('projects.owner_id', '=', 'owners.id'); })->where('projects.path', '=', $project_path)->where('owners.path', '=', $owner_path)->first($columns); */ if (!$project) { throw new ModelNotFoundException(); } return $project; }
/** * Get all owners. * * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Illuminate\Http\JsonResponse */ public function getOwners(Request $request) { $owners = Owner::paginate($request->get('per_page', 20)); return $this->paginator($owners, $request); }