Commit f87b76a805e8ac2d6a77747be171714e2289281a
Committed by
Dmitriy Zaporozhets
1 parent
f6f414ce
Exists in
master
and in
4 other branches
refactoring user team in public section
Showing
4 changed files
with
22 additions
and
6 deletions
Show diff stats
app/controllers/teams/application_controller.rb
app/controllers/teams/projects_controller.rb
1 | 1 | class Teams::ProjectsController < Teams::ApplicationController |
2 | 2 | def index |
3 | - @projects = @user_team.projects | |
4 | - @avaliable_projects = current_user.admin? ? Project.without_team(@user_team) : (Project.personal(current_user) + current_user.projects).uniq | |
3 | + @projects = user_team.projects | |
4 | + @avaliable_projects = current_user.admin? ? Project.without_team(user_team) : (Project.personal(current_user) + current_user.projects).uniq | |
5 | 5 | end |
6 | 6 | |
7 | 7 | def new |
8 | + @projects = Project.scoped | |
9 | + @projects = @projects.without_team(user_team) if user_team.projects.any? | |
10 | + #@projects.reject!(&:empty_repo?) | |
8 | 11 | end |
9 | 12 | |
10 | 13 | def create |
14 | + unless params[:project_ids].blank? | |
15 | + project_ids = params[:project_ids] | |
16 | + access = params[:greatest_project_access] | |
17 | + user_team.assign_to_projects(project_ids, access) | |
18 | + end | |
19 | + | |
20 | + redirect_to admin_team_path(user_team), notice: 'Projects was successfully added.' | |
11 | 21 | end |
12 | 22 | |
13 | 23 | def edit |
24 | + @user_team = user_team | |
14 | 25 | end |
15 | 26 | |
16 | 27 | def update |
28 | + if user_team.update_project_access(project, params[:greatest_project_access]) | |
29 | + redirect_to admin_team_path(user_team), notice: 'Membership was successfully updated.' | |
30 | + else | |
31 | + render :edit | |
32 | + end | |
17 | 33 | end |
18 | 34 | |
19 | 35 | def destroy |
36 | + user_team.resign_from_project(project) | |
37 | + redirect_to admin_team_path(user_team), notice: 'Project was successfully removed.' | |
20 | 38 | end |
21 | 39 | end | ... | ... |
app/helpers/user_teams_helper.rb
... | ... | @@ -19,7 +19,7 @@ module UserTeamsHelper |
19 | 19 | team.user_team_user_relationships.sort_by(&:permission).reverse.group_by(&:permission) |
20 | 20 | end |
21 | 21 | |
22 | - def remove_from_team_message(team, member) | |
22 | + def remove_from_user_team_message(team, member) | |
23 | 23 | "You are going to remove #{member.name} from #{team.name}. Are you sure?" |
24 | 24 | end |
25 | 25 | ... | ... |
app/views/teams/members/_show.html.haml
... | ... | @@ -27,5 +27,5 @@ |
27 | 27 | - elsif user.blocked |
28 | 28 | %span.btn.disabled.blocked Blocked |
29 | 29 | - elsif allow_admin |
30 | - = link_to team_member_path(@user_team, user), confirm: remove_from_team_message(@user_team, user), method: :delete, class: "very_small btn danger" do | |
30 | + = link_to team_member_path(@user_team, user), confirm: remove_from_user_team_message(@user_team, user), method: :delete, class: "very_small btn danger" do | |
31 | 31 | %i.icon-minus.icon-white | ... | ... |