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 +%> + +
序号 | +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) %>
+
+
+ |
+
序号 | +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" %> + | +