diff --git a/app/assets/javascripts/admins/organizations.js b/app/assets/javascripts/admins/organizations.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/admins/organizations.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/admins/organizations.scss b/app/assets/stylesheets/admins/organizations.scss new file mode 100644 index 000000000..a3cf9ca1f --- /dev/null +++ b/app/assets/stylesheets/admins/organizations.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admins/organizations controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admins/organizations_controller.rb b/app/controllers/admins/organizations_controller.rb new file mode 100644 index 000000000..4e40a509e --- /dev/null +++ b/app/controllers/admins/organizations_controller.rb @@ -0,0 +1,23 @@ +class Admins::OrganizationsController < Admins::BaseController + before_action :finder_org, except: [:index] + + def index + @orgs = paginate Organization.all + end + + def show + end + + def destroy + @org.destroy! + Admins::DeleteOrganizationService.call(@org.login) + render_delete_success + end + + private + + def finder_org + @org = Organization.find(params[:id]) + end + +end diff --git a/app/helpers/admins/organizations_helper.rb b/app/helpers/admins/organizations_helper.rb new file mode 100644 index 000000000..0265ab1e4 --- /dev/null +++ b/app/helpers/admins/organizations_helper.rb @@ -0,0 +1,2 @@ +module Admins::OrganizationsHelper +end diff --git a/app/models/organization.rb b/app/models/organization.rb index adf43a2cd..17eb28918 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -144,6 +144,57 @@ class Organization < Owner end end + def projects_count + Project.where( user_id: self.id).count + end + + # 用户账号状态 + def active? + status == User::STATUS_ACTIVE + end + + def registered? + status == User::STATUS_REGISTERED + end + + def locked? + status == User::STATUS_LOCKED + end + + def need_edit_info? + status == User::STATUS_EDIT_INFO + end + + def activate + self.status = User::STATUS_ACTIVE + end + + def register + self.status = User::STATUS_REGISTERED + end + + def lock + self.status = User::STATUS_LOCKED + end + + def need_edit_info + self.status = User::STATUS_EDIT_INFO + end + + def activate! + update_attribute(:status, STATUS_ACTIVE) + prohibit_gitea_user_login!(false) + end + + def register! + update_attribute(:status, STATUS_REGISTERED) + end + + def lock! + update_attribute(:status, STATUS_LOCKED) + prohibit_gitea_user_login! + end + def real_name name = lastname + firstname name = name.blank? ? (nickname.blank? ? login : nickname) : name diff --git a/app/services/admins/delete_organization_service.rb b/app/services/admins/delete_organization_service.rb new file mode 100644 index 000000000..db842845b --- /dev/null +++ b/app/services/admins/delete_organization_service.rb @@ -0,0 +1,28 @@ +class Admins::DeleteOrganizationService < Gitea::ClientService + attr_reader :token, :name + + def initialize(name) + @name = name + end + + def call + response = delete(url, params) + render_status(response) + end + + private + def params + Hash.new.merge(token: token) + end + + def url + "/orgs/#{name}".freeze + end + + def token + { + username: GiteaService.gitea_config[:access_key_id], + password: GiteaService.gitea_config[:access_key_secret] + } + end +end diff --git a/app/views/admins/organizations/edit.html.erb b/app/views/admins/organizations/edit.html.erb new file mode 100644 index 000000000..0cc9909f0 --- /dev/null +++ b/app/views/admins/organizations/edit.html.erb @@ -0,0 +1,41 @@ +<% + define_admin_breadcrumbs do + add_admin_breadcrumb('组织管理', admins_organizations_path) + add_admin_breadcrumb('组织详情') + end +%> + +
+
+ <%= link_to "/#{@org.login}", class: 'user-info-avatar col-md-1', target: '_blank', data: { toggle: 'tooltip', title: '个人中心' } do %> + + <% end %> + +
+ + <%= simple_form_for(@org, url: admins_organization_path(@org)) do |f| %> + +
基本信息
+
+
+ <%= f.input :login, label: '登录名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.login } %> +
+ +
+ <%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { class: 'col-md-11', value: @org.real_name } %> +
+ + +
+ +
+ <%= f.button :submit, value: '保存', class: 'btn-primary mr-3 px-4' %> + <%= link_to '取消', admins_organizations_path, class: 'btn btn-secondary px-4' %> +
+ <% end %> +
diff --git a/app/views/admins/organizations/index.html.erb b/app/views/admins/organizations/index.html.erb new file mode 100644 index 000000000..7c96b57ee --- /dev/null +++ b/app/views/admins/organizations/index.html.erb @@ -0,0 +1,8 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('组织管理', admins_organizations_path) %> +<% end %> + +
+ <%= render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } %> +
+ diff --git a/app/views/admins/organizations/index.js.erb b/app/views/admins/organizations/index.js.erb new file mode 100644 index 000000000..7e750ecf9 --- /dev/null +++ b/app/views/admins/organizations/index.js.erb @@ -0,0 +1 @@ +$('.users-list-container').html("<%= j( render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } ) %>"); \ No newline at end of file diff --git a/app/views/admins/organizations/index.json.jbuilder b/app/views/admins/organizations/index.json.jbuilder new file mode 100644 index 000000000..1278c3c13 --- /dev/null +++ b/app/views/admins/organizations/index.json.jbuilder @@ -0,0 +1,6 @@ +json.count @orgs.total_count +json.orgs do + json.array! @orgs.each do |org| + json.extract! org, :id, :login, :nickname + end +end \ No newline at end of file diff --git a/app/views/admins/organizations/shared/_org_list.html.erb b/app/views/admins/organizations/shared/_org_list.html.erb new file mode 100644 index 000000000..b8fac30d0 --- /dev/null +++ b/app/views/admins/organizations/shared/_org_list.html.erb @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + <% if organizations.present? %> + <% organizations.each_with_index do |org, index| %> + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
序号login昵称<%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %><%= sort_tag('最后登录', name: 'last_login_on', path: admins_organizations_path) %>项目数操作
<%= list_index_no((params[:page] || 1).to_i, index) %> + <%= link_to "/#{org.login}", target: '_blank' do %> + <%= overflow_hidden_span org.login, width: 100 %> + <% end %> + <%= org.nickname %> <%= display_text(org.created_on&.strftime('%Y-%m-%d %H:%M')) %><%= display_text(org.last_login_on&.strftime('%Y-%m-%d %H:%M')) %><%= link_to org.projects_count, "/#{org.login}", target: "_blank" %> + <%= link_to '查看', admins_organization_path(org), class: 'action' %> +
+ <%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %> + +
+
+ +<%= render partial: 'admins/shared/paginate', locals: { objects: organizations } %> diff --git a/app/views/admins/organizations/shared/_project_list.html.erb b/app/views/admins/organizations/shared/_project_list.html.erb new file mode 100644 index 000000000..e828938ff --- /dev/null +++ b/app/views/admins/organizations/shared/_project_list.html.erb @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + <% if projects.present? %> + <% projects.each_with_index do |project, index| %> + + + + + + + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
序号ID项目名称公开推荐Issues资源Pulls里程碑成员管理员<%= sort_tag('创建时间', name: 'created_on', path: admins_projects_path) %>操作
<%= list_index_no((params[:page] || 1).to_i, index) %><%= project.id %> + <%= link_to(project.name, "/#{project&.owner&.login}/#{project.identifier}", target: '_blank') %> + <%= project.is_public ? '√' : '' %><%= project.recommend ? '√' : '' %><%= project.issues.size %><%= project.attachments.size %><%= project&.pull_requests_count %><%= project.versions.size %><%= project.members.size %> + <%= link_to_project(project) %> + <%= project.created_on&.strftime('%Y-%m-%d %H:%M') %> + <% if project.is_public %> + <%= javascript_void_link '推荐', class: 'action recommend-action', data: { id: project.id }, style: project.recommend ? 'display: none;' : '' %> + <%= javascript_void_link '取消推荐', class: 'action unrecommend-action', data: { id: project.id }, style: project.recommend ? '' : 'display: none;' %> + <%= link_to "设置推荐等级", edit_admins_project_path(project.id), remote: true, class: "action edit-recommend-action", style: project.recommend ? '' : 'display: none;' %> + <% end %> + <%= link_to "删除", admins_project_path(project.id), method: :delete, data:{confirm: "确认删除的吗?"}, class: "delete-project-action" %> +
\ No newline at end of file diff --git a/app/views/admins/organizations/show.html.erb b/app/views/admins/organizations/show.html.erb new file mode 100644 index 000000000..b40f1c258 --- /dev/null +++ b/app/views/admins/organizations/show.html.erb @@ -0,0 +1,38 @@ +<% + define_admin_breadcrumbs do + add_admin_breadcrumb('组织管理', admins_organizations_path) + add_admin_breadcrumb('组织详情') + end +%> + +
+
+ <%= link_to "/#{@org.login}", class: 'user-info-avatar col-md-1', target: '_blank', data: { toggle: 'tooltip', title: '个人中心' } do %> + + <% end %> + +
+ + <%= simple_form_for(@org, url: admins_organization_path(@org)) do |f| %> + +
基本信息
+
+
+ <%= f.input :login, label: '登录名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.login } %> +
+ +
+ <%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.real_name } %> +
+ + +
+ <% end %> +

组织项目

+ <%= render partial: 'admins/organizations/shared/project_list', locals: { projects: @org.projects } %> + +
diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index fb96f088e..fc2fe6068 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -15,14 +15,15 @@